//+------------------------------------------------------------------+ //| fibo pivots.mq4 | //| mladen | //+------------------------------------------------------------------+ #property copyright "mladen" #property link "mladenfx@gmail.com" #property indicator_chart_window #property indicator_buffers 0 // // // // // extern string Levels = "0.382;0.618;1"; extern string TimeFrame = "D1"; extern int HourShift = 0; extern bool FixSundays = true; extern bool ShowLabels = false; extern bool ShowLevels = true; extern bool ShowPrices = false; extern bool ShowMiddleValues = false; extern int ShowTotalPivots = 5; extern int MainLinesWidth = 2; extern color UpperValuesColor = DeepSkyBlue; extern color LowerValuesColor = Red; extern color PivotValuesColor = Gray; extern color LabelsColor = Gray; extern int LabelsFontSize = 10; extern int LabelsShiftHorizontal = -15; extern int LabelsShiftVertical = 1; extern string PivotIdentifier = "fiboPivot1"; extern bool alertsOn = false; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsEmail = false; // // // // // double Pivot[]; double Range[]; double Dates[]; // // // // // datetime alertTimes[]; string alertEvents[]; double levels[]; int levelsCount; int timeFrame; int lookupTimeFrame; string Description; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int init() { lookupTimeFrame = PERIOD_H1; timeFrame = stringToTimeFrame(TimeFrame); if (timeFrame0) HourShift += 24; } if (ShowTotalPivots==0) ShowTotalPivots = 99999; ShowTotalPivots = MathMax(1,ShowTotalPivots); // // // // // Levels = StringTrimLeft(StringTrimRight(Levels)); if (StringSubstr(Levels,StringLen(Levels),1) != ";") Levels = StringConcatenate(Levels,";"); // // // // // int s = 0; int i = StringFind(Levels,";",s); while (i > 0) { string current = StringSubstr(Levels,s,i-s); double value = StrToDouble(current); if (value > 0) { ArrayResize(levels,ArraySize(levels)+1); levels[ArraySize(levels)-1] = value; } s = i + 1; i = StringFind(Levels,";",s); } ArraySort(levels); levelsCount = ArraySize(levels); ArrayResize(alertTimes,levelsCount*4+1); ArrayResize(alertEvents,levelsCount*4+1); // // // // // IndicatorBuffers(3); SetIndexBuffer(0,Pivot); SetIndexStyle(0,DRAW_NONE); SetIndexBuffer(1,Range); SetIndexBuffer(2,Dates); return(0); } // // // // // int deinit() { string lookFor = PivotIdentifier+"-"; int lookForLength = StringLen(lookFor); for (int i=ObjectsTotal()-1; i>=0; i--) { string objectName = ObjectName(i); if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName); } return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int start() { int counted_bars=IndicatorCounted(); int i,limit,drawLimit; if (Period() >= timeFrame) return(-1); if (counted_bars<0) return(-1); if (counted_bars>0) counted_bars--; limit = MathMin(Bars-counted_bars,Bars-1); drawLimit = MathMin(limit,iBarShift(NULL,0,iTime(NULL,timeFrame,ShowTotalPivots-1))); if (timeFrame==PERIOD_W1) while(TimeDayOfWeek(Time[drawLimit])==5) drawLimit--; // // // // // double pivot = Pivot[limit+1]; double range = Range[limit+1]; datetime dates = Dates[limit+1]; // // // // // for (i=limit; i>=0; i--) { int x = iBarShift(NULL,timeFrame,Time[i+1]-HourShift*3600,true); int y = iBarShift(NULL,timeFrame,Time[i] -HourShift*3600,true); if (x!=y) { int k = i; if (FixSundays && timeFrame==PERIOD_D1) while (k price && prev < price) doAlert(Description+what+" line crossed up" ,forWhat); if (curr < price && prev > price) doAlert(Description+what+" line crossed down",forWhat); } // // // // // void doAlert(string doWhat, int forWhat) { string message; if (alertEvents[forWhat] != doWhat || alertTimes[forWhat] != Time[0]) { alertEvents[forWhat] = doWhat; alertTimes[forWhat] = Time[0]; // // // // // message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," fibo pivot ",doWhat); if (alertsMessage) Alert(message); if (alertsEmail) SendMail(StringConcatenate(Symbol()," fibo pivot line crossing"),message); if (alertsSound) PlaySound("alert2.wav"); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // int stringToTimeFrame(string tfs) { int tf=0; tfs = StringUpperCase(tfs); if (tfs=="M1" || tfs=="1") { tf=PERIOD_M1; Description = "";} if (tfs=="M5" || tfs=="5") { tf=PERIOD_M5; Description = "5 minutes "; } if (tfs=="M15"|| tfs=="15") { tf=PERIOD_M15; Description = "15 minutes ";} if (tfs=="M30"|| tfs=="30") { tf=PERIOD_M30; Description = "half hour "; } if (tfs=="H1" || tfs=="60") { tf=PERIOD_H1; Description = "hourly "; } if (tfs=="H4" || tfs=="240") { tf=PERIOD_H4; Description = "4 hourly "; } if (tfs=="D1" || tfs=="1440") { tf=PERIOD_D1; Description = "daily "; } if (tfs=="W1" || tfs=="10080") { tf=PERIOD_W1; Description = "weekly "; } if (tfs=="MN" || tfs=="43200") { tf=PERIOD_MN1; Description = "monthly "; } return(tf); } // // // // // string StringUpperCase(string str) { string s = str; int length = StringLen(str) - 1; int tchar; while(length >= 0) { tchar = StringGetChar(s, length); // // // // // if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256)) s = StringSetChar(s, length, tchar - 32); else if(tchar > -33 && tchar < 0) s = StringSetChar(s, length, tchar + 224); length--; } return(s); }