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

Playback tick by tick data to debug a strategy

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

    Playback tick by tick data to debug a strategy

    Hi all,

    Not sure if there is a way to do this or not but is there a way to playback data tick by tick so that you can basically run a debugger on a strategy? I started my strategy in NinjaScript editor but completed it using Visual Studio 2019. I know that in the past when doing this for an indicator I had to connect the debug session to the NinjaTrader.exe process. How do I run play back on the tick data? Would I run Strategy Analyzer and set (check) Tick Replay to true.

    I am running my strategy on a 1 day chart with -

    Calculate = Calculate.OnEachTick;

    Also, I have been running this strategy on another platform. It has two different ways that it can hit a profit target. On the day that the strategy triggers and gets into the market I base the first profit target on the Average True Range. If I am not flat during that trading session, i.e. never hit my ATR target, I will get out at the next sessions first profitable opening, unless I am stopped out by my stop loss. I have not quite figured out how to get out on the next sessions first profitable opening. Are there any code examples that would show how to do this?

    #2
    Hello NeverDownMoney,

    It sounds like you have used the attach to process in the past to debug an indicator, it would be the same process for any NinjaScript type like a strategy. You would need to attach the debugger and set breakpoints in a location you want then run that script in whatever use case it needs debugged in. Debug mode does need to be enabled, here are the general steps for that: https://ninjatrader.com/support/help...=visual+studio

    If you wanted to play back tick data you can use the playback connection for that or also tick replay. Keep in mind that tick replay and playback are slightly different, you can learn about how tick replay works here: https://ninjatrader.com/support/help...ub=tick+replay

    Regarding the profitable opening, you may be able to use IsFirstBarOfSession for part of that logic: https://ninjatrader.com/support/help...sub=isfirstbar
    The profitable open also depends on what you mean here, did you mean the first price that is greater than the original entry price or what did you mean for profitable open?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I have attached to the NinjaTrader.exe as shown. I set a breakpoint in OnBarUpdate but it appears that the event never fires. So then I set a breakpoint in OnMarketData and that event seems to never fire either. My chart has my strategy loaded and I am launching playback data with the tick replay checked so why is it not hitting my breakpoints?

      Comment


        #4
        Regarding the First Profitable Opening, what I mean is the trading session immediately following the session that the trade was entered into. So, for example if I got filled yesterdays session and todays session I have a potential profit at market open then close the trade and take the profit.

        Regarding IsFirstBarOfSession - if you are trading a day chart won't this always be true?

        Comment


          #5
          I think that the problem that I am having is with the playback data. I noticed that when I load a new chart from NinjaTrader Continuum connection and for example I set days to load at 365 then it will load each day and I can step through the tick data for those days. Is this a correct assumption?

          Comment


            #6
            hello NeverDownMoney,
            I have attached to the NinjaTrader.exe as shown. I set a breakpoint in OnBarUpdate but it appears that the event never fires. So then I set a breakpoint in OnMarketData and that event seems to never fire either. My chart has my strategy loaded and I am launching playback data with the tick replay checked so why is it not hitting my breakpoints?
            With OnBarUpdate the only suggestion I could make would be to make sure its the first line of OBU in case one of your conditions is preventing it from being reached. Tick replay can take a very long time to process so you may not see the breakpoint hit for a very long time during calculating.

            OnMarketData would require specific programming for tick replay which is going to be a seperate set of logic than your normal realtime logic in OnMarketData, do you currently have that structure? If not I would suggest avoiding using tick replay until you have modified the script to be specific to tick replay programming style. https://ninjatrader.com/support/help...ub=tick+replay




            Regarding the First Profitable Opening, what I mean is the trading session immediately following the session that the trade was entered into. So, for example if I got filled yesterdays session and todays session I have a potential profit at market open then close the trade and take the profit.
            If you mean profitable based on the entry price, yes that is possible. You would need to collect the entry order from OnExecutionUpdate and then you could use its average price in your logic.



            Regarding IsFirstBarOfSession - if you are trading a day chart won't this always be true?

            Yes if you use a daily chart you would likely need to use other means to detect a new bar because 1 bar will be generated each day. You could store the CurrentBar value to a variable and then compare if the CurrentBar matches that variable or not to do something once on each new bar.


            I think that the problem that I am having is with the playback data. I noticed that when I load a new chart from NinjaTrader Continuum connection and for example I set days to load at 365 then it will load each day and I can step through the tick data for those days. Is this a correct assumption?
            No the playback should also work, I would suggest trying a more simple test such as using the SampleMACrossOver and setting a breakpoint on the first line of code in OnBarUpdate. I see that working on my end, it may just be that your condition or where the breakpoint was is not being reached in your test.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              So, yeah, I tried this with SampleMACrossOver, same result. The only time I can get it to step into the code is when I set a breakpoint at the very top of the code on one of the private variable declarations and then click on the strategies button of the chart. It will hit the break point and then after I have click-continued through the strategies dialog it never hits my breakpoint in the OnBarUpdate method and yes I have the breakpoint set at the first line of code in the method not inside a conditional.

              Comment


                #8
                Hello NeverDownMoney,

                Are you enabling and running the strategy as well? Breakpoints are being hit so this would relate somehow to how you are using the strategy or where you placed the breakpoint. I can see this working on my end using OnBarUpdate. and for the bar processing. You would see the breakpoint hit opening the menu if you placed the breakpoint in the general file because the type will be created when opening the menu. The OnBarUpdate and other overrides will only be called while its processing.

                Please let me know if I may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Thanks Jesse,

                  That was the problem, I needed to enable the strategy as well. It appears to be working with playback now.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by zstheorist, Today, 07:52 PM
                  0 responses
                  5 views
                  0 likes
                  Last Post zstheorist  
                  Started by pmachiraju, 11-01-2023, 04:46 AM
                  8 responses
                  150 views
                  0 likes
                  Last Post rehmans
                  by rehmans
                   
                  Started by mattbsea, Today, 05:44 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post mattbsea  
                  Started by RideMe, 04-07-2024, 04:54 PM
                  6 responses
                  33 views
                  0 likes
                  Last Post RideMe
                  by RideMe
                   
                  Started by tkaboris, Today, 05:13 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post tkaboris  
                  Working...
                  X