Custom Indicator Slow to Load

 

Good morning friends. 

I made a custom indicator. But it causes the chart to stop for minutes especially on lower timeframes.

Please help me review the code.

Thanks.

//+------------------------------------------------------------------+
//|                                              StochRSI Signal.mq4 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2

#property indicator_label1  "Bullish Reversal"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  Blue

#property indicator_label2  "Bearish Reversal"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  Red

input int                 kValue        =  3;              //K
input int                 dValue        =  3;              //D
input int                 rsiPeriod     =  14;             //RSI Period
input int                 stochPeriod   =  14;             //Stochastic Period
input ENUM_APPLIED_PRICE  priceApplied  =  PRICE_CLOSE;    //K
input int                 overBought    =  80;             //Over Bought
input int                 overSold      =  20;             //Over Sold

double bullishBuffer[];
double bearishBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(Digits);
   SetIndexBuffer(0, bullishBuffer);
   SetIndexArrow(0, 233);
   SetIndexBuffer(1, bearishBuffer);
   SetIndexArrow(1, 234);

   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 limit=rates_total-prev_calculated;
   double K1, K2, D1, D2;
   for(int i=0;i<limit;i++)
     {
        K1 = iCustom(NULL,0,"Trend Controller",kValue,dValue,rsiPeriod,stochPeriod,priceApplied,0,i+1);
        K2 = iCustom(NULL,0,"Trend Controller",kValue,dValue,rsiPeriod,stochPeriod,priceApplied,0,i+2);
        D1 = iCustom(NULL,0,"Trend Controller",kValue,dValue,rsiPeriod,stochPeriod,priceApplied,1,i+1);
        D2 = iCustom(NULL,0,"Trend Controller",kValue,dValue,rsiPeriod,stochPeriod,priceApplied,1,i+2);
        
        if(K2>=overBought && D1>=overBought)
          {
              if(K2>=D2 && K1<D1)
                {
                    bearishBuffer[i+1] = High[i+1];
                    continue;
                }
          }
       if(K2<=overSold && D1<=overSold)
          {
             if(K2<=D2 && K1>D1)
                {
                    bullishBuffer[i+1] =  Low[i+1];
                    continue;
                }
          }
         
     }

   return(rates_total);
  }
 
Osazee Asikhemhen: I made a custom indicator. But it causes the chart to stop for minutes especially on lower timeframes. Please help me review the code.
Nothing wrong with your code. Most likely, your “Trend Controller.”