Indicator Running Slow

 

Good morning, everyone!

I hope you are all well.

I am adapting an indicator (CurrencySlopeStrength) which, for those who are not familiar with it, behaves similarly to other oscillators, such as RSI, Stochastic, etc.

However, I have noticed that the indicator becomes heavy when attached to multiple charts, especially when MT4 is first opened.

The OnCalculate function is as shown in the code below. Is there anything I can do to optimize the performance of this indicator?


Thank you in advance for your attention and cooperation.

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 lastBar = rates_total - 1;
   if(lastBar < 0)
      return(0);

   // inpMaxBars = 200
   int limit = lastBar;
   if(inpMaxBars > 0)
      limit = MathMin(limit, inpMaxBars - 1);

   int startt;

   if(prev_calculated <= 0 || prev_calculated > rates_total)
     {
      startt = limit;
     }
   else
     {
      int lastDone = prev_calculated - 1;

      startt = MathMin(lastDone, limit);

      if(startt < 1)
         startt = 1;
     }

   for(int i = startt; i >= 0; i--)
     {
      ArrayInitialize(GBLCurrencyValues, 0.0);

      CalculateAllCurrenciesSlope(GBLBaseTF, time[i]);

      FillIndicatorBuffers(i);

      if(i == 1)
         ArrayCopy(GBLCurrencyValuesPrior, GBLCurrencyValues);

      if(i == 0)
         ManageDashboard(window);
     }

   if(GBLShowLevelCross)
     {
      DrawLevelLines(window);
      DrawLineLabels(window, time[0]);
     }
   else
     {
      ObjectDelete(GBLUniquePrefix + "HLine_High");
      ObjectDelete(GBLUniquePrefix + "HLine_Low");
     }

   return(rates_total);
  }
Stochastic Oscillator - Oscillators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
Stochastic Oscillator - Oscillators - Technical Indicators - Price Charts, Technical and Fundamental Analysis - MetaTrader 5 Help
  • www.metatrader5.com
The Stochastic Oscillator Technical Indicator compares where a security’s price closed relative to its price range over a given time period. The...
 
Jeovane Reges:
I have noticed that the indicator becomes heavy when attached to multiple charts, especially when MT4 is first opened.

I suspect that the heaviness is inherent in the nature of the multi-pair dashboard that you're coding. Upon loading the indicator, many buffers are being filled with data. As that completes, the heaviness tapers off. I really don't see a way to speed it up.

 
Ryan L Johnson #:

I suspect that the heaviness is inherent in the nature of the multi-pair dashboard that you're coding. Upon loading the indicator, many buffers are being filled with data. As that completes, the heaviness tapers off. I really don't see a way to speed it up.

Good afternoon. Thank you for your feedback. I am continuing my quest to improve performance, although I am almost convinced that it is not possible for the reasons you mentioned.