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

State.Realtime during Playback Historical Bars

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

    State.Realtime during Playback Historical Bars

    Hello NT8 Support,

    Inside OnBarUpdate(), I want to avoid executing certain code while the Playback connection loads historical bars as it gets itself to the date/time I choose. Then, after I press the "Play" button I want to begin executing that code -- just like normal real-time trading.

    Calculate is set to Calculate.OnBarClose;

    When I use the following test, the code inside the brackets executes during load of Playback bars (historical) and when printing bars in "real time":

    if ( State == State.Realtime ) // Have also tried if ( State == State.Realtime & CurrentBar == Count - 2 )
    {
    // Do something - should only execute this code after "Play" button is pressed, not while Playback is loading chart with historical bars
    }

    How can I keep the code inside the brackets above from executing until "Play" is pressed?

    Thank you.
    Last edited by D Trader; 07-11-2020, 01:45 PM.

    #2
    Hello D Trader,

    Thank you for your post.

    Where within your script is the code you don't wish to execute until play is hit? If you specify if (State == State.Realtime) within OnBarUpdate(), that code will not execute until play is pressed, regardless of the indicator reaching a real time state as no real time ticks are coming in yet.

    I'm attaching an example indicator that illustrates this. This example will print the state of the indicator from OnStateChange() and then also print that State.Realtime was reached on whatever the current bar is once play is pressed.

    Thanks in advance; I look forward to assisting you further.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      I have the same problem.
      And when I run your TestPlaybackStatus indicator, it DOES generate a lot of State.RealTime messages while changing the playback date/time with the slider.
      So this state is being set during catchup bars when navigating to a new start moment, which is very unfortunate (and incorrect).
      You should be able to see this for yourself; I'm running your indicator.

      Comment


        #4
        Hello wjadevries,

        Thank you for your reply.

        Did you pause playback prior to moving the slider?

        I will do some testing and follow up with my development team - I would generally expect that changing the slider would affect this. I would not advise applying any indicator/strategy that is dependent on State.RealTime while moving the slider in the interim.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Of course I paused before moving the slider.
          but try it yourself; you'll see.

          And I would definitely NOT expect State.RealTime when the slider is moved, but only when playing.
          Just as you said yourself in you answer to the original post from D Trader ;-)

          Comment


            #6
            Hello wjadevries,

            Thank you for your reply.

            I've confirmed with our development team that this would be expected. Basically, what occurs when you move the slider in Playback in NinjaTrader 8 is that it is basically like fast forwarding a video tape - it doesn't just skip to the new point, it actually plays through to that point at a high rate. You can see this happening if you apply, for example, the Sample MA Crossover to the chart and then move the slider forward - you'll see executions being taken as the Playback connection moves through to the new time.

            This is different than in NinjaTrader 7 where it would not play over the bars prior to the new slider location.

            However, if you move the slider prior to applying the indicator/strategy, you would not see this occur and you'd only see the "State.RealTime Reached..." print once the play button is pressed.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              In my opinion a rather strange and unwanted behavior.
              I cannot imagine that anyone moving a slider to fast forward (or back) wants the data in between played as real time.
              This should be State Historical until you press play again.
              If you fast forward without pressing pause first (still in playback), then I can imagine the data would be real time.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by algospoke, Yesterday, 06:40 PM
              2 responses
              21 views
              0 likes
              Last Post algospoke  
              Started by ghoul, Today, 06:02 PM
              3 responses
              14 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              45 views
              0 likes
              Last Post jeronymite  
              Started by Barry Milan, Yesterday, 10:35 PM
              7 responses
              21 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by AttiM, 02-14-2024, 05:20 PM
              10 responses
              181 views
              0 likes
              Last Post jeronymite  
              Working...
              X