Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy doesn't run in realtime

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strategy doesn't run in realtime

    This is my first strategy and I must be overlooking something simple here. I created an indicator that works perfectly. It basically is similar to pivot point indicator but with different formulas. Once the stock reaches the calculated price for either a long or short entry it plots some information on the chart. All is well with the indicator...

    I am now trying to use this to automate a trading strategy. I created the strategy over this past weekend and it appeared to be working fine. When I ran it on Sunday and I look at the real-time and historical performance the trades that were executed from 12/05/08 - 01/02/09 match up perfectly. All of the buys and sells show up on the chart and match up exactly with the indicator.

    For some reason the strategy did not work Monday or Tuesday in realtime although the indicator triggered multiple times. And furthermore Monday night I stopped the strategy and restarted it and it then shows the trades for Monday just fine. But those trades did not trigger when it was running during the day on Monday. Here is the strategy code:

    protected override void Initialize()
    {
    EntriesPerDirection = 4;
    EntryHandling = EntryHandling.AllEntries;
    TimeInForce = Cbi.TimeInForce.Day;
    TraceOrders = true;
    SetProfitTarget("1", CalculationMode.Ticks, 4);
    SetProfitTarget("2", CalculationMode.Ticks, 8);
    SetStopLoss("1", CalculationMode.Ticks, 6, false);
    SetStopLoss("2", CalculationMode.Ticks, 6, false);

    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()

    {
    // Condition set 1 ---Long Setup---
    if (Close[0] > MySetup().Buy[0])
    {
    // Only allow entries if we have no current positions open
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    EnterLongLimit(1, MySetup().Buy[0], "1");
    EnterLongLimit(1, MySetup().Buy[0], "2");
    }
    }
    // Condition set 2 ---Short Setup---
    if (Close[0] < MySetup().Sell[0])
    {
    // Only allow entries if we have no current positions open
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    EnterShortLimit(1, MySetup().Sell[0], "1");
    EnterShortLimit(1, MySetup().Sell[0], "2");
    }
    }
    }

    I am running this on the Sim account if that matters.

    I start a new chart, add the indicator, add the strategy... Is there something else I need to be doing?

    #2
    Hi rcossey73, first of all: welcome to the NinjaTrader forums!

    Do you see any errors generated in the Log tab of the Control Center?

    What is your CalculateOnBarClose setting in the indicator (MyBuy) you call?

    If not needed, please try running this again with both (Strategy and Indicator) set to CalculateOnBarClose = True

    I can also test the strategy on my end, you can send me the zip file to support at ninjatrader dot com and reference this thread as subject, Thanks!

    Comment


      #3
      No errors in the logs.

      CalculateOnBarClose is true in the indicator and false in the strategy. Let me try setting it to true in both and see.

      If that doesn't work, I will send you the files.

      Thanks!

      Comment


        #4
        rcossey73,

        What you want to do is completely remove the CalculateOnBarClose line from the indicator. There is a bug regarding different settings between indicators and strategies calling the indicators.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        633 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        567 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X