Please insert your code correctly: when editing a post, press the button , then paste the code into the window that appears.
Thanks for reminding me. This is my first time to post a topic.
Can you also provide a link to the original MQL4 version too, please?
As a first look, the OnCalculate() handler is treating the data as non-series (which is the default for MQL5) and using an incremental loop. However, the Get_SCASeries() function seems to be treating the data as a series and is using a decrementing loop, just like the default in MQL4 and using a limit for the loop of "(2*m_Period)-3" which explains why the last bars are not calculated.
Was the Get_SCASeries() function copied over directly from the MQL4 source?
This is one of the reasons I want to look at the original.
Since it seems that the problem is due to the mix-up of "Non-Series" and "Series" handling of the data, due to copying over a function from a MQL4 version, the easiest way to resolve it, is to change the OnCalculate() so as to handle the data as a Series (like it is in MQL4).
Here are my changes so as to reflect that. This is not the best way to do it, but just as an example to show where the problem is located.
This does not resolve all the issues as there are still problem areas, but serves only to show why the last bars were not being rendered in your version.
So, please supply the original MQL4 version for further verification!
int OnInit() { ////--- indicator buffers mapping SetIndexBuffer(0, ExtMLBuffer, INDICATOR_DATA); // SetIndexBuffer(1,InputBuffer1,INDICATOR_CALCULATIONS); ArraySetAsSeries(ExtMLBuffer, true); //--- indicator buffers mapping //--- set accuracy IndicatorSetInteger(INDICATOR_DIGITS, _Digits+1); //--- set first bar from what index will be drawn PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, 0); //--- line shifts when drawing PlotIndexSetInteger(0, PLOT_SHIFT, ExtBandsShift); IndicatorSetString(INDICATOR_SHORTNAME, "BB_scalping"+"("+string(mPeriod)+")"); //--- set drawing line empty value PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0); return(0); } //+------------------------------------------------------------------+ //| Bollinger Bands | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { ArraySetAsSeries(price, true); if(rates_total<2*mPeriod-1+begin) return(0); //--- first calculation or number of bars was changed //--- indexes draw begin settings, when we've recieved previous begin if(ExtPlotBegin!=mPeriod+begin) { ExtPlotBegin=mPeriod+begin; PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, ExtPlotBegin); } //--- starting calculation int pos = rates_total - ( ( prev_calculated < 1 ) ? 1 : prev_calculated ); //--- main cycle for(int i=pos; i>=0 && !IsStopped(); i--) { //--- indexes draw begin settings, when we've recieved previous begin ExtMLBuffer[i] = Get_SCASeries(rates_total, prev_calculated, Symbol(), NullBarRecount, price, timeframe, mPeriod, ExtMLBuffer); } //--- OnCalculate done. Return new prev_calculated. return(rates_total); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
***