Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index was outside the bounds of the array.

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

    Index was outside the bounds of the array.

    Hi,
    the following code is simple and straighforward. But there is always an error saying "Strategy 'MyCandleStopInStopOut': Error on calling 'OnBarUpdate' method on bar 20: Index was outside the bounds of the array." Does anybody know why ? And the error seems to be from bar 20 onward.
    Thanks !

    if (CurrentBar < 20)
    return;

    if (Close[1] > Open[1] && Value[0] > High[1]
    EnterLong(1, "Long Entry");



    #2
    Hello judysamnt7,


    From only that code I dont see what would cause that. do you know what specific line is having a problem? You can use Print statements to see how the logic is executing.




    Comment


      #3
      The purpose of this code above is to Enter a long order once current bar value goes above the previous bar's high, while previous bar is a green bar .

      Comment


        #4
        Hi Jesse,
        I believe the following line caused the out of bound of index error.
        if (Close[1] > Open[1] && Value[0] > High[1]

        Comment


          #5
          If I replaced Value[0] with Close[0], the error will be gone. Kind of weird.

          But what I really want is to check the real time price of current bar instead of close price. In this case, Can I still use Value[0] to get the tick by tick price of current bar ?

          Comment


            #6
            Hello judysamnt7,

            You may need a currentbar check:

            if(CurrentBar < 1) return;

            To know the realtime price you would need to use OnEachTick or OnPriceChange in realtime, that would let you see the Close[0] price as the realtime price.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            80 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            40 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            63 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            63 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            54 views
            0 likes
            Last Post CarlTrading  
            Working...
            X