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

Historical keyword in Replay mode

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

    Historical keyword in Replay mode

    The Historical keyword does not seem to work correctly in Replay mode. It returns true for all bars. I would expect it to work as if you were in live mode, and be set to true for all but the last bar. What is the best way to tell if you are running on the last bar in all modes? Also, from an indicator, how can you tell if Replay is running?

    #2
    aslane,

    Yes, "Historical" only is true when real-time data is being received.

    Unfortunately there is no supported way to check if replay is running. You could however setup some override flag that you set manually which tells the strategy you are in replay.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Ok, then please chalk that up to bug to be fixed in next rev, and feature to add in next rev, and let me know what the tracking numbers are.

      Comment


        #4
        aslane,

        This is unsupported, but you could try something like this – that’s in our Bartimer indicator.
        Code:
        private DateTime Now
                    {
                          get 
                          { 
                                DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now); 
        
                                if (now.Millisecond > 0)
                                      now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate).TotalSeconds));
        
                                return now;
                          }
                    }
        Specifically look here :

        Code:
        Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          While unsupported, this is good in the short term.

          Comment


            #6
            I'm lost on this one.

            I've used:

            Code:
            protected override void OnBarUpdate()
            {
            
                  if (Historical) return;
            ....
            }
            previous "trades" on the chart are ignored, and market replay works going forward, my code works, so therefore, it was false...

            What am I not understanding about this post? NT 7.0.1000.8... 32 bit.

            Edit: I'm referring my usage for Strategies. Not indicators. Maybe that is the difference you speak of



            Originally posted by aslane View Post
            The Historical keyword does not seem to work correctly in Replay mode. It returns true for all bars. I would expect it to work as if you were in live mode, and be set to true for all but the last bar. What is the best way to tell if you are running on the last bar in all modes? Also, from an indicator, how can you tell if Replay is running?

            Comment


              #7
              Originally posted by sledge View Post
              I'm lost on this one. [...]
              I'm with sledge, I've used 'if (Historical) {return;}' in both strategies and indicators in market replay, and I haven't run into any problems.

              Comment


                #8
                I have written a simple test for Historical, and it does seem to work in a trivial indi in replay mode. Unfortunately, it does not always work in complex code. I must be doing something to cause the issue, but I find it strange that I could cause the issue from my side of the fence. I'll try to isolate more.

                Comment


                  #9
                  Originally posted by aslane View Post
                  I have written a simple test for Historical, and it does seem to work in a trivial indi in replay mode. Unfortunately, it does not always work in complex code. I must be doing something to cause the issue, but I find it strange that I could cause the issue from my side of the fence. I'll try to isolate more.
                  Would your "complex code" have anything to do with "short circuit evaluation"?

                  I am out of guesses without seeing some code that isolates and is reproduceable.

                  Comment


                    #10
                    Please take a look at my post in this older thread and provide your comments about it as a possible solution. I have a similar need. Do you think it is viable? It's certainly not optimal, but can you think of any reason why it would fail?

                    Thanks.

                    Scott
                    sh_daggett
                    NinjaTrader Ecosystem Vendor - NinjaLaunchpad

                    Comment


                      #11
                      Historical stays 'true' for referenced indicator on phantom bar if updated

                      Hello!

                      I have studied the Historical property in Replay mode and found that 'Historical' for a referenced indicator will not switch to 'false' on the phantom bar that NT injects on the first real time tick if the callee is updated on every bar. But if you skip the call to update the referenced indicator on the phantom bar, then 'Historical ' switches to false also for the referenced indicator. Is this behaviour expected?

                      I have attached 2 simple indicators where you can reproduce my print statments below if you run the Caller in Replay mode. (The injected phantom bar is nr 81 my example below.)

                      Best Regards
                      poseidon


                      Case 1: Calle updated on every bar

                      TestHistoricalCaller:
                      *******************************************
                      CurrentBar: 80
                      CalculateOnBarClose: False
                      Historical: True

                      TestHistoricalCallee:
                      ----------------------------------------------
                      CurrentBar: 80
                      CalculateOnBarClose: False
                      Historical: True


                      TestHistoricalCaller:
                      *******************************************
                      CurrentBar: 81
                      CalculateOnBarClose: False
                      Historical: False (Historical changes to False on phantom bar)

                      TestHistoricalCallee:
                      ----------------------------------------------
                      CurrentBar: 81
                      CalculateOnBarClose: False
                      Historical: True (Historical stays TRUE for the referenced indicator on the phantom bar)

                      Case 2: Calle updated on every bar except for the injected phantom bar

                      TestHistoricalCaller:
                      *******************************************
                      CurrentBar: 80
                      CalculateOnBarClose: False
                      Historical: True

                      TestHistoricalCallee:
                      ----------------------------------------------
                      CurrentBar: 80
                      CalculateOnBarClose: False
                      Historical: True


                      TestHistoricalCaller:
                      *******************************************
                      CurrentBar: 81
                      CalculateOnBarClose: False
                      Historical: False


                      TestHistoricalCallee:
                      ----------------------------------------------
                      CurrentBar: 81
                      CalculateOnBarClose: False
                      Historical: False
                      Attached Files
                      Last edited by poseidon_sthlm; 03-16-2015, 08:45 AM.

                      Comment


                        #12
                        Hello poseidon_sthlm,

                        Thank you for your post.

                        If the bar contains historical "pieces" it will be flagged Historical. Until a new bar is formed solely from real-time data, the Historical flag will be true.

                        Comment


                          #13
                          I understand the basic concept of the Historical property. My question relates to the specific situation when NT injects a phantom bar where historical data ends and real time data begins. As I have shown below, the property Historical on the injected phantom bar is TRUE for the calling indicator (Caller) but FALSE for the referenced indicator (Callee) , unless you skip the update call on this phantom bar. Isn't this an inconsistent behaviour?

                          /Poseidon
                          Last edited by poseidon_sthlm; 03-16-2015, 10:39 AM.

                          Comment


                            #14
                            Hello poseidon_sthlm,

                            Thank you for your response.

                            If you force an update to the callee before printing the values in the caller, it should correct this.
                            TestHistoricalCallee().Update();

                            Comment


                              #15
                              Hello again,

                              My key point is that this inconsistency for the Historical property on the phantom bar is caused by the update call. So my work around here is to skip the update call in the Caller on the phantom bar. Why is this work around required to make the Historical property FALSE also for the referenced indicator on the first real time tick?

                              The code is simple an I have attached the indicators in post #11.

                              Code:
                              public class TestHistoricalCaller : Indicator
                                  {	
                              
                              		/// Variables
                              		int alt					= 1;
                              		bool historicalCurrentBar	        = true;
                              		bool historicalPrevBar		= true;
                              		
                              		TestHistoricalCallee myTestHistoricalCallee;
                              		
                              
                              		protected override void OnStartUp()
                                              {
                              			myTestHistoricalCallee = TestHistoricalCallee();	/// Instantiate Indicator
                              		}
                              		
                              		
                                      protected override void OnBarUpdate()
                                      {		
                              			if ( FirstTickOfBar )
                              			{
                              				Print("");
                              				Print("TestHistoricalCaller:");
                              				Print("*******************************************");
                              				Print("CurrentBar: " + CurrentBar);
                              				Print("CalculateOnBarClose: " + CalculateOnBarClose);
                              				Print("Historical: " + Historical);
                              				
                              				historicalPrevBar 		= historicalCurrentBar;
                              				historicalCurrentBar 	= Historical;
                              				
                              				switch(alt)
                              				{
                              					case 1:	/// Update calle on every bar
                              						double v1 = myTestHistoricalCallee[0];
                              						break;
                              						
                              					case 2:	/// Don't update calle on the injected phantom bar
                              						if ( historicalPrevBar == historicalCurrentBar )
                                                                              {
                                                                                   double v2 = myTestHistoricalCallee[0];
                                                                              }
                              						break;
                              				}
                              				
                              				Print("");
                              			}	
                                      }
                              		
                              			#region Properties
                              		
                              			[GridCategory("Parameters")]
                              			public int Alt
                              			{
                              				get { return alt; }
                              				set { alt = Math.Max(value, 1); }
                              			}
                              			
                              			#endregion
                                  }

                              Code:
                                  public class TestHistoricalCallee : Indicator
                                  {	
                              
                                      protected override void OnBarUpdate()
                                      {		
                              			if ( FirstTickOfBar )
                              			{
                              				Print("");
                              				Print("TestHistoricalCallee:");
                              				Print("----------------------------------------------");
                              				Print("CurrentBar: " + CurrentBar);
                              				Print("CalculateOnBarClose: " + CalculateOnBarClose);
                              				Print("Historical: " + Historical);
                              			}
                                      }
                                  }
                              Last edited by poseidon_sthlm; 03-17-2015, 04:36 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by kujista, Today, 05:44 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by elderan, Yesterday, 08:03 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by samish18, Yesterday, 08:57 AM
                              8 responses
                              25 views
                              0 likes
                              Last Post samish18  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by RookieTrader, Today, 07:41 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post RookieTrader  
                              Working...
                              X