Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy won't run historically

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

    Strategy won't run historically

    I'm having some problems getting my strategy to run historically. It's using a variable passed by a custom indicator. It works fine live, it works in market replay. But historically it doesn't create the correct triggers so I can't backtest it.

    The indicator on it's own does run fine historically despite being created for OnPriceChange. So I don't understand why it's not working in conjunction with the strategy.

    I've done some testing and it appears these lines of code are causing problems, this code is within the indicator not the strategy:

    ((CurrentBars[0] - 1) != BarNum_Signal)

    Code like this, shouldn't this run the same whether run OnBarClose or OnPriceChange?

    #2
    Hello several,

    Thank you for your inquiry.

    From just that line of code, I would expect it to work historically.

    When you say it won't run historically, do you mean it's not processing historical data at all, or is it just not returning results when you test in the Analyzer on historical data?

    Comment


      #3
      I mean if I run a market replay for the month of January '25, I get 70 triggers.

      If I run the same month through the strategy analyzer, I get 2 triggers. All settings are market data is correct and other strategies backtest..

      When I load the strategy onto a chart and view the output window, I can see also it doesn't get the right triggers historically. The indicator alone does though.

      Comment


        #4
        Hello several,

        Thank you for your response.

        Have you implemented 1-tick intrabar granularity? And if the strategy is running OnEachTick or OnPriceChange, have you enabled Tick Replay?


        Please review the help guide page on the differences on real-time vs backtest.



        A strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest.

        When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

        Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

        Calculate - https://ninjatrader.com/support/help.../calculate.htm

        To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar. Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

        High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

        Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

        SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_strate.htm

        TickReplay - https://ninjatrader.com/support/help...ick_replay.htm

        Please see this support article for a detailed explanation:
        https://support.ninjatrader.com/s/ar...ar-granularity

        Comment


          #5
          Hi, I'm going to try that later but still. The logic I'm using should work onBarClose. I've checked if Bar [1] meets certain criteria and the trigger is Bar [0], being greater than Bar [1]. OnPriceChange, this will trigger after 1 tick, but it should trigger also onBarClose. It does in the indicator, but just not when used in the strategy.

          Comment


            #6
            If after implementing 1-tick intrabar granularity and/or Tick Replay you're still seeing this behavior, we'll likely need to the debugging output to see what is going on.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            116 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            61 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            40 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            43 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            82 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X