//------------------------------------------------------------------ // // //------------------------------------------------------------------ #property indicator_chart_window #property indicator_buffers 1 extern int ExtDepth = 30; extern int ExtDeviation = 5; extern int ExtBackstep = 3; extern string FiboLevels = "0;23.6;38.2;50;61.8;100"; extern color Fibo1Color = clrDodgerBlue; extern int Fibo1Width = 1; extern int Fibo1Style = STYLE_DOT; extern int Fibo1LevelsStyle = STYLE_SOLID; extern bool ShowSecondFibo = true; extern color Fibo2Color = clrDarkSlateGray; extern int Fibo2Width = 1; extern int Fibo2Style = STYLE_DOT; extern int Fibo2LevelsStyle = STYLE_SOLID; extern bool ShowThirdFibo = true; extern color Fibo3Color = clrGoldenrod; extern int Fibo3Width = 1; extern int Fibo3Style = STYLE_DOT; extern int Fibo3LevelsStyle = STYLE_SOLID; // // // // // extern string _ = "alerts behaviour"; extern bool alertsOn = false; extern double alertsTolerance = 1.0; extern bool touchChanell = false; extern bool alertsOnCurrent = false; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsNotify = false; extern bool alertsEmail = false; extern bool alertsShowTouched = true; extern string soundFile = "alert2.wav"; extern int barsToShowCandles = 1000; extern color BarUpColor = Green; extern color BarDownColor = Red; extern color WickColor = Gray; extern int CandleWidth = 3; // // // // // double ExtMapBuffer[]; double ExtLowBuffer[]; double ExtHighBuffer[]; // // // // // int totalCandles; string windowID; double levelv[]; string levels[]; double values[]; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { FiboLevels = StringTrimLeft(StringTrimRight(FiboLevels)); if (StringSubstr(FiboLevels,StringLen(FiboLevels),1) != ";") FiboLevels = StringConcatenate(FiboLevels,";"); // // // // // int s = 0; int i = StringFind(FiboLevels,";",s); string current; while (i > 0) { current = StringSubstr(FiboLevels,s,i-s); ArrayResize(levels,ArraySize(levels)+1); levels[ArraySize(levels)-1] = current+" price %$ "; ArrayResize(levelv,ArraySize(levelv)+1); levelv[ArraySize(levelv)-1] = StrToDouble(current); s = i + 1; i = StringFind(FiboLevels,";",s); } ArrayResize(values,ArraySize(levelv)); // // // // // IndicatorBuffers(4); SetIndexBuffer(1,ExtMapBuffer); SetIndexBuffer(2,ExtLowBuffer); SetIndexBuffer(3,ExtHighBuffer); SetIndexEmptyValue(1,0.0); SetIndexEmptyValue(2,0.0); SetIndexEmptyValue(3,0.0); IndicatorShortName("fibo retracement("+ExtDepth+","+ExtDeviation+","+ExtBackstep+")"); return(0); } int deinit() { ObjectDelete("Fibo1"); ObjectDelete("Fibo2"); ObjectDelete("Fibo3"); deleteCandles(); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { CalculateZigZag(); // // // // // string fibo; int i; int LastZigZag; int PreviousZigZag; int PPreviousZigZag; int PPPreviousZigZag; for (int z=0;z=0;i--) { ObjectSet(fibo,OBJPROP_FIRSTLEVEL+i,levelv[i]/100); ObjectSetFiboDescription(fibo,i,levels[i]); } } ObjectSet(fibo,OBJPROP_TIME1,Time[PreviousZigZag]); ObjectSet(fibo,OBJPROP_TIME2,Time[LastZigZag]); ObjectSet(fibo,OBJPROP_PRICE1,ExtMapBuffer[LastZigZag]); ObjectSet(fibo,OBJPROP_PRICE2,ExtMapBuffer[PreviousZigZag]); // // // // // if (ShowSecondFibo) { fibo = "Fibo2"; if( ObjectFind(fibo)==-1 ) { ObjectCreate(fibo, OBJ_FIBO, 0,Time[PPreviousZigZag], ExtMapBuffer[PreviousZigZag], Time[PreviousZigZag], ExtMapBuffer[PPreviousZigZag]); ObjectSet(fibo,OBJPROP_COLOR,Fibo2Color); ObjectSet(fibo,OBJPROP_STYLE,Fibo2Style); ObjectSet(fibo,OBJPROP_WIDTH,Fibo2Width); ObjectSet(fibo,OBJPROP_LEVELCOLOR,Fibo2Color); ObjectSet(fibo,OBJPROP_FIBOLEVELS,ArraySize(levelv)); for (i=ArraySize(levelv)-1;i>=0;i--) { ObjectSet(fibo,OBJPROP_FIRSTLEVEL+i,levelv[i]/100); ObjectSetFiboDescription(fibo,i,levels[i]); } } ObjectSet(fibo,OBJPROP_TIME1,Time[PPreviousZigZag]); ObjectSet(fibo,OBJPROP_TIME2,Time[PreviousZigZag]); ObjectSet(fibo,OBJPROP_PRICE1,ExtMapBuffer[PreviousZigZag]); ObjectSet(fibo,OBJPROP_PRICE2,ExtMapBuffer[PPreviousZigZag]); } // // // // // if (ShowThirdFibo) { fibo = "Fibo1"; if( ObjectFind(fibo)==-1 ) { ObjectCreate(fibo, OBJ_FIBO, 0,Time[PPPreviousZigZag], ExtMapBuffer[PPreviousZigZag], Time[PPreviousZigZag], ExtMapBuffer[PPPreviousZigZag]); ObjectSet(fibo,OBJPROP_COLOR,Fibo3Color); ObjectSet(fibo,OBJPROP_STYLE,Fibo3Style); ObjectSet(fibo,OBJPROP_WIDTH,Fibo3Width); ObjectSet(fibo,OBJPROP_LEVELCOLOR,Fibo3Color); ObjectSet(fibo,OBJPROP_FIBOLEVELS,ArraySize(levelv)); for (i=ArraySize(levelv)-1;i>=0;i--) { ObjectSet(fibo,OBJPROP_FIRSTLEVEL+i,levelv[i]/100); ObjectSetFiboDescription(fibo,i,levels[i]); } } ObjectSet(fibo,OBJPROP_TIME1,Time[PPPreviousZigZag]); ObjectSet(fibo,OBJPROP_TIME2,Time[PPreviousZigZag]); ObjectSet(fibo,OBJPROP_PRICE1,ExtMapBuffer[PPreviousZigZag]); ObjectSet(fibo,OBJPROP_PRICE2,ExtMapBuffer[PPPreviousZigZag]); } // // // // // if (alertsShowTouched) ShowCandles(); if (alertsOn) CheckTouches(); return(0); } //+------------------------------------------------------------------+ //| //+------------------------------------------------------------------+ // // // // // void CalculateZigZag() { int shift, back,lasthighpos,lastlowpos,index; double val,res; double curlow,curhigh,lasthigh,lastlow; //---- for(shift=Bars-ExtDepth; shift>=0; shift--) { index=iLowest(NULL,0,MODE_LOW,ExtDepth,shift); val=Low[index]; if(val==lastlow) val=0.0; else { lastlow=val; if((Low[shift]-val)>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtLowBuffer[shift+back]; if((res!=0)&&(res>val)) ExtLowBuffer[shift+back]=0.0; } } } ExtLowBuffer[shift]=0.0; if(val!=0.0) ExtLowBuffer[index]=val; //--- high index=iHighest(NULL,0,MODE_HIGH,ExtDepth,shift); val=High[index]; if(val==lasthigh) val=0.0; else { lasthigh=val; if((val-High[shift])>(ExtDeviation*Point)) val=0.0; else { for(back=1; back<=ExtBackstep; back++) { res=ExtHighBuffer[shift+back]; if((res!=0)&&(res=0; shift--) { curlow=ExtLowBuffer[shift]; curhigh=ExtHighBuffer[shift]; if(curlow==0 && curhigh==0) continue; //--- if(curhigh!=0) { if(lasthigh>0) { if(lasthigh0) { if(lastlow>curlow) ExtLowBuffer[lastlowpos]=0; else ExtLowBuffer[shift]=0; } //--- if((curlow=0; shift--) { if(shift>=Bars-ExtDepth) ExtMapBuffer[shift]=0.0; else { curlow=ExtLowBuffer[shift]; curhigh=ExtHighBuffer[shift]; //---- res=0; if(curlow!=0) { if(lastlowpos==-1) { res=curlow; lastlowpos=shift; } else { if(lasthighpos!=-1 && lastlowpos>lasthighpos) { res=curlow; lastlowpos=shift; } } } if(curhigh!=0) { if(lasthighpos==-1) { res=curhigh; lasthighpos=shift; } else { if(lastlowpos!=-1 && lasthighpos>lastlowpos) { res=curhigh; lasthighpos=shift; } } } //---- ExtMapBuffer[shift]=res; } } } //+------------------------------------------------------------------+ //| //+------------------------------------------------------------------+ // // // // // void fillValues(string forFibo) { int fibLines = ObjectGet(forFibo,OBJPROP_FIBOLEVELS); int i; double price1 = ObjectGet(forFibo,OBJPROP_PRICE1); double price2 = ObjectGet(forFibo,OBJPROP_PRICE2); for (i=0;i price2) values[i] = NormalizeDouble(price2 + (levelv[i]/100*(price1-price2)),Digits); if (price1 < price2) values[i] = NormalizeDouble(price1 + (levelv[i]/100*(price2-price1)),Digits); } } // // // // // void CheckTouches() { if (ShowSecondFibo) { fillValues("Fibo2"); for (int i = 0;i= 0) && (highDiff <= diff)) answer = -1; if ((lowDiff >= 0) && (lowDiff <= diff)) answer = 1; } else { if ((highDiff >= 0) && (highDiff <= diff)) doAlert("fibo level "+DoubleToStr(levelv[index],1)+" line touched from down"); if ((lowDiff >= 0) && (lowDiff <= diff)) doAlert("fibo level "+DoubleToStr(levelv[index],1)+" line touched from up"); } return(answer); } // // // // // void doAlert(string doWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doWhat || previousTime != Time[0]) { previousAlert = doWhat; previousTime = Time[0]; // // // // // message = StringConcatenate(Symbol()," - ",TimeFrameToString(Period())," chart, at ",TimeToStr(TimeLocal(),TIME_SECONDS)," ",doWhat); if (alertsMessage) Alert(message); if (alertsNotify) SendNotification(StringConcatenate(Symbol(), Period() ," pivot line touch " +" "+message)); if (alertsEmail) SendMail(StringConcatenate(Symbol()," pivot line touch"),message); if (alertsSound) PlaySound(soundFile); } } //+------------------------------------------------------------------+ //| //+------------------------------------------------------------------+ // // // // // void deleteCandles() { while(totalCandles>0) { ObjectDelete(StringConcatenate(windowID,"c-",totalCandles)); totalCandles -= 1; } } // // // // // void ShowCandles() { datetime time1; datetime time2; deleteCandles(); // // // // // if (ShowSecondFibo) { fillValues("Fibo2"); time1 = MathMin(ObjectGet("Fibo2",OBJPROP_TIME1),ObjectGet("Fibo2",OBJPROP_TIME2)); time2 = MathMax(ObjectGet("Fibo2",OBJPROP_TIME1),ObjectGet("Fibo2",OBJPROP_TIME2)); for (int i = 0;i= time1) && (Time[i] <= time2)) { for (int k = 0;k= time1) && (Time[i] <= time2)) { for (k = 0;k= time1) && (Time[i] <= time2)) { for (k = 0;k0) ObjectSet(name,OBJPROP_COLOR,BarUpColor); else ObjectSet(name,OBJPROP_COLOR,BarDownColor); } //+------------------------------------------------------------------+ //| //+------------------------------------------------------------------+ // // // // // string TimeFrameToString(int tf) { string tfs="Current time frame"; switch(tf) { case PERIOD_M1: tfs="M1" ; break; case PERIOD_M5: tfs="M5" ; break; case PERIOD_M15: tfs="M15" ; break; case PERIOD_M30: tfs="M30" ; break; case PERIOD_H1: tfs="H1" ; break; case PERIOD_H4: tfs="H4" ; break; case PERIOD_D1: tfs="D1" ; break; case PERIOD_W1: tfs="W1" ; break; case PERIOD_MN1: tfs="MN1"; } return(tfs); }