Why would this work on the chart window and not on separate window? - page 2

 
Mladen Rakic #:

Nothing wrong with MT5 in your case - but your code



Ive found the issue. Your code is correct only that you didnt divide by

(Slope_LookBack+1)

After division it will match the mt4 version. Thanks for this. 

 
Tonny Obare #:

Ive found the issue. Your code is correct only that you didnt divide by

After division it will match the mt4 version. Thanks for this. 

Learn to read the code - line 54 of the posted test indicator goes like this : 

         Slope_Buffer[i] = (Ma_Buffer[i]-(i>=Slope_LookBack ?  Ma_Buffer[i-Slope_LookBack] : Ma_Buffer[0]))/_Point;

Your change has nothing in common with any division

 
Mladen Rakic #:

Learn to read the code - line 54 of the posted test indicator goes like this : 

Your change has nothing in common with any division

You didnt get me. Anyway I added what was missing in your code now its at par with the mt4 version except for the current open bar where my mt4 code is real time while yours is frozen in place. Thanks all. I believe its fine now.
 

For reference this works fine for the most part. Might help someone in future. Though Im still wondering why the earlier issue only happened with separate_window.

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 1
#property indicator_label1  "Slope_line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

input int                Maperiod       = 14;
input int                Mashift        = 0;
input ENUM_MA_METHOD     Mamethod       = MODE_SMA;
input ENUM_APPLIED_PRICE MaappliedPrice = PRICE_CLOSE;
input int                Slope_LookBack = 3;

double Slope_Buffer[],Ma_Buffer[];
int maHandle;

//------------------------------------------------------------------
//
//------------------------------------------------------------------
int OnInit()
{
   SetIndexBuffer(0,Slope_Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Ma_Buffer,INDICATOR_CALCULATIONS);
   

      // MA handle
      
      maHandle = iMA(_Symbol,_Period,Maperiod,Mashift,Mamethod,MaappliedPrice);
   return(INIT_SUCCEEDED);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
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  = (prev_calculated>0) ? prev_calculated-1 : 0;
   int toCopy = (prev_calculated>0) ? rates_total-prev_calculated+1 : rates_total;
            if (CopyBuffer(maHandle,0,0,toCopy,Ma_Buffer)!=toCopy) return(prev_calculated);

   for (int i=limit; i<rates_total && !_StopFlag; i++)
      {
      double IndNow=Ma_Buffer[i];
      double IndAgo=Ma_Buffer[i+Slope_LookBack];
      double SlopeBufferRaw=(Ma_Buffer[i]-(i>=Slope_LookBack ?  Ma_Buffer[i-Slope_LookBack] : Ma_Buffer[0]))/_Point;


         Slope_Buffer[i] =SlopeBufferRaw/(Slope_LookBack+1); 
      }
   return(rates_total);
}
//+------------------------------------------------------------------+