• 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

Multi-DataSeries: OnBarUpdate() Live vs Sim Behavior

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

    Multi-DataSeries: OnBarUpdate() Live vs Sim Behavior

    Hello, I have a few questions concerning how OnBarUpdate() gets triggered and when data becomes available when dealing with the dynamics of a multi-dataseries strategy.

    it is my understanding that NT8 triggers OnBarUpdate() for every new bar event for every unique data series added to a strategy.

    if this is the case then let's assume I have a strategy in which the primary series is USDJPY, 1 Minute TimeFrame, and I added the following additional data series in the following order:

    Code:
    protected override void OnStateChange()
    {
      if (State == State.SetDefaults)
      {            
            Name   = "Multi-Time Frame & Instruments Example";
      }
      else if (State == State.Configure)
      {  
        AddDataSeries(BarsPeriodType.Minute, 5);               // 5 minute USDJPY dataseries
        AddDataSeries("EURUSD", BarsPeriodType.Minute, 1);     // 1 minute EURUSD dataseries
        AddDataSeries("GBPJPY", BarsPeriodType.Minute, 1);     // 1 minute GBPJPY dataseries
      }
    }
    Questions:


    1. Given above, if a new bar event raises for all the data series then what is the order in which these events are processed?

    here are two scenerios I can think of:
    a) OnBarUpdate() is triggered "randomly". Meaning in whichever order the new bar events happened to occur (non-predictable) that is the order in which they will be processed.
    b) OnBarUpdate() is triggered sequentially based on the order in which the data series were added. Meaning USDJPY 1 Minute gets OnBarUpdate() triggered first since it is the primary series. Then USDJPY 5 minute and so on..

    2. Does the answer to question 1 differ if the strategy is running Live or Sim(backtest)?

    3. Let's assume a new bar from 1 Minute USDJPY dataseries (the primary series) is responsible for triggering OnBarUpdate() first. Given the code below, is the primary series (USDJPY 1 Minute) comparing it's open price, which happens to be the open price of the same bar that triggered OnBarUpdate(), to the open price of the latest USDJPY 5 Minute bar (the bar that has raised a new bar event but has yet to be processed / trigger OnBarUpdate) or is it comparing to the open price of the last USDJPY 5 minute bar that triggered OnBarUpdate() which occurred about 5 minutes ago in this pseudo-example.

    Code:
    protected override void OnBarUpdate()
    {    
        if (BarsInProgress == 0)
        {
            if (Opens[0][0] > Opens[1][0])
            Print("The primary bar's open price (USDJPY 1 Minute) is greater than USDJPY 5 Minute bar open price");
        }
    }
    To rephrase question 3 more simply, does a bar that has raised a new bar event become accessible within a multi-series strategy before the new bar event has triggered OnBarUpdate() or is the bar made available ONLY when OnBarUpdate() is triggered.


    Thank you in advance and I hope I'm not overcomplicating things too much but just want to be extremely precise and confident in trading logic and minimize as much live vs sim discrepancies as possible.

    #2
    Hello pharofx, thanks for your post and welcome to the NinjaTrader forum.

    For question 1, if the script's Calculate property is Calculate.OnBarClose then the script will process the BarsInProgress in the order they were added starting with the primary series with the exception of the 5-minute series you added. That will be called every 5 minutes, messing up the order because it's a higher period. If all the series were 1 minute, they would process in the order they were added.

    For question 2, you need at least one 5 minute bar in order to access Opens[1][0], in your script you would write:

    Code:
    OnBarUpdate()
    {
        if(CurrentBars[0] < 0 || CurrentBars[1] < 0 || CurrentBars[2] < 0 || CurrentBars[3] < 0)
            return;
    
        //Otherwise, here you have at least one 5 minute bar to access.
    }
    In real time data, if a 1 minute series is "in the middle" of a 5 minute series, then the last 5 minute bar that was made will be referenced by Opens[1][0].

    Best regards.

    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mkoning, Today, 04:20 PM
    0 responses
    1 view
    0 likes
    Last Post mkoning
    by mkoning
     
    Started by itrader46, Today, 02:59 PM
    3 responses
    7 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by madams212121, Today, 12:10 PM
    13 responses
    28 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by jvanelli, Today, 12:19 PM
    1 response
    20 views
    0 likes
    Last Post NinjaTrader_BrendanC  
    Started by raaxus, Today, 11:17 AM
    3 responses
    21 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Working...
    X