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 NullPointStrategies, Today, 05:17 AM
            0 responses
            44 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            65 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X