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

Secondary TimeFrame fires error

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

    Secondary TimeFrame fires error

    I have this code:



    put it on 60 min chart, and on bar 16th, it fires error;

    Indicator 'XXXX': Error on calling 'OnBarUpdate' method on bar 16: You are accessing an index with a value that is invalid since it is out-of-range...

    I cant understand what is the problem, because the PRINT shows that it has enough bars.

    #2
    Hello TazoTodua,
    Thanks for your post.

    You should be checking to see if your added Data Series has enough bars too. Your 'bar check' should be something like the following snippet.
    Code:
    if (CurrentBars[0]<=15 || CurrentBars[1]<=15) return;
    Help Guide - CurrentBars
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Josh, Many thanks. No errors come out, but :

      1) i still cant make it work. i.e.

      I have 5 day chart (60 min TF). If i just use this:

      Code:
      		protected override void OnBarUpdate()
      		{
      			if (CurrentBars[1]<=1 ) 
      			{
      				Draw.ArrowUp(this, "tag1"+CurrentBar, true, 0, Low[0] - TickSize, Brushes.Red);
      				return; 
      			}
      			//if (BarsInProgress !=0 ) return;
       
      			 Values[0][0]= Lows[1][0];
      		}
      it doesnt show for me (instead, i see N/A value in DataBox) during the first 4 days, instead, only starts to show up after 4 day passed from start bar. See the screenshot: even 1 day offseted value: https://i.imgur.com/OGCw3m8.png


      2) In other platforms, there are shorthand, like Close(period="day"). Is anyhting like that available in NT without a burden of need to AddDataSeries/CUrrentBars/BarsInProgress.... Just firing a quick function like that... ?
      Last edited by ttodua; 08-20-2018, 10:52 AM.

      Comment


        #4
        That snippet of code does not work for me.
        Are you sure you aren't getting any errors?
        Where is your 'bar check'?

        There is not another way to access other time frames without following the rules and considerations for multi-time frame scripts.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          no, i run that... here is full code:

          Comment


            #6
            Why is Draw.ArrowUp inside your 'bar check' return statement?

            I get an error with the code you provided. If you move Draw.ArrowUp outside of the return statement and just into OnBarUpdate() does it produce what you are looking for?
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Josh, sorry for that. you can just remove that DrawArrow completely, i dont care of that.

              the concept is that i got the line after 3 days, and even incorrectly, offseted 1 day...
              that is my problem.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by kevinenergy, 02-17-2023, 12:42 PM
              118 responses
              2,778 views
              1 like
              Last Post kevinenergy  
              Started by briansaul, Today, 05:31 AM
              0 responses
              9 views
              0 likes
              Last Post briansaul  
              Started by traderqz, Yesterday, 12:06 AM
              11 responses
              28 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by PaulMohn, Today, 03:49 AM
              0 responses
              8 views
              0 likes
              Last Post PaulMohn  
              Started by inanazsocial, Today, 01:15 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_Jason  
              Working...
              X