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 Connection, Market Replay, Play button state (Playing or Stopped)

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

    Playback Connection, Market Replay, Play button state (Playing or Stopped)

    How can I programmatically access the "state" property of the Play Button in the Playback control?

    I have a timer setup from your example code, but it doesn't stop running when the playback is stopped.

    i.e. I need something like ...
    Code:
    var playbuttonState = NinjaTrader.Gui.Tools.PlaybackControl.PlayButton.State;



    #2
    Hello balltrader,

    Thank you for the question.

    I am unsure of a way to access the controller's button events directly but you can access the playback speed which is 0 when paused. If you have a timer running, you can likely check the playback speed from the timer to know if it should be stopped.

    Code:
    Print(NinjaTrader.Adapter.PlaybackAdapter.PlaybackSpeed);
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      thanks, that works for debugging.

      Is there an eventHandler for when playback starts again?
      if not, I can check status of the myTimer state during the event raise of OnMarketData for debugging...
      i.e.
      Code:
      if (myTimer.Enabled != true) { myTimer.Enabled = true; }

      Comment


        #4
        Hello balltrader,

        I am unable to see anything specific event-wise relating to the play/pause events. For this you would likely need to form some logic to check if the playback has started again. It sounds like you are working outside of the event-driven nature of the script so this is likely something you will need to come up with custom logic to handle.

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

        Comment


          #5
          Why doesn't NT8 suspend event timers when playback is paused? Or its not possible?

          I don't think I was crazy enough to put an event timer in playback code. I wonder what nt7 does?

          Comment


            #6
            Here is what I did, in case anyone else experiences this.

            Code:
            protected override void OnMarketData(MarketDataEventArgs marketData)
                    {    // TODO debugging: if myTimer was stopped becuase market replay playback was paused, 
                        // but now it is started again, i need to start the timer again.
                        Print("timer enabled? = " + myTimer.Enabled );
                        if (myTimer.Enabled == false) { myTimer.Enabled = true; }
                        ...
            Code:
            // When timer reaches it's interval, i.e. every 15 secs, this method will be called
                    private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
                    {    Print("Timer event raised. Checking playback speed... " + NinjaTrader.Adapter.PlaybackAdapter.PlaybackSpeed );
            
                        // TODO debugging: stop timer if market replay playback speed is 0 (playback paused)
                        if (NinjaTrader.Adapter.PlaybackAdapter.PlaybackSpeed == 0 )
                        {    Print("playback speed eq 0, trying to stop timer");
                            myTimer.Stop(); 
                        }
                        ...

            Comment


              #7
              Originally posted by sledge View Post
              Why doesn't NT8 suspend event timers when playback is paused? Or its not possible?

              I don't think I was crazy enough to put an event timer in playback code. I wonder what nt7 does?
              It is probably possible, since you could programmatically find all instances of the Timer Class in DotNet, and then set Enable = False when market replay playback is paused, but perhaps this is not the desired case by the tech team at ninjatrader, or nobody else was as crazy as me to put a timer in my playback.

              I'm just using market replay playback during writing and testing / debugging code ideas, in the live trading connection, the data feed should always be active, and therefore would not need to be paused, UNLESS you left NT running all weekend while the exchange was closed.


              So now I have a second question... Is there any object property i could access to see if the current connection (exchange, i..e Continuum) is active or closed, i.e. it's outside trading hours or a holiday?

              or do I need to create elaborate logic to determine the trading hours and possible holidays?
              Code:
              if (Time[0].DayOfWeek != DayOfWeek.Monday && Time[0].DayOfWeek != DayOfWeek.Friday)
                          {
                              if ((ToTime(Time[0]) >= 93000 
              ...

              Comment


                #8
                Hello balltrader,

                Thank you for the reply.

                Would you be able to detail further what you are trying to do before I try to provide further solutions on this topic? It is not clear why you are using a timer here and I would need more information on the goal to make further suggestions.

                The playback connection will pause everything including your script when you press pause but the platform is not expecting for you to use a timer so that is something you would have to control yourself outside of the platforms events. Are the events of the platform not sufficient for what you are trying to do? If you can provide more detail on the end goal, perhaps there is a more standard way to accomplish that.

                If you are using the event overrides like OnBarUpdate or OnMarketData your logic will stop when you pause the connection and no market data is coming in to drive the simulation.

                Regarding the connection and session, yes there are various ways to check this information but this would also relate to the event-driven overrides so it would still be in my interest to better understand the goal before recommending these items.

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

                Comment


                  #9
                  I'm writing my code, and testing it using the playback connection.
                  When I pause the playback, the timer used to continue and the event was being raised, without active order flow from OnMarketData, etc.

                  So my concern was

                  ninjatrader app is always running,
                  it is the weekend, so markets are closed,
                  is the timer still running in the background, trying to measure order flow event that do not exist because the market is closed?

                  i..e when the weekend hits, does the connection to market data get shutoff automatically, and then since there is no active connection to a data provider, my timer is "magically" stopped,

                  or, do I need to write code to detect if the connection to a market data provider is closed, and then stop the timer, and when the connection is open, start the timer?
                  Code:
                   if (myAccount.Connection.Status == ConnectionStatus.ConnectionLost)
                  or, when the connection is opened / restarted, does the state change, such as
                  Code:
                  State.Realtime
                  which could be used to enable the timer object?

                  Comment


                    #10
                    aha, I just did a code search across all files, for term ".Realtime", and found some sample code in @BarTimer.cs that appears useful as a starting point...

                    Comment


                      #11
                      Hello balltrader,

                      I am still not clear on why you are using a timer to be able to provide more assistance on this question. Can you explain simply why you are using a timer here?

                      The platform is not going to control the code you write especially when it comes to items like timers or event handlers, those are all outside of what the platform is aware that you are doing. Because the platform is not expecting a timer to be used at all, you need to exclusively control that if you require a timer to be used. Once you start the timer it is running until you stop it or exit the process.

                      A timer will not assist with market data, if there is no data coming in a timer will not assist in seeing any new data events. I am getting a hint that you are trying to measure data that is outside of the trading hours, is this correct?
                      trying to measure order flow event that do not exist because the market is closed?
                      If the market is closed, there is no data to measure. If you mean outside of the selected trading hours, it is possible that there is still data coming in but you may need to change the trading hours being used to include that data.

                      Again I am not sure what you are using a timer for to provide more accurate answers here.


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

                      Comment


                        #12
                        sorry for the obfuscation, I have been having early halloween ****tails and probably not making sense.

                        I am using a timer as a trigger to take a snapshot of the qty of trades made by market participants (i.e. every 30 seconds timer interval is raised, call a method to record and reset the count of trade transactions as being tracked by code in the OnMarketUpdate event).

                        in my example blab above, if Friday 5 pm ny time comes around, and the market exchange closes, does the connection automatically close?

                        if the market is closed, for example the futures market closes at 5pm ny time and reopens at 6pm ny timezone, is the state still = Realtime or Terminated?
                        if the market is closed, what will the connection status value be?
                        ConnectionStatus.Disconnecting
                        or
                        ConnectionStatus.Disconnected

                        thank you



                        Comment


                          #13
                          Hello balltrader,

                          In regard to your question:

                          if Friday 5 pm ny time comes around, and the market exchange closes, does the connection automatically close?
                          No, that is simply the closing time for that market.

                          Your connection would not disconnect based on an exchanges hours, however, it is possible for a disconnect to occur based on other reasons. For example, data provider scheduled maintenance or internet connectivity issues. Your platform would remain connected and the script would remain enabled when moving outside of the instruments trading hours.

                          If you are trying to take a snapshot every 30 seconds during market hours, I would suggest to instead use an added 30 second series for that logic. The only time that may not specifically occur every 30 seconds would be in a low volume time where it takes more than 30 seconds for a tick to be received. You could also place this logic directly in the OnMarketData override and you could utilize the last Ticks time to compare 30 second intervals. These approaches would be controlled by the replay controller as you are using the events of the script.

                          I look forward to being of further assistance.


                          JesseNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by kujista, Today, 06:23 AM
                          0 responses
                          1 view
                          0 likes
                          Last Post kujista
                          by kujista
                           
                          Started by traderqz, Yesterday, 04:32 PM
                          1 response
                          10 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Started by f.saeidi, Today, 05:56 AM
                          1 response
                          4 views
                          0 likes
                          Last Post Jltarrau  
                          Started by Jltarrau, Today, 05:57 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post Jltarrau  
                          Started by Stanfillirenfro, Yesterday, 09:19 AM
                          7 responses
                          52 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Working...
                          X