Buy Sell Pressure Indicator

 

I got Buy Sell Pressure Indicator form some where and it's a AFL Code.

I try to code in MQ4 but it's not work.

Anyone help me to code this indicator.


_SECTION_BEGIN("Buy & Sell Pressure - Smoothed with Histogram - V.1.0");
SetChartOptions(0,chartShowArrows|chartShowDates);
sp = H-C;
bp = C-L;
bpavg = EMA(bp,80);
spavg = EMA(sp,80);
nbp = bp/bpavg;
nsp = sp/spavg;
diff = nbp-nsp;
diffcolor = IIf(diff>0,colorGreen,colorOrange);
Varg = EMA(V,80);
nv = V/Varg;
nbfraw = nbp * nv;
nsfraw = nsp * nv;
nbf = EMA(nbp * nv,20);
nsf = EMA(nsp * nv,20);
Plot(nbf,"Buying Pressure",colorTurquoise,1|styleThick);
Plot(nsf,"selling Pressure",colorYellow,1|styleThick);
diff = nbf-nsf;
diffcolor = IIf(diff>0,colorGreen,colorRed);
SetBarFillColor( diffcolor ); 
PlotOHLC(0,diff,0,diff,"Force",IIf(diff>0,colorLime,colorOrange), styleCandle | styleOwnScale ) ;
_SECTION_END();

I separate in two indicator.

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Yellow




extern int MAMethod = MODE_LWMA;
extern int period = 10;
extern int nobs = 300; 


double SP[],BP[],SPave[],BPave[],Vave[],Vol[],BSP[],nsf[],nbf[];


int init()
{
   
   IndicatorShortName(StringConcatenate("BS Pressure (", period, ")"));
   IndicatorBuffers(7);
   SetIndexBuffer(0,nbf);             
   SetIndexBuffer(1,nsf);
   SetIndexBuffer(2,SP);
   SetIndexBuffer(3,BP);
   SetIndexBuffer(4,SPave);
   SetIndexBuffer(5,BPave);
   SetIndexBuffer(6,Vave);     
   return(0);
}


int start()
{
   
   
   int i,limit;
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;

   SetIndexDrawBegin(0,Bars-nobs+period);
         limit = nobs+period;
   for (i=limit; i>=0; i--)
   {
               
               SP[i] =  High[i]-Close[i];
               BP[i] =  Close[i]-Low[i];
               Vol[i] = Volume[i];
   }
   for (i=limit-period; i>=0; i--)
   {
               
               SPave[i] =  iMAOnArray(SP,0,period,0,MAMethod,i);
               BPave[i] =  iMAOnArray(BP,0,period,0,MAMethod,i);
               Vave[i] =  iMAOnArray(Vol,0,period,0,MAMethod,i);
   }
      
   for (i=limit-period; i>=0; i--)
   {
               
               nsf[i] =  SP[i]*Vave[i]/ SPave[i] ;
               nbf[i] =  BP[i]*Vave[i]/ BPave[i];
               
   }
      

   
   
   return(0);
}


And below indicator call above indicator.


#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 LimeGreen
#property indicator_color2 Yellow
#property indicator_color3 Blue
#property indicator_level1 0.0


extern int period1 = 10;
extern int MAMethod = MODE_LWMA;
extern int period2 = 50;
extern int nobs = 300; 


double SP[],BP[],BSP[],nsf[],nbf[];


int init()
{
   
   IndicatorShortName(StringConcatenate("BS Pressure (", period2, ")"));
   IndicatorBuffers(3);
   SetIndexBuffer(0,BP);             
   SetIndexBuffer(1,SP);
   SetIndexBuffer(2,BSP);
     
   return(0);
}


int start()
{
   
   
   int i,limit;
   int counted_bars=IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;

   SetIndexDrawBegin(0,Bars-nobs+period2);
         limit = nobs+period2;
   for (i=limit; i>=0; i--)
   {
               
               nsf[i] =  iCustom(NULL,0,"Buy Sell Pressure",MAMethod,period2,period2*10,1,i);
               nbf[i] =  iCustom(NULL,0,"Buy Sell Pressure",MAMethod,period2,period2*10,0,i);
              
   }
   for (i=limit-period1; i>=0; i--)
   {
               
               SP[i] =  iMAOnArray(nsf,0,period1,0,MAMethod,i);
               BP[i] =  iMAOnArray(nbf,0,period1,0,MAMethod,i);
               BSP[i] =  BP[i]-SP[i];
   }
      
   

   
   
   return(0);
}


If any one can merge in one indicator please do it.

I have a limit coding.

Reason: