//+------------------------------------------------------------------+ //| spinning_top.mq4 | //| Copyright © 2009, Investatech Inc. | //| http://www.investatech.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Investatech Inc." #property link "http://www.investatech.com" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Red //---- buffers double SpinningTop[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { string curr_value="SpinningTop Finder is present."; ObjectCreate("STF_Label", OBJ_LABEL, 0, 0, 0);// Creating obj. ObjectSet("STF_Label", OBJPROP_CORNER, 1); // Reference corner ObjectSet("STF_Label", OBJPROP_XDISTANCE, 10);// X coordinate ObjectSet("STF_Label", OBJPROP_YDISTANCE, 20);// Y coordinate ObjectSetText( "STF_Label", curr_value, 12,"Arial", Black) ; IndicatorBuffers(1); //---- indicator lines SetIndexStyle(0,DRAW_ARROW,0,2,Red); SetIndexArrow(0,251); SetIndexEmptyValue(0,0.0); SetIndexBuffer(0,SpinningTop); SetIndexLabel(0,"SpinningTop"); SetIndexDrawBegin(0,0); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("STF_Label"); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- if(Bars<=10) return(0); //---- initial zero if(counted_bars<1) { for(int i=1;i<=10;i++) SpinningTop[Bars-i]=0; } i=Bars-10-1; if(counted_bars>=10) i=Bars-counted_bars-1; //the following lines make the code compatible with fractioanl pips //we need to replace Point with _my_point in the rest of the code double _my_point=Point; if (_my_point==0.00001) _my_point=0.0001; if (_my_point==0.001) _my_point=0.01; //---- i=Bars-counted_bars-1; while(i>=0) { double high=High[i]; double low =Low[i]; double open = Open[i]; double close = Close[i]; double _range=MathRound(MathAbs(high-low)/_my_point); double _realbody=MathRound(MathAbs(open-close)/_my_point); double up_oc=MathMax(open,close); double down_oc=MathMin(open,close); double _uppershadow=MathRound(MathAbs(high-up_oc)/_my_point); double _lowershadow=MathRound(MathAbs(down_oc-low)/_my_point); if (_range<0.01) _range=0.014367; double _atr=MathRound(iATR(Symbol(),0,14,i)/_my_point); bool trigger1=_uppershadow>(0.9*_realbody); bool trigger2=_lowershadow>(0.9*_realbody); bool trigger3=_realbody<(0.5*_range); bool trigger4=_uppershadow<(2.5*_lowershadow); bool trigger5=_lowershadow<(2.5*_uppershadow); bool trigger6=_realbody>(0.05*_range); bool trigger7=_range<_atr; bool conditions_met=trigger1 && trigger2 && trigger3 && trigger4 && trigger5 && trigger6 && trigger7; if (_range==0.014367) conditions_met=false; if (conditions_met) SpinningTop[i]=Low[i]-3*_my_point; if (!conditions_met) SpinningTop[i]=0; i--; } //---- return(0); } //+------------------------------------------------------------------+