Message: Indicator is too slow, rewrite the indicator, please

 

Dear devels,

I am still studying MQL5 and one of my indicator's test I have got that message. Could you comment if I am write the "for loop" correctly and optimized?

   //--- declaration of local variables
   int index = 0;

   //--- check for bars count
   if (rates_total < InpPeriod)
      return (0);            // not enough bars for calculation
                             //--- first calculation or number of bars was changed
   //--- correct position for first iteration
   if (prev_calculated < InpPeriod)
   {
      index=InpPeriod;
      ArrayInitialize(bufferMASa, EMPTY_VALUE);
      ArrayInitialize(bufferMASa2, EMPTY_VALUE);
      PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpPeriod);
      PlotIndexSetInteger(1, PLOT_DRAW_BEGIN, InpPeriod);
   }        
   else
      index = prev_calculated - 1;
      // try to test: "index = prev_calculated - InpPeriod;"

    for (int i=index; i < rates_total && !IsStopped(); i++) {

I will be very thankful with any comment or suggestion...

 
  1. It could be that your code is time consuming try using the profiler: in the Editor => Debug => Start Profiling
  2. Or your indicator has to wait (too long) for the initial quotes (too many? Reduce "Max bars in Charts" in Options (Ctrl+O) => Charts
 
Carl Schreiber #:
  1. It could be that your code is time consuming try using the profiler: in the Editor => Debug => Start Profiling
  2. Or your indicator has to wait (too long) for the initial quotes (too many? Reduce "Max bars in Charts" in Options (Ctrl+O) => Charts

Thanks Carl. I am debugging it. I will have to understand better the rates_total and prev_calculated. I think I have not got the main idea yet for optimizations.

 
b2tradingclub #: I will have to understand better the rates_total and prev_calculated. I think I have not got the main idea yet

See How to do your lookbacks correctly #9#14 & #19. (2016)

 
William Roeder #:

See How to do your lookbacks correctly #9#14 & #19. (2016)

Thank you so much, William.

Reason: