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,
    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


    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,



            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,


                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 elderan, Today, 08:03 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post elderan
                    by elderan
                     
                    Started by algospoke, Today, 06:40 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post algospoke  
                    Started by maybeimnotrader, Today, 05:46 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post maybeimnotrader  
                    Started by quantismo, Today, 05:13 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post quantismo  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    8 responses
                    169 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X