Download MetaTrader 5

Expert Advisors Array Definition

To add comments, please log in or register
Searching on MQL5.community is performed in all sections. Try it!
SAM
28
SAM 2009.01.09 17:25 

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.

Justin Abene
203
Justin Abene 2009.01.09 19:09  

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.
SAM
28
SAM 2009.01.10 14:39  
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.

Mamat Husim
19
Mamat Husim 2016.10.13 15:04  
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.

whroeder1
14512
whroeder1 2016.10.13 15:29  
  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
To add comments, please log in or register