Download MetaTrader 5

Problem in change array size

To add comments, please log in or register
Mehrdad Shiri
4507
Mehrdad Shiri 2015.01.30 09:01 

hi

i have problem in my indicator. can you please check this:

i use several array ; like this :

.
.
#define BAR_COUNT 100
.
.
double A[BAR_COUNT],B[BAR_COUNT];
.
.
//+------------------------------------------------------------------+
void OnInit()
  {
   .
.
}
//+------------------------------------------------------------------+
int OnCalculate()
{
.
.
//--- done
   return(rates_total);
}
//+------------------------------------------------------------------+
*** SEVERAL SUBPROGRAME AND SOME OF THEM USING : " BAR_COUNT "

AND IT WORK.

now i want to get the value of " BAR_COUNT" from another indicator, so i modified the code as below:

( modification are highlithed )

.
.
#define BAR_COUNT 100
.
.
double A[BAR_COUNT],B[BAR_COUNT];
.
.
double BASE[];
.
.
//+------------------------------------------------------------------+
void OnInit()
  {
   .
.
   SetIndexBuffer(36,BASE,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(BASE,true);
   BASE_handle=iCustom(NULL,0,"Examples\\INDICATOR NAME ");
.
.
}
//+------------------------------------------------------------------+
int OnCalculate()
{
.
.
   int copy__4=CopyBuffer(BASE_handle,27,0,12,BASE);
   #define  BAR_COUNT BASE[2]
   ArrayResize(A,BASE[2],BASE[2]); for(int i=1;i<BASE[2];i++) ArrayResize(A,i,BASE[2]);
   ArrayResize(B,BASE[2],BASE[2]); for(int i=1;i<BASE[2];i++) ArrayResize(B,i,BASE[2]);
.
.
//--- done
   return(rates_total);
}
//+------------------------------------------------------------------+
*** SEVERAL SUBPROGRAME AND SOME OF THEM USING : " BAR_COUNT "

so i get the value , but i have problem about it..( if it about array resize or is it nessary, ) 

***   https://www.mql5.com/en/docs/array/arrayresize

*** Note : The function can be applied only to dynamic arrays. It should be noted that you cannot change the size of dynamic arrays assigned as indicator buffers by the SetIndexBuffer() function. For indicator buffers, all operations of resizing are performed by the runtime subsystem of the terminal.

--->  i dont use them as indicator buffers.

---------------------------------------------

can you please help?

thank you.
Documentation on MQL5: Array Functions / ArrayResize
Documentation on MQL5: Array Functions / ArrayResize
  • www.mql5.com
Array Functions / ArrayResize - Reference on algorithmic/automated trading language for MetaTrader 5
Dr.Trader
3803
Dr.Trader 2015.01.31 11:06  
double A[BAR_COUNT],B[BAR_COUNT];

Is not a dynamic array. You should use following data declaration:

double A[],B[];

In this case array size is dynamic, and it can be resized.

Also, you don't need this part marked with red color, you can delete it.

ArrayResize(A,BASE[2],BASE[2]); for(int i=1;i<BASE[2];i++) ArrayResize(A,i,BASE[2]);
ArrayResize(A,BASE[2],BASE[2]); is enough. 
Mehrdad Shiri
4507
Mehrdad Shiri 2015.01.31 13:15  
Dr.Trader:
thank you.
To add comments, please log in or register