
//+------------------------------------------------------------------+
//|                                                     KPVForce.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

/*

Original Formula

WBP:=(HHV(HIGH,5)+LLV(LOW,5)+CLOSE)/3;
VFORCE:= SUM(((TP()-REF(TP(),-1))/REF(TP(),-1))*VOLUME,13)/SUM(VOLUME,13);
VFORCEup:=IF(PLRu OR PLRd,0,VFORCE);
{ - if plr is true, we only want a large arrow on the bar}
VFORCEdn:=IF(PLRd OR PLRu,0,VFORCE);
{ - if plr is true, we only want a large arrow on the canlde}
FORCEu:=VFORCEup>0;
{ - plots a blue arrow on candles}
FORCEd:=VFORCEdn<0;
{ -plots a red arrow on candles}


*/


#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_maximum 1
#property indicator_minimum 0

//---- input parameters


//---- buffers  WHH=HHV(WH,25);WLL=LLV(WL,25);WBP_MA=MOV(WBP,25,S)
double WBP[],VFu[],VFd[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 3 additional buffers are used for counting.
   IndicatorBuffers(3);
//---- name for DataWindow and indicator subwindow label
   SetIndexBuffer(2,WBP);

   

//----
   SetIndexStyle(0,DRAW_HISTOGRAM,0,5);
   SetIndexBuffer(0, VFu);
   SetIndexStyle(1,DRAW_HISTOGRAM,0,5);
   SetIndexBuffer(1, VFd);
   short_name="KPVForce";
   IndicatorShortName(short_name);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| KPVForce                                                         |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k,counted_bars=IndicatorCounted();
   double VF;
   if(Bars<=32) return(0);
//---- initial zero

//---- last counted bar will be recounted
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++; 

   double T1,T2;

/*

VFORCE:= SUM(((TP()-REF(TP(),-1))/REF(TP(),-1))*VOLUME,13)/SUM(VOLUME,13);
VFORCEup:=IF(PLRu OR PLRd,0,VFORCE);
{ - if plr is true, we only want a large arrow on the bar}
VFORCEdn:=IF(PLRd OR PLRu,0,VFORCE);
{ - if plr is true, we only want a large arrow on the canlde}
FORCEu:=VFORCEup>0;
{ - plots a blue arrow on candles}
FORCEd:=VFORCEdn<0;
{ -plots a red arrow on candles}*/

 for(i=0; i<limit-1; i++)
      {T1=(High[i]+Low[i]+Close[i])/3;T2=(High[i+1]+Low[i+1]+Close[i+1])/3;
       T1=T1-T2;WBP[i]=T1/T2*Volume[i];
       }
      
 for(i=0; i<limit; i++) 
 {VF=iMAOnArray(WBP,Bars,13,0,MODE_SMA,i);
 
 if (VF>0){
          VFu[i]=1;VFd[i]=0;}
         if (VF<0){
          VFu[i]=0;VFd[i]=1;} 

  }
 
   return(0);
  }
//+------------------------------------------------------------------+