mql4 bollingers bands always give the same value

33 Views Asked by At

bollingers bands always give the same value and give the same value in each symbol there is no error in the code sequence but there is a logical error can you help

property copyright "Copyright 2024, MetaQuotes Ltd."
property link      "https://www.mql5.com"
property version   "1.00"
property strict
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{

double bb_degeri = iBands(NULL,PERIOD_CURRENT,21,0,2,PRICE_CLOSE);
Alert("");
Alert(bb_degeri);

it needs to give a different value for each symbol and the forex bot I will write will open and close trades according to these values

1

There are 1 best solutions below

0
PaulB On

Your question states MQL4, your code looks more like MQL5, you need to clarify which language you are using as they are distinctly different.

MQL4 is relitevly straight forward, check the documentation: iBands

Values are retrieved using the following code

double value=iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0);

MQL5 requires a handler. Again check the documentation: iBands

Example:

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   handle_iBands = iBands(_Symbol, PERIOD_CURRENT, 20, 0, 0.21, PRICE_OPEN);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int max=rates_total; //rates_total;
   CopyBuffer(handle_iBands, 0, 0, max, Upper);
   CopyBuffer(handle_iBands, 0, 0, max, Lower);
   double value1=Upper[0];
   double value2=Lower[0];
return(rates_total);
}