//+------------------------------------------------------------------+ //| BOP_v1.mq4 | //| Copyright © 2016, TrendLaboratory Ltd. | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2003@yahoo.co.uk | //+------------------------------------------------------------------+ #property copyright "Copyright © 2016, TrendLaboratory Ltd." #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 LightBlue #property indicator_width1 2 #property indicator_color2 Tomato #property indicator_width2 2 //---- input parameters extern int PreSmooth = 1; extern int Smooth = 14; extern int MA_Mode = 0; // Mode of MA //---- buffers double Up[]; double Dn[]; double BOP[]; double sBOP[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(4); SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexBuffer(0,Up); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexBuffer(1,Dn); SetIndexBuffer(2,BOP); SetIndexBuffer(3,sBOP); //---- name for DataWindow and indicator subwindow label string short_name="Balance of Power ("+PreSmooth+","+Smooth+","+MA_Mode+")"; IndicatorShortName(short_name); SetIndexLabel(0,"Up"); SetIndexLabel(1,"Down"); //---- SetIndexDrawBegin(0,PreSmooth + Smooth); SetIndexDrawBegin(1,PreSmooth + Smooth); return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int shift, limit, counted_bars=IndicatorCounted(); //---- if ( counted_bars < 0 ) return(-1); if ( counted_bars ==0 ) limit=Bars-PreSmooth-Smooth-1; if ( counted_bars < 1 ) for(int i=1;i0) limit=Bars-counted_bars; limit--; for( shift=limit; shift>=0; shift--) { double mClose = iMA(NULL,0,PreSmooth,0,MA_Mode,PRICE_CLOSE,shift); double mOpen = iMA(NULL,0,PreSmooth,0,MA_Mode,PRICE_OPEN,shift); double mHigh = iMA(NULL,0,PreSmooth,0,MA_Mode,PRICE_HIGH,shift); double mLow = iMA(NULL,0,PreSmooth,0,MA_Mode,PRICE_LOW,shift); if ((mHigh-mLow)!=0) BOP[shift] = (mClose - mOpen)/(mHigh-mLow); else BOP[shift] = 0; } for( shift=limit; shift>=0; shift--) { sBOP[shift] = iMAOnArray(BOP,0,Smooth,0,MA_Mode,shift); if (sBOP[shift] >= sBOP[shift+1]) {Up[shift] = sBOP[shift]; Dn[shift] = 0;} else if (sBOP[shift] < sBOP[shift+1]) {Dn[shift] = sBOP[shift]; Up[shift] = 0;} } //---- return(0); } //+------------------------------------------------------------------+