scalping ma doesn't work well in mt5

 
Years ago, I found a scalping ma indicator programming in mql4 from website. It is a very good one and I really appreciate this author's great work. I try to use the same algorithm to program same indicator in mql5. But I have never gotten the last few bars printed out. It would be very thankful it someone could help!

***

Maxwell
Maxwell
  • 2015.05.24
  • www.mql5.com
Trader's profile
 
Please insert your code correctly: when editing a post, press the button   Code, then paste the code into the window that appears.
 
Vladimir Karputov:
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.

 
Maxwell: This is my indicator plot out screen.
Can you also provide a link to the original MQL4 version too, please?
 
Fernando Carreiro:
Can you also provide a link to the original MQL4 version too, please?
Sorry, I no longer have that link. That is why I try to get help here.
 
Maxwell: Sorry, I no longer have that link. That is why I try to get help here.
So, how do you know how to make the MQL5 version then? Do you still have the source file with you? If it is an open source, can you please attach it?
 
Maxwell: This is my indicator plot out screen.

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);
  }


Files:
 
Why did you remove your post with your code and your screenshot?
Reason: