Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trying to simulate backtesting OnBarClose=false

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

    Trying to simulate backtesting OnBarClose=false

    First of all, my understanding is that we can not back test strategies CalculateOnBarClose=false, right?

    Assuming I am correct, then I have to add a second 1-tick time frame and now I have to deal with coding a multiple time frame strategy.

    This is not my actual strategy, but here's a similar situation:

    Let's say I have an SMA(20) and an SMA(50) and an SMA(200). I buy when the 20 crosses above the 50, but only when the 50 is above the 200. So I want to buy if the 50 is above the 200 on the 5min time frame (calculated on bar close) but i want to enter once the 20 crosses above the 50 intrabar, not wait for the 5min bar to close.

    However, I want the buys to happen if the 20/50 bars cross intrabar, not on bar close. So I am trying something like this.

    Let's say I'm running the strat on 5min bars (primary time frame)

    In my class

    Code:
    private bool _upTrend;
    In Initialize()...

    Code:
    _upTrend = false;
    
    Add(PeriodType.Tick, 1);
    and in OnBarUpdate()

    Code:
    if (BarsArray == 0 && FirstTickOfBar)   // the 5-min bars
    {
       _upTrend = (SMA(50)[1] > SMA(200)[1];
    }
    else if (BarsArray == 1)  // the 1-tick bars
    {
       if (SMA(20)[0] > SMA(50)[0] && _upTrend)
          EnterLong();
    }
    However, the trades are still happening on bar close. Is this because SMA(20)[0] doesn't update until the 5min bar closes because it's on the higher time frame? If so, how can I monitor the changes in the SMAs intrabar while the bar is forming? My fear is that this is not possible and Ninjatrader is not a good solution for this.

    #2
    shodson, please try submitting the order to the 1 tick time frame. You can use the method that specifies the names and the BarsInProgress index to submit to:
    Code:
    //EnterLong(int barsInProgressIndex, int quantity, string signalName);
    EnterLong(1, 1, "long crossover entry"); // submit to the second bars index (index = 1)
    AustinNinjaTrader Customer Service

    Comment


      #3
      I did that but the trades are still firing at 5min intervals, not on the 1-tick bars

      Comment


        #4
        shodson, can you please provide the full code you're using so we can see if anything else is amiss?
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        663 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        376 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        110 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        580 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X