=20 #property copyright "Copyright =A9 2007, Tim Hyder" #property link "" #define vers "04.09.2007" #define major 1 #define minor 1 #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 6 #property indicator_buffers 4 #property indicator_color1 Lime #property indicator_color2 DarkOrange #property indicator_color3 Green #property indicator_color4 Red extern string _tmp1_ =3D " --- #TrendMTFROC options ---"; //Use VertShift as unique number to indentify each indicator=20 //when multiple are displayed. extern int VertShift =3D 1; extern double FineVertShift =3D -0.3; extern bool DisplayLegend =3D True;=20 extern int TimeFrame =3D 0; extern double NonYenTrendLevel =3D 50; extern double YenTrendLevel =3D 0.5; extern int MaxBars =3D 500; extern string _tmp2_ =3D " --- MA-ATR-ROC options ---"; extern int MA.Length =3D 20; extern int MA.Type =3D MODE_SMA; extern int MA.Price =3D PRICE_CLOSE; extern int ATR.Period =3D 5; extern int ROC.Period =3D 5; extern string _tmp3_ =3D " --- Alerts ---"; extern bool AllowTextAlerts =3D true; extern bool AllowSoundAlerts =3D true; extern string LongSound =3D "alert3.wav"; extern string ShortSound =3D "alert4.wav"; extern bool AllowEmailAlerts =3D false; //colour of time frame label on far right of indicator color TextColor =3D White; //extern string _tmp4_ =3D " --- Legend Positioning ---"; int Legend.X =3D 550; int Legend.Y =3D 2; int Legend.BigSpace =3D 78; int Legend.SmallSpace =3D 12; //---- buffers double buf2_up[]; double buf2_down[]; double buf1_up[]; double buf1_down[]; string shortname =3D ""; string pref =3D "MTF_ROC"; int ArrSize =3D 110;//159; int BarWidth =3D 0; datetime LastTime =3D -1; //-----------------------------------------------------------------------= ---------------------------------------- void init() { =20 SetIndexStyle(0, DRAW_ARROW, 0, BarWidth); SetIndexStyle(1, DRAW_ARROW, 0, BarWidth); SetIndexStyle(2, DRAW_ARROW, 0, BarWidth); SetIndexStyle(3, DRAW_ARROW, 0, BarWidth); =20 SetIndexArrow(0, ArrSize); SetIndexArrow(1, ArrSize); SetIndexArrow(2, ArrSize); SetIndexArrow(3, ArrSize); =20 SetIndexBuffer(0, buf1_up); SetIndexBuffer(1, buf1_down); SetIndexBuffer(2, buf2_up); SetIndexBuffer(3, buf2_down); =20 SetIndexEmptyValue(0, 0.0); SetIndexEmptyValue(1, 0.0); SetIndexEmptyValue(2, 0.0); SetIndexEmptyValue(3, 0.0); SetIndexLabel(0, NULL); SetIndexLabel(1, NULL); SetIndexLabel(2, NULL); SetIndexLabel(3, NULL); IndicatorDigits(0); =20 //shortname =3D "TrendMTFROC ("+UniqueNum+", "+TimeFrame+", = "+VertShift+")"; shortname =3D "#TrendMTFROC"; if (DisplayLegend) IndicatorShortName(shortname); } void deinit() { for (int i=3DObjectsTotal()-1; i>-1; i--) { if (StringFind(ObjectName(i), pref+"_TF_"+VertShift) >=3D 0) { ObjectDelete(ObjectName(i)); continue; } =20 if (StringFind(ObjectName(i), pref+"_LG_"+VertShift) >=3D 0) { ObjectDelete(ObjectName(i)); continue; } } } void start() { if (TimeFrame > 0 && TimeFrame < Period()) { //Alert("Period of the indicator must be equal or greater than = current timeframe"); //return; } int counted_bars=3DIndicatorCounted(); //---- check for possible errors if (counted_bars < 0) return(-1); //---- the last counted bar will be recounted if (counted_bars > 0) counted_bars--; int limit =3D Bars - counted_bars; limit =3D MathMin(limit, MaxBars); =20 int i,tf; = //-------------------------------1---------------------------------------= - =20 =20 string txt =3D tf2txt(TimeFrame); double TimeDiff =3D Time[0]-Time[1]; =20 string name =3D pref+"_TF_"+VertShift+"_"+txt; =20 if (ObjectFind(name) =3D=3D -1) { =20 if(VertShift<FineVertShift) FineVertShift =3D 0; ObjectCreate(name, OBJ_TEXT, WindowFind(shortname), = iTime(NULL,0,0)+3*TimeDiff, VertShift-FineVertShift); ObjectSetText(name, txt,6,"Arial", TextColor); } else { ObjectSet(name, OBJPROP_TIME1, iTime(NULL,0,0)+3*TimeDiff); } = //-------------------------------Legend----------------------------------= ------ =20 =20 int FontSz =3D 7; int XDist =3D 0; XDist =3D Legend.X; if (DisplayLegend) { name =3D pref+"_LG_"+VertShift+"_Legend"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 //ObjectSet(name, OBJPROP_CORNER, 0); ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, "LEGEND", FontSz, "Arial", Silver); //--- name =3D pref+"_LG_"+VertShift+"_Sq1"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + 45; ObjectSet(name, OBJPROP_XDISTANCE,XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, CharToStr(110), FontSz+1, "Wingdings", = indicator_color1); =20 name =3D pref+"_LG_"+VertShift+"_Txt1"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + Legend.SmallSpace; ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, "TREND UP", FontSz, "Arial", indicator_color1); //--- =20 name =3D pref+"_LG_"+VertShift+"_Sq2"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + Legend.BigSpace-20; ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, CharToStr(110), FontSz+1, "Wingdings", = indicator_color3); =20 name =3D pref+"_LG_"+VertShift+"_Txt2"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + Legend.SmallSpace; ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, "BULLISH START", FontSz, "Arial", = indicator_color3); //--- =20 name =3D pref+"_LG_"+VertShift+"_Sq3"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + Legend.BigSpace; ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, CharToStr(110), FontSz+1, "Wingdings", = indicator_color2); =20 name =3D pref+"_LG_"+VertShift+"_Txt3"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + Legend.SmallSpace; ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, "BEARISH START", FontSz, "Arial", = indicator_color2); =20 //--- =20 name =3D pref+"_LG_"+VertShift+"_Sq4"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + Legend.BigSpace; ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, CharToStr(110), FontSz+1, "Wingdings", = indicator_color4); =20 name =3D pref+"_LG_"+VertShift+"_Txt4"; =20 if (ObjectFind(name) =3D=3D -1) ObjectCreate(name, OBJ_LABEL, WindowFind(shortname), 0, 0); =20 XDist =3D XDist + Legend.SmallSpace; ObjectSet(name, OBJPROP_XDISTANCE, XDist); ObjectSet(name, OBJPROP_YDISTANCE, Legend.Y); ObjectSetText(name, "DOWN TREND", FontSz, "Arial", = indicator_color4); =20 } =20 = //-------------------------------2---------------------------------------= - double Level =3D NonYenTrendLevel; if (StringFind(Symbol(), "JPY") !=3D -1) Level =3D YenTrendLevel; datetime TimeArray_1[]; ArrayCopySeries(TimeArray_1,MODE_TIME,Symbol(),TimeFrame); int yy; =20 //limit =3D MathMax(limit, TimeFrame/Period()); =20 for (i=3D0, yy=3D0; i<limit; i++) { if (Time[i] < TimeArray_1[yy]) yy++; double ROC =3D iCustom(NULL, TimeFrame, "i-MA-ATR-ROC", MA.Length, = MA.Type, MA.Price, ATR.Period, ROC.Period, 0, yy); =20 //int shift =3D iBarShift(NULL, TimeFrame, Time[i]); //double ROC =3D iCustom(NULL, TimeFrame, "i-MA-ATR-ROC", MA.Length, = MA.Type, MA.Price, ATR.Period, ROC.Period, 0, shift); buf1_down[i] =3D 0; buf1_up[i] =3D 0; =20 buf2_down[i] =3D 0; buf2_up[i] =3D 0; =20 if (ROC >=3D Level)=20 buf1_up[i] =3D VertShift; else if(ROC < Level && ROC >=3D 0) buf2_up[i] =3D VertShift; else if(ROC < 0 && ROC >=3D -Level) buf1_down[i] =3D VertShift; else if(ROC < -Level)=20 buf2_down[i] =3D VertShift; } =20 //----- /* buf1_up //Lime buf2_up //Green buf1_down //DarkOrange buf2_down //Red */ =20 string MailSubject =3D "#TrendMTFROC Alert"; string msg; =20 int bar =3D 1; =20 if (LastTime !=3D Time[0]) { //-> Lime if (buf1_up[bar] !=3D 0 && buf1_up[bar+1] =3D=3D 0) { msg =3D "ROC Trend on " +Symbol()+ " " +tf2txt(TimeFrame)+ " has = changed to Strong Long"; if (AllowTextAlerts) Alert(msg); if (AllowSoundAlerts) PlaySound(LongSound); if (AllowEmailAlerts) SendMail(MailSubject, msg); } //<- Lime if (buf1_up[bar] =3D=3D 0 && buf1_up[bar+1] !=3D 0) { msg =3D "ROC Trend on " +Symbol()+ " " +tf2txt(TimeFrame)+ " has = changed from Strong Long"; if (AllowTextAlerts) Alert(msg); if (AllowSoundAlerts) PlaySound(LongSound); if (AllowEmailAlerts) SendMail(MailSubject, msg); } //-> Red if (buf2_down[bar] !=3D 0 && buf2_down[bar+1] =3D=3D 0) { msg =3D "ROC Trend on " +Symbol()+ " " +tf2txt(TimeFrame)+ " has = changed to Strong Short"; if (AllowTextAlerts) Alert(msg); if (AllowSoundAlerts) PlaySound(ShortSound); if (AllowEmailAlerts) SendMail(MailSubject, msg); } //<- Red if (buf2_down[bar] =3D=3D 0 && buf2_down[bar+1] !=3D 0) { msg =3D "ROC Trend on " +Symbol()+ " " +tf2txt(TimeFrame)+ " has = changed from Strong Short"; if (AllowTextAlerts) Alert(msg); if (AllowSoundAlerts) PlaySound(ShortSound); if (AllowEmailAlerts) SendMail(MailSubject, msg); } =20 //----- =20 LastTime =3D Time[0]; } =20 return(0); } =20 =20 =20 //+------------------------------------------------------------------+ /* void getPeriod() { switch(Period())=20 { case 1:=20 Period_1=3D1; Period_2=3D5; //Period_3=3D15; Period_4=3D30; break; case 5:=20 Period_1=3D5; Period_2=3D15;// Period_3=3D30; Period_4=3D60; break; case 15:=20 Period_1=3D15; Period_2=3D30; //Period_3=3D60; = Period_4=3D240; break; case 30:=20 Period_1=3D30; Period_2=3D60; //Period_3=3D240; = Period_4=3D1440; break; case 60:=20 Period_1=3D60; Period_2=3D240;// Period_3=3D1440; = Period_4=3D10080; break; case 240:=20 Period_1=3D240; Period_2=3D1440;// Period_3=3D10080; = Period_4=3D43200; break; case 1440:=20 Period_1=3D1440; Period_2=3D10080; //Period_3=3D43200; = Period_4=3D43200; break; case 10080:=20 Period_1=3D10080; Period_2=3D43200;// Period_3=3D43200; = Period_4=3D43200; break; case 43200:=20 Period_1=3D43200; Period_2=3D43200;// Period_3=3D43200; = Period_4=3D43200; break; =20 } } */ string tf2txt(int tf) { if (tf =3D=3D 0) tf =3D Period(); =20 if (tf =3D=3D PERIOD_M1) return("M1"); if (tf =3D=3D PERIOD_M5) return("M5"); if (tf =3D=3D PERIOD_M15) return("M15"); if (tf =3D=3D PERIOD_M30) return("M30"); if (tf =3D=3D PERIOD_H1) return("H1"); if (tf =3D=3D PERIOD_H4) return("H4"); if (tf =3D=3D PERIOD_D1) return("D1"); if (tf =3D=3D PERIOD_W1) return("W1"); if (tf =3D=3D PERIOD_MN1) return("MN"); =20 return("??"); }
Sample
image not available
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Implements a curve of type DRAW_ARROW
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features:
It issuies visual alerts to the screen
It plays sound alerts
It sends emails