why Close[Bars] generate an "array out of range" warning

 

if I get the current Bar number for example 65029, then Close[65029] will return the value, but if directly use the Close[Bars] statement at that time, it will generate an "array out of range" warning, except the line "#property strict" is not written in script,

is there any explanation for this?

sorry if this has already been discussed, please give me a link to the topic so I will go there and read it, thanks for the response.

The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market
  • www.mql5.com
Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
 
M Rusman Hn: if I get the current Bar number for example 65029, then Close[65029] will return the value, but if directly use the Close[Bars] statement at that time, it will generate an "array out of range" warning, except the line "#property strict" is not written in script, is there any explanation for this? sorry if this has already been discussed, please give me a link to the topic so I will go there and read it, thanks for the response.

The current bar is at index [ 0 ] and the oldest bar is at [ Bars - 1 ]. If you count from [ 0 ] to [ Bars - 1 ] , there will be a total of Bars.

 
Fernando Carreiro #:

The current bar is at index [ 0 ] and the oldest bar is at [ Bars - 1 ]. If you count from [ 0 ] to [ Bars - 1 ] , there will be a total of Bars.

ah, sorry I mean, in the example case I mentioned 65029 is the current total number of Bars,

but you are right, I was wrong trying to use the number of bars for the array elements, it has to be an index , I was also wrong in saying that Close[65029] will return a value, this also won't work if 65029 is the total bars.

so to get the last Close bar price (old bar) we have to use the last index, namely Bars-1, so it has to be Close[Bar-1], thank you sir

 
M Rusman Hn #: thank you sir
You are welcome!
Reason: