• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Tick Replay - Intrabar Update

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

    Tick Replay - Intrabar Update

    Hi,

    Using tick replay (or not using if there's an alternate solution), during a backtest, is it possible for OnBarUpdate to be called for each tick when using a higher timeframe for the back test (15 mins as an example).

    I know I can add a 1 tick series, but I want to get the 15 minute bar values on each tick as the bar is being built, not when it is complete, so for example if the most recent tick was a new high in that 15 minute period, I want to access a 15 minute bar with that tick as the high.

    I know I can get data from OnMarketData, but I don't think this updates the bars.

    Thanks

    #2
    Hello tmfdouglas,

    Thank you for your note.

    If you add a 1 tick series to your script OnBarUpdate will be called on each new tick. If you run your strategy with Calculate to OnEachTick, then the 15 minute series in the strategy will reflect the last price.

    I would suggest the following example of how to pull in a secondary tick series,
    https://ninjatrader.com/support/foru...ead.php?t=6652

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response, the solution you detail is what I expected to be the case, although when I try it the latest 15 min bar is only ever updated once that time period has closed (so 15, 30, 45, 00), not each time there is a new tick.

      Below is the strategy I've been using to test, and attached is a screenshot of the outputted bar data. What I'm trying to achieve is to get the most recent data from the 15 min bar as it's being built, so for example at 14:07 which I expect in most cases some of the values would be different to 14:02. I'd expect at 14:07 for the close of the current 15 min bar to be the same as the latest tick.

      When accessing index [0] of the 15 minute series it's always the previous closed bar though.


      Code:
      		protected override void OnStateChange()
      		{
      			if(State == State.SetDefaults)
      			{				
      				Calculate		= Calculate.OnEachTick;
      				Name			= "SampleIntrabarBacktest";
      			}
      			
      			else if(State == State.Configure)
      			{
      				AddDataSeries(Data.BarsPeriodType.Tick, 1);
      			}
              }
      
      		protected override void OnBarUpdate()
      		{
      			/// Large number to ensure bar index error isn't seen, run backtest over 2 months of data
      			if (BarsInProgress == 1 && CurrentBar < 10000)
      				return;
      			
      			Print("BarInProgress " + BarsInProgress + "  |  1 Tick DateTime: " + Time[0].ToString("dd-MM-yyyy HH:mm:ss") + " |  1 Tick Last: " + Close[0] + "  |  15 Min DT: " + Times[0][0] + "  |  15 Min Close: " + Closes[0][0] + "  |  15 Min High: " + Highs[0][0] + "  | 15 Min Open: " + Opens[0][0] + "  |  15 Min Low: " + Lows[0][0]);
      		}
      Attached Files

      Comment


        #4
        Hello tmfdouglas,

        If you replace what you have in OnBarUpdate with the following,

        Code:
        if (CurrentBars[0] < 20 || CurrentBars[1] < 20) return;
        
        Print(Closes[0][0].ToString());
        Print("10 min series"+Closes[1][0].ToString());
        You should see the prints for the 15 minute series.

        What you have in OBU is not letting the secondary tick series trigger OBU.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          if I run your code the print from Print(Closes[0][0].ToString()) is the same value for times OnBarUpdate is called by the tick series during that bar time period (15 min in this case).

          What I'm after is for the 15 min bar (in this case the primary data series) to be updated on each tick, not at the close of the bar, so each time OnBarUpdate is called I can access the value of the min 15 bar as it is being built, before it is closed.

          Example of what I'm running produces results such as the below, as you can see even when OnBarUpdate has been triggered, if I access the primary date series (15 mins), it returns the same values as when that bar was created (so first line shows the latest 15 min bar, following lines are triggered by the tick data series, but return the same values for the 15 min primary series, close of 1.17203 an example).

          BarInProgress 0 | 1 Tick DateTime: 20-07-2018 21:45:00 | 1 Tick Last: 1.17203 | 15 Min DT: 20/07/2018 21:45:00 | 15 Min Close: 1.17203 | 15 Min High: 1.17249 | 15 Min Open: 1.17239 | 15 Min Low: 1.17174
          1.17203
          10 min series1.17204 Open: 1.17204
          BarInProgress 1 | 1 Tick DateTime: 20-07-2018 21:45:00 | 1 Tick Last: 1.17204 | 15 Min DT: 20/07/2018 21:45:00 | 15 Min Close: 1.17203 | 15 Min High: 1.17249 | 15 Min Open: 1.17239 | 15 Min Low: 1.17174
          1.17203
          10 min series1.17204 Open: 1.17204
          BarInProgress 1 | 1 Tick DateTime: 20-07-2018 21:45:01 | 1 Tick Last: 1.17204 | 15 Min DT: 20/07/2018 21:45:00 | 15 Min Close: 1.17203 | 15 Min High: 1.17249 | 15 Min Open: 1.17239 | 15 Min Low: 1.17174
          1.17203
          10 min series1.17203 Open: 1.17203
          BarInProgress 1 | 1 Tick DateTime: 20-07-2018 21:45:03 | 1 Tick Last: 1.17203 | 15 Min DT: 20/07/2018 21:45:00 | 15 Min Close: 1.17203 | 15 Min High: 1.17249 | 15 Min Open: 1.17239 | 15 Min Low: 1.17174
          1.17203
          10 min series1.17204 Open: 1.17204
          BarInProgress 1 | 1 Tick DateTime: 20-07-2018 21:45:03 | 1 Tick Last: 1.17204 | 15 Min DT: 20/07/2018 21:45:00 | 15 Min Close: 1.17203 | 15 Min High: 1.17249 | 15 Min Open: 1.17239 | 15 Min Low: 1.17174
          1.17203
          10 min series1.17204 Open: 1.17204
          BarInProgress 1 | 1 Tick DateTime: 20-07-2018 21:45:04 | 1 Tick Last: 1.17204 | 15 Min DT: 20/07/2018 21:45:00 | 15 Min Close: 1.17203 | 15 Min High: 1.17249 | 15 Min Open: 1.17239 | 15 Min Low: 1.17174

          Code:
          		protected override void OnStateChange()
          		{
          			if(State == State.SetDefaults)
          			{				
          				Calculate		= Calculate.OnEachTick;
          				Name			= "SampleIntrabarBacktest";
          			}
          			
          			else if(State == State.Configure)
          			{
          				AddDataSeries(Data.BarsPeriodType.Tick, 1);
          			}
                  }
          
          		protected override void OnBarUpdate()
          		{
          			if (CurrentBars[0] < 20 || CurrentBars[1] < 20) return;
          
          			Print(Closes[0][0].ToString());
          			Print("10 min series" + Closes[1][0].ToString() + " Open: " + Opens[1][0].ToString());
          
          			Print("BarInProgress " + BarsInProgress + "  |  1 Tick DateTime: " + Time[0].ToString("dd-MM-yyyy HH:mm:ss") + " |  1 Tick Last: " + Close[0] + "  |  15 Min DT: " + Times[0][0] + "  |  15 Min Close: " + Closes[0][0] + "  |  15 Min High: " + Highs[0][0] + "  | 15 Min Open: " + Opens[0][0] + "  |  15 Min Low: " + Lows[0][0]);			
          		}

          Comment


            #6
            Hello tmfdouglas,

            If you run the code I provided in real time you will see prints of the current 15 minute bar as it updates.

            Why this is not the case historically, which is what you’re seeing for your 7-20-18 prints, has to do with note 2 at the following link under Data processing sequence,

            https://ninjatrader.com/support/help...meFrameObjects

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              I'm still not clear, I've read the link you've posted before, but it's referring to the timestamps of bars, rather than the frequency they're updated. I understand that the sequence of events can differ historically, but it's that these events aren't happening that I'm asking about, in this context the event is the 15 min bar being updated by each new tick and triggering OnBarUpdate, but is it only being triggered once at the end of each 15 min period.

              Is there a way to make the 15 min bar trigger OnBarUpdate when a new tick is processed when running historically?

              If so to also get the updated value on the current 15 min bar, for example if the new tick was the highest in that 15 min period the new highest value, and the new close value as whilst in the majority of cases there'll be more ticks to be processed in that 15 min period, it's the last tick the strategy is aware of at that time.

              Thanks

              Comment


                #8
                Hello tmfdouglas,

                Yes, you could enable tick reply.

                See,
                https://ninjatrader.com/support/help...ick_replay.htm

                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  That's what I thought, and what I've been trying, but as you can see from the attached screenshot even when using tick replay the results of the previous 15 min bar are still persisted even when more recent ticks are processed in OnBarUpdate.
                  Attached Files

                  Comment


                    #10
                    Hello tmfdouglas,

                    Could you please send an email to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link t o this thread, and attach the log and trace files for the day in subject which you can find in My Documents>NinjaTrader8>Log and My Documents>NinjaTrader8/Trace folders.

                    I look forward to your email.
                    Alan P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by hurleydood, Today, 12:34 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post hurleydood  
                    Started by smf2005, Today, 11:51 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Kate  
                    Started by ksarin, Today, 12:17 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post ksarin
                    by ksarin
                     
                    Started by cpabiz20k, Today, 11:45 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_PaulH  
                    Started by toughnedglass, Yesterday, 11:36 AM
                    1 response
                    15 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X