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 pechtri, 06-22-2023, 02:31 AM
          9 responses
          122 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by frankthearm, 04-18-2024, 09:08 AM
          16 responses
          66 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by habeebft, Today, 01:18 PM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by benmarkal, Today, 12:52 PM
          2 responses
          14 views
          0 likes
          Last Post benmarkal  
          Started by f.saeidi, Today, 01:38 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X