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

PeriodType && BarsArray

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

    PeriodType && BarsArray

    hello everyone and congratulations for the excellent support.
    after days that I'm breaking my head to solve a problem I decided to play the help from home.

    I'm developing an indicator Nt7 that works on the 30min time frame and I need to develop some calculations using the LinReg calculated on the closing of the previous day but on the 1 DAY time frame.

    I stated this in the Initialize:

    protected override void Initialize()
    {
    Add(PeriodType.Day, 1); //dataseries1
    }


    & this in the OnBarUpdate:

    protected override void OnBarUpdate()
    {
    if (CurrentBars[1]==0&&BarsPeriod.Id == PeriodType.Day && BarsPeriod.Value >= 21)
    {
    double LinRegValue = LinReg(BarsArray[1], 18)[0];
    }
    }


    But this code with the start of the market replay continues to generate errors of this type:
    Error on calling 'OnBarUpdate' method for indicator 'IndicatorsLinReg' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    thanks for a support
    Chris

    #2
    Hello Chris,

    Thanks for your inquiry.

    In your code, you are referencing your daily data series before a daily bar is built.

    As we can see from the error, on bar 0, we hit an indexing error. In your code we see a reference to the daily series when that daily series is on bar 0. Since LinReg() has a period of 18, you will need 18 bars of daily data for the indicator to work without error.

    When debugging, I recommend to place prints to see how far you code gets before you hit an error. Once you identify a problematic line, the next step would be to identify any issues with the way that line is written.

    I've included some development tips for debugging and making sure you have enough bars for the data series you are referencing.

    Debugging - https://ninjatrader.com/support/foru...ead.php?t=3418

    Making sure you have enough bars - https://ninjatrader.com/support/foru...ead.php?t=3170

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      good morning,
      I thought a lot and added debub with the print function.
      I think I have come to the conclusion that I have a problem with OnBarUpdate ().

      protected override void OnBarUpdate()
      {
      Print("CurrentDay step A : " + CurrentDay);
      if (BarsInProgress == 1)
      {Print("stop0 " + CurrentBar + " " + ToTime(Time[0])+ " "+ CurrentDay);
      return;
      }
      if (BarsInProgress == 1&&BarsInProgress == 0)
      {Print("@@ OK @@ " + CurrentBar + " " + ToTime(Time[0])+ " "+ CurrentDay);
      }
      if (CurrentBar <1)
      {Print("stop1 " + CurrentBar + " " + ToTime(Time[0])+ " "+ CurrentDay);
      return;
      }
      if (CurrentBars[1] <1)
      {Print("stop2 " + CurrentBar + " " + ToTime(Time[0])+ " "+ CurrentDay);
      return;
      }


      the code above excludes the logic on the BarsArray [1] so that OnBarUpdate () works only on the primary data set.

      However, I believe that at 8:00 am when the OnBarUpdate () of both the 30-minute candle and the 1D candle occurs, the logic stops the call also on the 30-minute bar of the BarsArray [0].
      This happens to me in the market replay.

      this is the log of the debug that just shows that onbarupdate does not intervene to the formation of the bar at H 8.00. (I also attach a screen) :

      CurrentDay step A : 20180223
      190000 CurrentBar: 973 CurrentBar[1]: 50 Open : 12480,5 state:FirstMorningBar day :20180223
      CurrentDay step A : 20180223
      193000 CurrentBar: 974 CurrentBar[1]: 50 Open : 12484,5 state:FirstMorningBar day :20180223
      CurrentDay step A : 20180223
      200000 CurrentBar: 975 CurrentBar[1]: 50 Open : 12487,5 state:FirstMorningBar day :20180223
      CurrentDay step A : 20180223
      203000 CurrentBar: 976 CurrentBar[1]: 50 Open : 12496 state:FirstMorningBar day :20180223
      CurrentDay step A : 20180223
      210000 CurrentBar: 977 CurrentBar[1]: 50 Open : 12493 state:FirstMorningBar day :20180223
      CurrentDay step A : 20180223
      213000 CurrentBar: 978 CurrentBar[1]: 50 Open : 12511,5 state:FirstMorningBar day :20180223
      CurrentDay step A : 20180223
      GlobalProfit 0
      220000 CurrentBar: 979 CurrentBar[1]: 51 Open : 12528 state:FirstMorningBar day :20180223
      CurrentDay step A : 20180223
      stop0 51 220000 20180223


      thanks for the precious support.
      Attached Files

      Comment


        #4
        Hello

        Thanks for your reply.

        I am not entirely clear on the issue you are now encountering.

        I see that you skip out of all operations after your print on BarsInProgress 1 and you also have a condition that checks if current iterating bar is BarsInProgress 1 and BarsInProgress 0. This second condition cannot be true.

        without the full context of the code and further detail on the issue you are hitting I cannot provide much further input.

        Considering the noted programming issues, I may suggest reviewing the Multi Time Frame and Instruments documentation while debugging your code as it provides a complete guide for creating and using Multi Series NinjaScripts. I will provide a link below.

        Multi Series NinjaScripts (Important read!) - https://ninjatrader.com/support/help...nstruments.htm

        After reviewing this material, please let us know if you are still encountering issues and please provide any further description of what you expect to see so we can be of additional help.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Today, 03:20 PM
        0 responses
        5 views
        0 likes
        Last Post cre8able  
        Started by Fran888, 02-16-2024, 10:48 AM
        3 responses
        47 views
        0 likes
        Last Post Sam2515
        by Sam2515
         
        Started by martin70, 03-24-2023, 04:58 AM
        15 responses
        114 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by The_Sec, Today, 02:29 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        32 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X