iBands method is giving very big value

 

Hi all,


I am using BilingerBands in my EA but it is returning very big value as follows which is definitely not correct.


9.881312916824931e-324


Following is the code of OnTick method:

void OnTick()
{
   //-Sorting array from current candle downward..
   ArraySetAsSeries(lowerBollingerBandArray, true);
   
   //-Defining bollinger bands..
   bollingerBandDefination = iBands("EURUSD", PERIOD_H1, 20, 0, 2, PRICE_CLOSE);
   
   //-Copying lower bollinger band data into array..
   CopyBuffer(bollingerBandDefination, 2, 0, 3, lowerBollingerBandArray);
   
   Print("EURUSD" + ":" + (string)(lowerBollingerBandArray[1]));
}

Please help...

 
salirazataqvi:

Hi all,


I am using BilingerBands in my EA but it is returning very big value as follows which is definitely not correct.


9.881312916824931e-324


Following is the code of OnTick method:


Please help...

This value is EMPTY_VALUE, which is normal considering the way you coded it.

Please read the documentation. Get the handle in OnInit(). Check your returned value.

 
Ahmad Zuhairdi Noh:

Yup, Alain is correct. Read the documentation. Here as a starter.

Try the following:

or

The topic is about mql5. Your answer will confuse people.
 
MQL5 has a slightly different logic. Get used to writing correctly.
double lowerBollingerBandArray[];
int bollingerBandDefination;

int OnInit()
{
   //-Sorting array from current candle downward..
   ArraySetAsSeries(lowerBollingerBandArray, true);
   
   //-Defining bollinger bands..
   bollingerBandDefination = iBands("EURUSD", PERIOD_H1, 20, 0, 2, PRICE_CLOSE);
     
     return(INIT_SUCCEEDED);
}

void OnTick()
{
   //-Copying lower bollinger band data into array..
   if( CopyBuffer(bollingerBandDefination, 2, 0, 3, lowerBollingerBandArray) < 3 ) return;
   
   Print ( "EURUSD: " + DoubleToString(lowerBollingerBandArray[1], (int)SymbolInfoInteger("EURUSD", SYMBOL_DIGITS)));
}
 
Alain Verleyen:
salirazataqvi: 9.881312916824931e-324

This value is EMPTY_VALUE,

Not EV.

Constant Description Value
EMPTY_VALUE Empty value in an indicator buffer DBL_MAX
          Standard Constants, Enumerations and Structures / Named Constants / Other Constants - Reference on algorithmic/automated trading language for MetaTrader 5

Constant Description Value
DBL_MIN Minimal positive value, which can be represented by double type 2.2250738585072014e-308

DBL_MAX

Maximal value, which can be represented by double type

1.7976931348623158e+308

          Standard Constants, Enumerations and Structures / Named Constants / Numerical Type Constants - Reference on algorithmic/automated trading language for MetaTrader 5
 
whroeder1:
Not EV.

Constant Description Value
EMPTY_VALUE Empty value in an indicator buffer DBL_MAX
          Standard Constants, Enumerations and Structures / Named Constants / Other Constants - Reference on algorithmic/automated trading language for MetaTrader 5


Constant Description Value
DBL_MIN Minimal positive value, which can be represented by double type 2.2250738585072014e-308

DBL_MAX

Maximal value, which can be represented by double type

1.7976931348623158e+308

          Standard Constants, Enumerations and Structures / Named Constants / Numerical Type Constants - Reference on algorithmic/automated trading language for MetaTrader 5
Right, it's just a wrong value as the OP didn't check the functions returned values.
 

Thanks all of you for your help. One more question. I am trying to develop multi currency EA, do I need to declare separate variable for handler, and price array as I need to perform same analysis for all currency pairs.


If this is the case I have to write the code when ever I add new currency pair. Cant I use array for handler and an two dimensional array of price. I tried to do this but dint succeed.


Please help in this regards.


Thanks.

 
string symbols[3] = {"EURUSD", "GBPUSD", "USDCHF"};
struct BANDS
{
     int       digits,
               bollingerBandDefination;
     double    lowerBollingerBandArray[];
} bands[3];

int OnInit()
{
     for(int i=0; i<3; i++)
     {
          //-Sorting array from current candle downward..
          ArraySetAsSeries(bands[i].lowerBollingerBandArray, true);
   
          bands[i].digits = (int)SymbolInfoInteger(symbols[i], SYMBOL_DIGITS);
          //-Defining bollinger bands..
          bands[i].bollingerBandDefination = iBands(symbols[i], PERIOD_H1, 20, 0, 2, PRICE_CLOSE);
     }
     
     return(INIT_SUCCEEDED);
}

void OnTick()
{
     for(int i=0; i<3; i++)
          if( CopyBuffer(bands[i].bollingerBandDefination, 2, 0, 3, bands[i].lowerBollingerBandArray) == 3 )
               Print(symbols[i] + ": " + DoubleToString(bands[i].lowerBollingerBandArray[1], bands[i].digits));
}
Reason: