Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Strategy not displaying results in Strategy Analyzer, only via Replay Mode

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

    Strategy not displaying results in Strategy Analyzer, only via Replay Mode

    Hello !


    We are having an issue because the strategy data and trades works ONLY on Playback mode, not anywhere else.
    How can we fix this in the code ?

    Thanks !

    #2
    Hello lordkaan,

    Thanks for your post.

    What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)

    Is your script skipping historical processing by calling if (State == State.Historica) return; in OnBarUpdate()?

    Does the strategy use OnMarketData() or OnMarketDepth()?

    Does the strategy use Atm Strategy Methods to place and manage orders?

    Atm Strategy Methods: https://ninjatrader.com/support/help...gy_methods.htm

    If you run a backtest on the SampleMACrossover in the Strategy Analyzer window do you see results returned?

    Have you added debugging prints to see exactly how your strategy's logic is behaving and how the strategy is placing orders?

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.



    We look forward to assisting further.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for getting back to me,

      Version is the latest 8.1.2.1

      Yes the strategy uses OnBarUpdate but not State == State.Historical ,
      It uses OnMarketData

      Comment


        #4
        Hello lordkaan,

        Thanks for your notes.

        I understand your script is using OnMarketData().

        OnMarketData() is a real-time data stream. Since the Strategy Analyzer only uses Historical data for backtests/optimizations, the script never processes any real-time data and OnMarketData() does not get called.

        From the OnMarketData() help guide: "By default, this method is not called on historical data (backtest), however it can be called historically by using TickReplay

        If used with TickReplay, please keep in mind Tick Replay ONLY replays the Last market data event, and only stores the best inside bid/ask price at the time of the last trade event. You can think of this as the equivalent of the bid/ask price at the time a trade was reported. As such, historical bid/ask market data events (i..e, bid/ask volume) DO NOT work with Tick Replay. To obtain those values, you need to use a historical bid/ask series separately from TickReplay through OnBarUpdate(). More information can be found under Developing for Tick Replay.​"

        You could consider enabling Tick Replay when backtesting the strategy to have the OnMarketData() method called historically.

        See this help guide page for more information about OnMarketData(): https://ninjatrader.com/support/help...marketdata.htm
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks,

          How could I replace OnMarketData() then?
          Tick Replay solution does not work
          Last edited by lordkaan; 03-10-2024, 05:54 PM.

          Comment


            #6
            Hello lordkaan,

            Thanks for your notes.

            TickReplay does allow OnMarketData() to be called historically in a backtest. Note that Tick Replay ONLY replays the Last market data event. Historical bid/ask market data events (i..e, bid/ask volume) DO NOT work with Tick Replay.

            If you need bid/ask events from OnMarketData(), to obtain those values you need to modify your strategy to use a historical bid/ask series separately from TickReplay through OnBarUpdate(). More information can be found under the Developing for Tick Replay help guide page.​​

            Otherwise, you could consider placing your strategy logic within OnBarUpdate() and not use OnMarketData() for logic in your script. Or, use Playback with Market Replay data to test your strategy.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Can I send the portion of code somewhere for you to help me ? I've removed OnMarketData() but doesn't change

              Comment


                #8
                Hello lordkaan,

                Thanks for your notes.

                Yes, you could share an exported script on this forum thread so I may see if anything specific is standing out in your code.

                To export the script, go to Tools > Export > NinjaScript AddOn.

                Or, you could write in to support[at]ninjatrader[dot]com to send us an exported script so we may see if there is anything specific standing out. If you choose to do this, in the subject of your email include "Attn: BrandonH" and in the body of the email include a link to this forum thread.

                Ultimately, debugging steps would need to be taken to understand exactly how your script is behaving and processing logic.

                To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

                In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

                Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

                Below is a link to a forum post that demonstrates how to use prints to understand behavior.

                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Just sent the email thanks

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by rhyminkevin, Today, 04:58 PM
                  3 responses
                  47 views
                  0 likes
                  Last Post Anfedport  
                  Started by iceman2018, Today, 05:07 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post iceman2018  
                  Started by lightsun47, Today, 03:51 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post lightsun47  
                  Started by 00nevest, Today, 02:27 PM
                  1 response
                  14 views
                  0 likes
                  Last Post 00nevest  
                  Started by futtrader, 04-21-2024, 01:50 AM
                  4 responses
                  50 views
                  0 likes
                  Last Post futtrader  
                  Working...
                  X