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

out of range index error with Draw.Text

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

    out of range index error with Draw.Text

    What is the best way to eliminate this error:

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

    Bars required to trade is 20

    I have this code:

    if (ShowLines ) Draw.Text(this, "Lable1", false,MyValue.ToString(), Convert.ToInt32((ChartBars.ToIndex-ChartBars.FromIndex)*0.1), LowOfRange-TickSize*2, 0, Brushes.Green, smallFont, TextAlignment.Justify, Brushes.Transparent, Brushes.Transparent, 0);

    thought about :
    if (ShowLines && CurrentBar > 50) Draw.Text(this .....

    not working...

    #2
    Hello dadarara,

    Thank you for your note.

    If you replace the following with 5, does the code work without exception?

    Convert.ToInt32((ChartBars.ToIndex-ChartBars.FromIndex)*0.1)

    I look forward to your reply.

    Alan P.NinjaTrader Customer Service

    Comment


      #3
      yes it does.
      but I was wondering why the number of visible bars on screen at the moment of strategy initiation would matter to historical calculation?
      and what would be the better practice if I wish to draw.text at some offset from the right of the chart that should also be related to the total number of bars.
      cant be 5. on chart of 60min it might work. but with 30sec chart there are much more bars so 5 would be insignificant number.
      Last edited by dadarara; 10-07-2018, 02:20 PM.

      Comment


        #4
        I am not yet clear of how to do it, please help

        Comment


          #5
          Hello dadarara,

          You should ensure that CurrentBar > Convert.ToInt32((ChartBars.ToIndex-ChartBars.FromIndex)*0.1) if you wish to use that value as an offset. See current bar checks,


          Why would passing a 5 for the BarsAgo not work for drawing text 5 bars back from the CurrentBar?

          I look forward to your reply.
          Alan P.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by f.saeidi, Today, 11:02 AM
          1 response
          1 view
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by geotrades1, Today, 10:02 AM
          4 responses
          12 views
          0 likes
          Last Post geotrades1  
          Started by rajendrasubedi2023, Today, 09:50 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by lorem, Today, 09:18 AM
          2 responses
          11 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by geddyisodin, Today, 05:20 AM
          4 responses
          30 views
          0 likes
          Last Post geddyisodin  
          Working...
          X