Download MetaTrader 5
To add comments, please log in or register
Subscribe to signals right in MetaTrader. It is easy!
chua le
234
chua le 2016.02.28 05:38 
//+------------------------------------------------------------------+
//| Pips Indicator.mq4                                    |
//| Chua Le                                                          |
//| https://www.forex-tsd.com                                         |
//+------------------------------------------------------------------+
#property copyright "Chuale"
#property link "http://www.abc.com"


double     EmaEURUSD,EmaGBPUSD,EmaAUDUSD,EmaEURJPY,EmaGBPJPY;
double     S_Array[5];
int        xMultiply;
   
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators

//----
return(1);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- check for possible errors
if (counted_bars<0) return(-1);
//---- last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int pos=Bars-counted_bars;
//---- main calculation loop
while(pos>=0)
{
   EmaEURUSD = iMA("EURUSD",PERIOD_H1,100,0,MODE_EMA,PRICE_CLOSE,0);
   EmaGBPUSD = iMA("GBPUSD",PERIOD_H1,100,0,MODE_EMA,PRICE_CLOSE,0);
   EmaAUDUSD = iMA("AUDUSD",PERIOD_H1,100,0,MODE_EMA,PRICE_CLOSE,0);
   EmaEURJPY = iMA("EURJPY",PERIOD_H1,100,0,MODE_EMA,PRICE_CLOSE,0);
   EmaGBPJPY = iMA("GBPJPY",PERIOD_H1,100,0,MODE_EMA,PRICE_CLOSE,0);
   S_Array[27]={EmaEURUSD,EmaGBPUSD,EmaAUDUSD,EmaEURJPY,EmaGBPJPY};
   ArraySort(S_Array,MODE_DESCEND); 
Comment ("1 = "+DoubleToString(S_Array[0],Digits)+"\n"+
         "2 = "+DoubleToString(S_Array[1],Digits)+"\n"+
         "3 = "+DoubleToString(S_Array[2],Digits)+"\n"+
         "4 = "+DoubleToString(S_Array[3],Digits)+"\n"+
         "5 = "+DoubleToString(S_Array[4],Digits)+"\n"
           );         
pos--;
}
return(0);
}
chua le
234
chua le 2016.02.28 05:39  

Dear All,

 

I have the above simple indicator with the error of "constant Expression Required" after compilation. Kindly help.

 

thank you 

Ovo Cz
2955
Ovo Cz 2016.02.28 07:43  
double S_Array[]={.....};
can contain only constants, no variables nor expressions.
Carl Schreiber
5962
Carl Schreiber 2016.02.28 09:02  
chuale:

Dear All,

 

I have the above simple indicator with the error of "constant Expression Required" after compilation. Kindly help.

 

thank you 

You should read about the use of arrays (a bit out-dated) and dynamic arrays!

1) You defined a static array which cannot change the size:

double     S_Array[5];
...
    S_Array[27]={EmaEURUSD,EmaGBPUSD,EmaAUDUSD,EmaEURJPY,EmaGBPJPY}; // no compiler error here?

2) As Ovo said you can only assign values (numbers, strings) to an array - one by one, like:

S_Array[0] = EmaEURUSD;
/
To add comments, please log in or register