Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New strategy shows no trades in backtest, other ones all work

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

    New strategy shows no trades in backtest, other ones all work

    Hi guys, I just made a simple strategy that utilizes fair value gaps and it works perfectly well in market replay as well as when I add it to a chart it shows all the trades it has taken with stop and take profit markers.

    However, when I run in strategy analyzer 'Backtest', nothing shows up (it says 0 trades taken). It works for ALL other strategies. I made the following observations:

    1) the Chart tab in the strategy analyzer IS populated with my 1 indicator that I use, so it did plot that successfully.
    2) enabling trace orders doesn't print anything. Nothing gets printed as the entries are not executing, nothing in the orders tab either.
    3) im not disabling anything related to historical data in my strategy. there is one simple if statement in my strategy to determine entry that isn't executing for some reason.
    4) I am using on bar update mode , not on each tick which I know doesn't work properly on historical data.

    Platform information: Windows, Ninja trader 8, C# code.

    I only have 2 .cs files total, one for the strategy and one for the indicator. I am a programmer so I understand how stuff works in general but unsure of this bug in my strategy. It is trying to read a value from my indicator to determine the entry, but that value is never being set for some reason despite plots from bar update in the indicator happening on the chart in the strategy analyzer. Any help is appreciated.

    ​I have attached screenshots of what the analyzer looks like, as well as my order entry code in my strategy and the actual strategy code itself with the one indicator I use (FVG indicator)
    Attached Files

    #2
    I want to mention that I have fixed this issue for anyone else who may have it. It happened to be because in my indicator, I was checking a condition if (DrawObjects[fvg.Tag] != null) which was null when backtesting.

    For anyone who has any drawing in their indicators, remember it could be null in a backtest even if the things show up on the chart like they did for me

    Comment


      #3
      Hello, could you please share with what you've replaced the null part with? I am also working on a strategy and I was hoping to learn as I am new to coding. Thank you.

      Comment


        #4
        Originally posted by Superlifter View Post
        Hello, could you please share with what you've replaced the null part with? I am also working on a strategy and I was hoping to learn as I am new to coding. Thank you.
        Hi, I just added “ || State == State.Historical” to the if statement, so that it would still run in historical mode.

        essentially for conditions you’re unsure about that may not run in historical mode, just add that. The || is the or operator, so it would execute if state is historical or the old condition is true.

        if (thing != null || State == State.Historical

        Comment


          #5
          Superlifter,

          Welcome to the NinjaTrader forums!

          Below I am providing a link to a support article with helpful resources on getting started with C# and NinjaScript.


          As marmello learned the chart is not constructed when running a backtest and drawing objects will not be drawn. Adding the check for null prevents the error from occuring.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thank you to the two of you, I appreciate it.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X