Expert Advisors Array Definition

 

Hello,

I write an Expert Advisors program that stores the Indicator values iEnvelopes, iBands and iMA in an Array.
Unfortunately, the program doesn't work. No prices are stored in the Array.

What must I do?

extern int SMA_Period = 4;
extern int SMA_Shift = 0;
extern int SMA_Method = 0;
double SMA[];

extern int Env_Period = 20;
extern int Env_Shift = 0;
extern double Env_Deviation = 0.12;
double Env_Upper[];
double Env_Lower[];

extern int Band_Period = 10;
extern int Bands_Shift = 0;
extern double B_Deviation = 1.5;

double Band_Upper[];
double Band_Main[];
double Band_Lower[];

int limit;
int Counted_bars;

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start(){


Counted_bars = IndicatorCounted();
if(Counted_bars<0) return(-1);
if(Counted_bars>0) Counted_bars--;
int i = Bars-Counted_bars-1;


while(i>=0) {

Env_Upper[i]= iEnvelopes(NULL, 0, Env_Period, MODE_SMA, Env_Shift, PRICE_CLOSE, Env_Deviation, MODE_UPPER, 0);
Env_Lower[i]= iEnvelopes(NULL, 0, Env_Period, MODE_SMA, Env_Shift, PRICE_CLOSE, Env_Deviation, MODE_LOWER, 0);

SMA[i]=iMA(NULL,0,SMA_Period,0,MODE_SMA,PRICE_CLOSE,0);

Band_Upper[i] = iBands(NULL, 0, Band_Period, B_Deviation, Bands_Shift, PRICE_CLOSE, MODE_UPPER, 0);
Band_Main[i] = iBands(NULL, 0, Band_Period, B_Deviation, Bands_Shift, PRICE_CLOSE, MODE_MAIN, 0);
Band_Lower[i] = iBands(NULL, 0, Band_Period, B_Deviation, Bands_Shift, PRICE_CLOSE, MODE_LOWER, 0);
i--;
}

Comment("\n Bars: ",Bars, "\n CountedBars= ", limit,
"\n \n SMA[0] ", SMA[0], "\n SMA[1] ", SMA[1], "\n SMA[2] ", SMA[2],
"\n \n Env_Upper[0]= ", Env_Upper[0], "\n Env_Upper[1]= ", Env_Upper[1],
"\n \n Band_Upper[0]= ", Band_Upper[0], "\n Band_Upper[1]= ", Band_Upper[1],
"\n \n Band_Main[0]= ", Band_Main[0], "\n Band_Main[1]= ", Band_Main[1],
"\n \n Band_Lower[0]= ", Band_Lower[0], "\n Band_Lower[1]= ", Band_Lower[1]);

return;
}


Thanks very much for each answer.

 

You have to declare the array size first:

int goodTimesArray[5];
Or use ArrayResize(): https://docs.mql4.com/array/ArrayResize . MQL doesn't use dynamic self sizing arrays.
 
jmca wrote >>

You have to declare the array size first:

Or use ArrayResize(): https://docs.mql4.com/array/ArrayResize . MQL doesn't use dynamic self sizing arrays.

Thanks very much.

 
jmca:

You have to declare the array size first:

Or use ArrayResize(): https://docs.mql4.com/array/ArrayResize . MQL doesn't use dynamic self sizing arrays.

It works for me, tq ........................May god guide you.

 
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Declare a fixed size, resize the arrays first, or make them buffers. learn to code