Script Array Out Of Bounds After Using CopyOpen

 

Hi everyone,

I am trying to get a 7200 close quotes from CopyClose. It is working well however I do not know if I have enough elements in my array/chart. Heres my code:


#property show_inputs
extern int num_of_5_minute_candles = 7200; // M5 in one week

void OnStart()
{
   double Close_Array[];
   ArrayResize(Close_Array, num_of_5_minute_candles);
   
   Print("a: " + ArraySize(Close_Array));
   
   string str = SymbolName(0, false);
   
   CopyClose(str, PERIOD_M5, 0, num_of_5_minute_candles, Close_Array);
   
   int b = ArraySize(Close_Array);
   
   Print("b: " + b);
   
}

a: 7200

b: 4585

These values come from the terminal after the script is executed. It is very important that I get 7200 values. Is there any way I can do this? When I try to find Close_Array[] values greater than 4585 then I get out of bounds exception. 

 

What is the value of b when you choose for example:


num_of_5_minute_candles = 20;


Did you check if you have enough candle data on your chart ( iBars() )?

 
Amine Abed #:

What is the value of b when you choose for example:



Did you check if you have enough candle data on your chart ( iBars() )?

When I change num_of_5_minute_candles = 20 a=20 and b=20 when I print the values. I do not understand the link you have sent. 

 
PublicImageLtd #: I am trying to get a 7200 close quotes from CopyClose. It is working well however I do not know if I have enough elements in my array/chart. These values come from the terminal after the script is executed. It is very important that I get 7200 values. Is there any way I can do this? When I try to find Close_Array[] values greater than 4585 then I get out of bounds exception ...  When I change num_of_5_minute_candles = 20 a=20 and b=20 when I print the values.

You should first see if the amount of available history is enough for your request. You may want 7200, but the amount of chart history may only have 4585 to offer.

So verify that you have that amount of data available. Read the documentation on the function iBars() as well SeriesInfoInteger() and the following properties:

ENUM_SERIES_INFO_INTEGER

Identifier

Description

Type

SERIES_BARS_COUNT

Bars count for the symbol-period for the current moment

long

SERIES_FIRSTDATE

The very first date for the symbol-period for the current moment

datetime

SERIES_LASTBAR_DATE

Open time of the last bar of the symbol-period

datetime

SERIES_SERVER_FIRSTDATE

The very first date in the history of the symbol on the server regardless of the timeframe

datetime

SERIES_TERMINAL_FIRSTDATE

The very first date in the history of the symbol in the client terminal, regardless of the timeframe

datetime

SERIES_SYNCHRONIZED

Symbol/period data synchronization flag for the current moment

bool

 
PublicImageLtd #:

When I change num_of_5_minute_candles = 20 a=20 and b=20 when I print the values. I do not understand the link you have sent. 

I didn't send a link. MQL5 website does that by itself somehow.


I think you don't have enough bars on your chart.