Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intraday crack spread indicator - RB contract not accessible

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

    Intraday crack spread indicator - RB contract not accessible

    Hi,

    I have a crack spread indicator the uses CL, RB, HO contracts that runs fine on a daily chart, however when I port the indicator to an intraday chart, say 15 min bars, the RB contract does not load and throws a Index out of range error, (see attached file). This happens ONLY for RB. HO contract has no problem, so when I change the order of the AddSeries, the Series that causes the error is always RB.

    Here is the code I use to add the series:

    Code:
    AddDataSeries("RB 09-16",Data.BarsPeriodType.Minute, 15,Data.MarketDataType.Last);
    AddDataSeries("HO 09-16",Data.BarsPeriodType.Minute, 15,Data.MarketDataType.Last);
    The Crack spread calculation that I am using:

    Code:
    Spread[0] = ((42*(RBcontracts*Closes[1][0] + HOcontracts*Closes[2][0]) - CLcontracts*Closes[0][0]) / Math.Max(1,CLcontracts));
    I'm running B12 on Windows10 Pro. IB data feed.

    Thanks in advance.
    Attached Files

    #2
    Hello ours_solaire, and thank you for your question.

    This is likely caused by OnBarUpdate being triggered by each of your bars series. The only time you are guaranteed to be able to access your HO bars is when BarsInProgress == 2, but this in turn means that your primary data series and RB bars are not guaranteed.

    You are going to have to use a programming strategy to keep everything in sync. To make things easy for you to do so, Ninja provides the CurrentBars array, which is docucmented here



    You are save to proceed when every member of CurrentBars has at least one bar.

    Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      the fix

      Thanks Jessica for the prompt reply.

      I added the following line before calculating the spread:

      Code:
      if(CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1) return;
      This seems to have corrected the problem, however I don't understand why this line is needed for intraday but not for daily bars. Can you explain the difference please?

      Comment


        #4
        This is because "under the hood" Ninja receives two kinds of data

        • Tick data. Every time a price changes, Ninja gets told. The advantage is that Ninja is more responsive, the disadvantage is that there is more data, which translates to reduced speed and increased bandwidth
        • Daily data. Once a day, data is compiled and sent to Ninja. The advantage is that this data is sparse, so Ninja has less to download and process. The disadvantage is that Ninja is not only less responsive, but less able to filter out unwanted data. This is why you can not apply session templates to daily bars.

        Because all your daily data likely comes in at once, it is all likely available from any series. Contrast this with tick data, which almost certainly comes in at different times, which Ninja reacts to as soon as it is available.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the clarification.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          21 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Working...
          X