Error Code 4806 working with iBands in expert

 

i'm new in mql5,

i want to develop expert to find stocks with conditions base on band bollinger (iBand).

with this below code i have Error code 4806 in BarsCalculated,

double lowerBollingerBandArray[];
double upperBollingerBandArray[];
double middleBollingerBandArray[];

double BoundWithValue[];

int bollingerBandDefination,calculated=0;

int symbols=SymbolsTotal(true);

string symbolName;


int IlowestNumber10,IlowestNumber115;  //ایندکس کندل کمترین قیمت 10 و 115 روزه

double IlowestNumber10Value,IlowestNumber115Value; //- قیمت بسته شدن کندل مینیمم 10 و 115 روزه

int OnInit()
  { 
   
  
  for(int i=0;i<2;i++)
  {
     symbolName=SymbolName(i,true);       
     if (BandWidthCalc(symbolName)==true)
     
        
       PrintFormat("SYMBOL NAME %S",symbolName); 
     
  }
return(INIT_SUCCEEDED);

//--------------------

void OnDeinit(const int reason)
  {
 
  }
//+------------------------------------------------------------------+
//| "Tick" event handler function                                    |
//+------------------------------------------------------------------+
void OnTick()
  { 
   
  }

//+-------------------------------------------------------------------

bool BandWidthCalc(string symbol)
  {
  
  //-Sorting array from current candle downward..
   ArraySetAsSeries(lowerBollingerBandArray, true);
   ArraySetAsSeries(middleBollingerBandArray, true);
   ArraySetAsSeries(upperBollingerBandArray, true);
   ArraySetAsSeries(BoundWithValue, true);
   
   calculated=Bars(symbol,PERIOD_D1);
   
   if (calculated<0)
   {
      PrintFormat("ERROR  ==%d",calculated);
      return(false);
   }
   //-Defining bollinger bands..
   bollingerBandDefination = iBands(symbol, PERIOD_D1, 20, 0, 2.0, PRICE_CLOSE);
   
   ResetLastError();
   
   calculated=BarsCalculated(bollingerBandDefination); 
   
   
   if(calculated<=0) 
     { 
      PrintFormat("BarsCalculated() returned %d, error code %d, SYMBOL NAME %7S",calculated,GetLastError(),symbol); 
      return(false); 
     } 
   else
     {
      return(true);
     }  
   
   //-Copying lower bollinger band data into array..
   if( CopyBuffer(bollingerBandDefination, 2, 0, calculated, lowerBollingerBandArray) < 3 ) return(false);
   if( CopyBuffer(bollingerBandDefination, 0, 0, calculated, middleBollingerBandArray) < 3 ) return(false);
   if( CopyBuffer(bollingerBandDefination, 1, 0, calculated, upperBollingerBandArray) < 3 ) return(false);
   
   ArrayResize(BoundWithValue,calculated);
   //-calculate WidthBand for specificie symbol
   
    
     for(int i=0;i<10;i++)
     {          
        BoundWithValue[i]=floor(( (upperBollingerBandArray[i] - lowerBollingerBandArray[i]) / middleBollingerBandArray[i]) * 100);                
     }
     
     //-calculate min(10 days last,bandwith)
     IlowestNumber10=iLowest(symbol,PERIOD_D1,MODE_LOW,10,0);
     IlowestNumber10Value=iClose(symbol,PERIOD_D1,IlowestNumber10);
     
      //-calculate min(115 days last from day 11,bandwith)
     IlowestNumber115=iLowest(symbol,PERIOD_D1,MODE_LOW,115,11);
     IlowestNumber115Value=iClose(symbol,PERIOD_D1,IlowestNumber115);
     
    /* if (IlowestNumber10Value<IlowestNumber115Value)
        return(true);
     else
        return(false);
    */    
     if (BoundWithValue[0]<50)
        return(true);
     else
        return(false);   
    
  }

anybody can help me

thanks alot...

 
  1. Perhaps you should read the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
              How to call indicators in MQL5 - MQL5 Articles 12 March 2010

    Also see my example for encapsulating calls
              Detailed explanation of iCustom - MQL4 programming forum 2017.05.23

  2.  IlowestNumber10=iLowest(symbol,PERIOD_D1,MODE_LOW,10,0);
    On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
              Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
              Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
              Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
              SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum 2019.09.03

  3. Simplify your code
    Your code
         if (BoundWithValue[0]<50)
            return(true);
         else
            return(false);   
    simplified
    return BoundWithValue[0]<50;
 

thanks alot my problem solved...


edit my code and put handle off indicator in OnInit() and other in OnTick()

Reason: