Indicator is very slow!!! to load, how to improve it thanks

 
#property copyright "Copyright 2017, PondXYZ Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_color1 clrBlue

#property indicator_style1 STYLE_SOLID

#property indicator_type1 DRAW_LINE

#property indicator_width1 1

#property indicator_color2 clrRed

#property indicator_style2 STYLE_SOLID

#property indicator_type2 DRAW_LINE

#property indicator_width2 1

#property indicator_color3 clrNONE



input int InpPeriod1=8;

input int InpPeriod2=21;

input ENUM_MA_METHOD InpMethod = MODE_SMMA;

double BufferMa1[],BufferMa2[],BufferData[]; 

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

//| Custom indicator initialization function                         |

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

int OnInit()

  {

   SetIndexBuffer(0,BufferMa1);

   SetIndexBuffer(1,BufferMa2);

   SetIndexBuffer(2,BufferData);

   SetIndexLabel(0,"MA"+(string)InpPeriod1);

   SetIndexLabel(1,"MA"+(string)InpPeriod2);

   SetIndexLabel(2,"R14");

   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;

   if(prev_calculated>0)limit++;

   

   for(int i = limit-1; i>=0; i--){

      BufferData[i] = iWPR(_Symbol,_Period,14,i);

      int period = (rates_total-i)<InpPeriod ? (rates_total-i) : InpPeriod;

      BufferMa1[i] = iMAOnArray(BufferData,0,InpPeriod1,0,InpMethod,i);

      BufferMa2[i] = iMAOnArray(BufferData,0,InpPeriod2,0,InpMethod,i);

   }   

   return(rates_total);

  }

//////////////////////////////////////////////////////////////////////////////////////////////////

I THINK IT MUST BE THIS CODE, BUT DON'T KNOW HOW TO FIX IT,  ANY SUGGEST PLEASE!!!

 

   int limit =rates_total-prev_calculated;

   if(prev_calculated>0)limit++;

   

   for(int i = limit-1; i>=0; i--){

Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
pondxyz:

When I add Indicator to window or when I change Timeframe, It very slow to load, How to fix this problem. Thanks

***

Please insert the code correctly: when editing a message, press the button   Codeand paste your code into the pop-up window
 

Already fix it by my self ^^

//+------------------------------------------------------------------+
//| 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;
   if(prev_calculated>0)limit++;
   
   for(int i = limit-1; i>=0; i--){
      BufferData[i] = iWPR(_Symbol,_Period,14,i);
   }
   for(int i = limit-1; i>=0; i--){   
      //int period = (rates_total-i)<InpPeriod ? (rates_total-i) : InpPeriod;
      BufferMa1[i] = iMAOnArray(BufferData,0,InpPeriod1,0,InpMethod,i);
      BufferMa2[i] = iMAOnArray(BufferData,0,InpPeriod2,0,InpMethod,i);
   }   
   return(rates_total);
  }
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.