9 SMA on William R

 

Hi,

I am planning to write a code where I can plot 9 SMA on to the William's R (14) in a Separate indicator window. Not able to do it. Appreciate if someone can help.

I have a strategy that is working great with this combination, but want to do int MT4.



thanks,

Pratyush

 

wpr_ma 

#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2
input int      sma_period=9;
input int      wpr_period=14;
input bool     show_wpr=true;
double         wpr[],wpr_ma[];
//+------------------------------------------------------------------+
int OnInit(){
   SetLevelValue(0,-100); SetLevelValue(1,-80);  SetLevelValue(2,-20);  SetLevelValue(3,0);
   SetIndexBuffer(0,wpr);   SetIndexLabel(0,"wpr");   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,clrBlue);
   SetIndexBuffer(1,wpr_ma);SetIndexLabel(1,"wpr_ma");SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,clrRed);
   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 = MathMax(rates_total-prev_calculated,2);
   for(int i=0; i<limit; i++){  
      if (show_wpr) wpr[i]=iWPR(_Symbol,_Period,wpr_period,i);
      wpr_ma[i]=wpr_ma(i);       
   }
   return(rates_total);
}
//+------------------------------------------------------------------+
double wpr_ma(int i){
   double u=0;
   for(int j=i;j<i+sma_period;j++) u+=iWPR(_Symbol,_Period,wpr_period,j);
   u=u/sma_period;
   return u;