Extract iMAOnArray and buff_fma1 calculation to the separate loop, after one you now have.
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 lookback = 1000; // Replacing loop function with the one you pointed out for(int iBar = Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar) { double fast_ = iMA(_Symbol,PERIOD_CURRENT, ma1, 0, ma_type, PRICE_CLOSE, iBar); double slow_ = iMA(_Symbol,PERIOD_CURRENT, ma2, 0, ma_type, PRICE_CLOSE, iBar); double macd = fast_ - slow_; buff_macd[iBar] = macd; } for(int iBar = Bars-1-MathMax(lookback, prev_calculated); iBar >= 0; --iBar) { double filter_1 = iMAOnArray(buff_macd,0,fma1,0,ma_typem,iBar); buff_fma1[iBar] = filter_1; } //--- return value of prev_calculated for next call return(rates_total); }
I'm not sure how iMAOnArray works, but it looks like it can somehow detect when you change value in array, and then it recalculates complete array, instead of just last value.
I know what is iMAOnArray and what it does.
Thing that documentation does not say is why it takes longer to calculate when you change array in the loop, like the OP asked.
Hello everyone, I'm recreating a MACD (I know there's dedicated function, just wanted to calcualte by myself) and when I calculate the signal line it makes my platform freeze for a bit, everytime I change signal line period I get a 10sec lag of the platofm. Someone can help point out why that happen? Thank's.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone, I'm recreating a MACD (I know there's dedicated function, just wanted to calcualte by myself) and when I calculate the signal line it makes my platform freeze for a bit, everytime I change signal line period I get a 10sec lag of the platofm. Someone can help point out why that happen? Thank's.