//+------------------------------------------------------------------+ //| FractalLevel.mq4 | //| Copyright © 2009 DareXau | //| darexau@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009 DareXau" #property link "mailto:darex.au@gmail.com" #property indicator_chart_window extern int TimeFrame=0; extern int Distanse=0; extern string FrUpNam="Up"; extern string FrDnNam="Dn"; extern color ClUp=Red; extern color ClDn=Green; extern bool comment=false; //-----------------------------------------------------------------------------+ double FrPrise; double FrUpPrise=0,FrDnPrise=0; //+----------------------------------------------------------------------------+ void init(){ if(TimeFrame==0){TimeFrame=Period();} IndicatorShortName("FactalLevel"+TimeFrame); FrUpNam=StringConcatenate(FrUpNam,TimeFrame); FrDnNam=StringConcatenate(FrDnNam,TimeFrame); return;} void deinit(){ ObjectDelete(FrDnNam); ObjectDelete(FrUpNam); Comment(" "); return;} //+----------------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); int limit; double tmp; int i, j,k; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //-----------------------------------------------------------------------------+ LineUp(); LineDn(); string FUP=DoubleToStr((FrUpPrise-Distanse*Point),Digits); string FDP=DoubleToStr((FrDnPrise+Distanse*Point),Digits); int diap=MathRound((FrUpPrise-FrDnPrise)/Point); if(comment){Comment("TimeFrame="+TimeFrame+ "\nUpPrise ="+FUP+ "\nDnPrise ="+FDP+ "\nFractal Channel =" +diap+"Point");} return(0); } //-----------------------------------------------------------------------------+ //-----------------------------------------------------------------------------+ void LineDn(){ FrPrise=NormalizeDouble(FindNearFractal(0,TimeFrame,MODE_LOWER),MarketInfo(Symbol(),MODE_DIGITS)); FrPrise=NormalizeDouble(FrPrise-Distanse*Point,MarketInfo(Symbol(),MODE_DIGITS)); //Comment(FrPrise); if(ObjectFind(FrDnNam)==0){ if(ObjectGet(FrDnNam,OBJPROP_PRICE1)==FrPrise){return;}} FrDnPrise=FrPrise; ObjectDelete(FrDnNam); SetHLine(ClDn,FrDnNam,FrDnPrise,2,1); WindowRedraw(); return;} //-----------------------------------------------------------------------------+ //-----------------------------------------------------------------------------+ void LineUp(){ FrPrise=NormalizeDouble(FindNearFractal(0,TimeFrame,MODE_UPPER),MarketInfo(Symbol(),MODE_DIGITS)); FrPrise=NormalizeDouble(FrPrise+Distanse*Point,MarketInfo(Symbol(),MODE_DIGITS)); if(ObjectFind(FrUpNam)==0){ if(ObjectGet(FrUpNam,OBJPROP_PRICE1)==FrPrise){return;}} FrUpPrise=FrPrise; ObjectDelete(FrUpNam); SetHLine(ClUp,FrUpNam,FrUpPrise,2,1); WindowRedraw(); return;} //-----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+ double FindNearFractal(string sy="0", int tf=0, int mode=MODE_LOWER) { if (sy=="" || sy=="0") sy=Symbol(); double f=0; int d=MarketInfo(sy, MODE_DIGITS), s; if (d==0) if (StringFind(sy, " ")<0) d=4; else d=2; for (s=2; s<100; s++) { f=iFractals(sy, tf, mode, s); if (f!=0) return(NormalizeDouble(f, d)); } Print("FindNearFractal(): "); return(0); } //+----------------------------------------------------------------------------+ //+----------------------------------------------------------------------------+ void SetHLine(color cl, string nm="", double p1=0, int st=0, int wd=1) { if (nm=="") nm=DoubleToStr(Time[0], 0); if (p1<=0) p1=Bid; if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_HLINE, 0, 0,0); ObjectSet(nm, OBJPROP_PRICE1, p1); ObjectSet(nm, OBJPROP_COLOR , cl); ObjectSet(nm, OBJPROP_STYLE , st); ObjectSet(nm, OBJPROP_WIDTH , wd); } //+----------------------------------------------------------------------------+