//+------------------------------------------------------------------+ //| ProjectName | //| Copyright 2012, CompanyName | //| http://www.companyname.net | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MetaQuotes Software Corp." #property link "http://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 2 //--- plot ExtMapBuffer1 #property indicator_label1 "Ups" #property indicator_type1 DRAW_COLOR_ARROW #property indicator_color1 clrRed,C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0' #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot ExtMapBuffer2 #property indicator_label2 "Downs" #property indicator_type2 DRAW_COLOR_ARROW #property indicator_color2 clrBlue,C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0',C'0,0,0' #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- input parameters input bool AlertsOn=true; input bool Comments=true; input bool TrendLine=true; input int TrendLineStyle=0; input int TrendLineWidth=1; input color UpperTrendLineColour=clrLimeGreen; input color LowerTrendLineColour=clrRed; input bool ProjectionLines=true; input int ProjectionLinesStyle=2; input int ProjectionLinesWidth=1; input color UpperProjectionLineColour=clrLimeGreen; input color LowerProjectionLineColour=clrRed; input bool HorizontLine=true; bool TD=false;/*Default is false. True setting draws up and down arrows instead of dots on TD Points creating more clutter.*/ int BackSteps=0;/*Used to be extern int now just int. Leave at 0*/ int ShowingSteps=1;/*Used to be extern int now just int. Leave at 1*/ bool FractalAsTD=false;/*Used to be extern bool now just bool. Leave at false, otherwise Trend Lines based on Fractal Points not TD Points*/ double TrendLineBreakUp=-1;//Line added. bool TrendLineBreakUpFlag=false;//Line added. double TrendLineBreakDown=-1;//Line added. bool TrendLineBreakDownFlag=false;//Line added. //double high[]; //double low[]; //double close[]; int H1; int H2; int L1; int L2; //--- indicator buffers double Ups[]; double Downs[]; double DemandLineHigh[]; double DemandLineLow[]; double TakeProfitHigh[]; double TakeProfitLow[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { PlotIndexSetInteger(0,PLOT_ARROW,217); PlotIndexSetInteger(1,PLOT_ARROW,218); //--- indicator buffers mapping SetIndexBuffer(0,Ups,INDICATOR_DATA); SetIndexBuffer(1,Downs,INDICATOR_DATA); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW //--- PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW); PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0); PlotIndexSetInteger(1,PLOT_DRAW_TYPE,DRAW_ARROW); for (int i=1;i<=10;i++) { ObjectDelete(0,"HHL_"+i);ObjectDelete(0,"HL_"+i); ObjectDelete(0,"HLL_"+i);ObjectDelete(0,"LL_"+i); ObjectDelete(0,"HC1_"+i); ObjectDelete(0,"HC2_"+i); ObjectDelete(0,"HC3_"+i); ObjectDelete(0,"LC1_"+i); ObjectDelete(0,"LC2_"+i); ObjectDelete(0,"LC3_"+i); } Comment(""); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { datetime t[]; CopyTime(Symbol(),Period(),0,Bars(Symbol(),Period()),t); for (int i=1;i<=10;i++) { ObjectDelete(0,"HHL_"+i);ObjectDelete(0,"HL_"+i); ObjectDelete(0,"HLL_"+i);ObjectDelete(0,"LL_"+i); ObjectDelete(0,"HC1_"+i); ObjectDelete(0,"HC2_"+i); ObjectDelete(0,"HC3_"+i); ObjectDelete(0,"LC1_"+i); ObjectDelete(0,"LC2_"+i); ObjectDelete(0,"LC3_"+i); } for(int i=0;i10) { Comment("ShowingSteps readings 0 - 10"); return(0); } for(int i=1;i<=ShowingSteps;i++)Comm=Comm+TDMain(i,High,Low,Close,Time); Comm=Comm+"------------------------------------\nShowingSteps="+ShowingSteps+"\nBackSteps="+BackSteps; if(FractalAsTD==true)Comm=Comm+"\nFractals"; else Comm=Comm+"\nTD point"; if(Comments==1)Comment(Comm); else Comment(""); //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { //--- } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { //--- } //+------------------------------------------------------------------+ void FractalFill(string symbol,ENUM_TIMEFRAMES tf, datetime &Time[]) { int count=Bars(Symbol(),Period()); //--- Set the arrays as timeseries ArraySetAsSeries(Ups,true); ArraySetAsSeries(Downs,true); ArraySetAsSeries(Time,true); //--- Create handle of the Indicator Fractals int FractalsHandle=iFractals(symbol,tf); Print("FractalsHandle = ",FractalsHandle); //--- Set Last error value to Zero ResetLastError(); //--- Try to copy the values of the indicator int copied=CopyBuffer(FractalsHandle,0,0,Bars(Symbol(), Period()),Ups); if(copied<=0) { Print("Unable to copy the upper fractals. Error = ",GetLastError()); return; } ResetLastError(); //--- Try to copy the values of the indicator copied=CopyBuffer(FractalsHandle,1,0,Bars(Symbol(),Period()),Downs); if(copied<=0) { Print("Unable to copy the bottom fractals. Error = ",GetLastError()); return; } ResetLastError(); //--- Copy timeseries containing the opening bars of the last 1000 ones copied=CopyTime(NULL,0,0,Bars(Symbol(),Period()),Time); if(copied<=0) { Print("Unable to copy the Opening Time of the last 1000 bars"); return; } int upcounter=0,downcounter=0; // count there the number of arrows bool created;// receive the result of attempts to create an object for(int i=2;iUps[H1]) { H2=i; break; } } } meet=false; for(int i=2;i0 && H2>0) { if(TrendLine==1) { ObjectCreate(0,"HL_"+Step,OBJ_TREND,0,0,0,0); TrendLineHighTD(H1,H2,Step,Col[Step*2-2],high,time); } else ObjectDelete(0,"HL_"+Step); if(HorizontLine==1 && Step==1) { ObjectCreate(0,"HHL_"+Step,OBJ_HLINE,0,0,0); ObjectSetInteger(0,"HHL_"+Step,OBJPROP_BACK,true);//Line added HorizontLineHighTD(H1,H2,Step,Style,Col[Step*2-2], high); } else ObjectDelete(0,"HHL_"+Step); if(ProjectionLines==1) { ObjectCreate(0,"HC1_"+Step,OBJ_HLINE,0,0,0); ObjectCreate(0,"HC2_"+Step,OBJ_HLINE,0,0,0); ObjectCreate(0,"HC3_"+Step,OBJ_HLINE,0,0,0); Comm=Comm+TakeProfitHighTD(H1,H2,Step,Col[Step*2-2],high, low, close,time); } else { ObjectDelete(0,"HC1_"+Step); ObjectDelete(0,"HC2_"+Step); ObjectDelete(0,"HC3_"+Step); } } //----------------------------------------------------------------------------------- if(L1>0 && L2>0) { if(TrendLine==1) { ObjectCreate(0,"LL_"+Step,OBJ_TREND,0,0,0,0); TrendLineLowTD(L1,L2,Step,Col[Step*2-1],low,time); } else ObjectDelete(0,"LL_"+Step); if(HorizontLine==1 && Step==1) { ObjectCreate(0,"HLL_"+Step,OBJ_HLINE,0,0,0); ObjectSetInteger(0,"HLL_"+Step,OBJPROP_BACK,true);//Line added HorizontLineLowTD(L1,L2,Step,Style,Col[Step*2-1],low); } else ObjectDelete(0,"HLL_"+Step); if(ProjectionLines==1) { ObjectCreate(0,"LC1_"+Step,OBJ_HLINE,0,0,0); ObjectCreate(0,"LC2_"+Step,OBJ_HLINE,0,0,0); ObjectCreate(0,"LC3_"+Step,OBJ_HLINE,0,0,0); Comm=Comm+TakeProfitLowTD(L1,L2,Step,Col[Step*2-1],high, low, close,time); } else { ObjectDelete(0,"LC1_"+Step); ObjectDelete(0,"LC2_"+Step); ObjectDelete(0,"LC3_"+Step); } } //-------------------------------------------------------------------- if(AlertsOn)//added this Alerts section { //Print("Alerts On"); if(close[0]>TrendLineBreakUp && TrendLineBreakUpFlag==false) { //Print("Upper TrendLine Break ",Symbol()," ",Period()," ",Bid); // Alert("UTL Break>",TrendLineBreakUp," on ",_Symbol," ",_Period," @ ",Bid); TrendLineBreakUpFlag=true; } if(close[0]0;i--)if(close[i]>high[H2]-kH*(H2-i)){k=high[H2]-kH*(H2-i);break;} if(k>0) { Comm=Comm+"UTD_Line ("+DoubleToString(high[H2]-kH*H2,j)+") broken at "+DoubleToString(k,j)+", uptargets:\n"; ii=ArrayMinimum(low,i,H2-i)+i; HC1=high[H2]-kH*(H2-ii)-low[ii]; HC2=high[H2]-kH*(H2-ii)-close[ii]; ii=ArrayMinimum(close,i,H2-i)+i; HC3=high[H2]-kH*(H2-ii)-close[ii]; St=TrendLineStyle;/*Original STYLE_SOLID*/ } else { k=high[H2]-kH*H2; Comm=Comm+"UTD_Line ("+DoubleToString(k,j)+"), probable break-up targets:\n"; ii=ArrayMinimum(low,0,H2); HC1=high[H2]-kH*(H2-ii)-low[ii]; HC2=high[H2]-kH*(H2-ii)-close[ii]; ii=ArrayMinimum(close,0,H2); HC3=high[H2]-kH*(H2-ii)-close[ii]; St=TrendLineStyle;/*Original STYLE_DASHDOT*/ } ObjectSetInteger(0,"HL_"+Step,OBJPROP_STYLE,St); Comm=Comm+"T1="+DoubleToString(HC1+k,j)+" ("+DoubleToString(HC1/_Point,0)+"pts.)\n";//changed "pts.)" to "pts.)\n" //Comm=Comm+" T2="+DoubleToStr(HC2+k,j)+" ("+DoubleToStr(HC2/Point,0)+"pts.)"; //Comm=Comm+" T3="+DoubleToStr(HC3+k,j)+" ("+DoubleToStr(HC3/Point,0)+"pts.)\n"; ObjectSetInteger(0,"HC1_"+Step,OBJPROP_TIME,Time[H1]);ObjectSetInteger(0,"HC1_"+Step,OBJPROP_TIME,1,Time[0]); ObjectSetDouble(0,"HC1_"+Step,OBJPROP_PRICE,HC1+k);ObjectSetDouble(0,"HC1_"+Step,OBJPROP_PRICE,1,HC1+k); ObjectSetInteger(0,"HC1_"+Step,OBJPROP_COLOR,Col);ObjectSetInteger(0,"HC1_"+Step,OBJPROP_STYLE,St); //ObjectSet("HC2_"+Step,OBJPROP_TIME1,Time[H1]);ObjectSet("HC2_"+Step,OBJPROP_TIME2,Time[0]); //ObjectSet("HC2_"+Step,OBJPROP_PRICE1,HC2+k);ObjectSet("HC2_"+Step,OBJPROP_PRICE2,HC2+k); //ObjectSet("HC2_"+Step,OBJPROP_COLOR,Col);ObjectSet("HC2_"+Step,OBJPROP_STYLE,St); //ObjectSet("HC3_"+Step,OBJPROP_TIME1,Time[H1]);ObjectSet("HC3_"+Step,OBJPROP_TIME2,Time[0]); //ObjectSet("HC3_"+Step,OBJPROP_PRICE1,HC3+k);ObjectSet("HC3_"+Step,OBJPROP_PRICE2,HC3+k); //ObjectSet("HC3_"+Step,OBJPROP_COLOR,Col);ObjectSet("HC3_"+Step,OBJPROP_STYLE,St); if(Step==1) { ObjectSetInteger(0,"HC1_"+Step,OBJPROP_WIDTH,ProjectionLinesWidth);/*Original OBJPROP_WIDTH,2*/ ObjectSetInteger(0,"HC1_"+Step,OBJPROP_STYLE,ProjectionLinesStyle);/*This Line of code added from original. TD Upper Projection Line Style*/ // ObjectSet("HC2_"+Step,OBJPROP_WIDTH,2); // ObjectSet("HC3_"+Step,OBJPROP_WIDTH,2); } else { ObjectSetInteger(0,"HC1_"+Step,OBJPROP_WIDTH,2); // ObjectSet("HC2_"+Step,OBJPROP_WIDTH,2); // ObjectSet("HC3_"+Step,OBJPROP_WIDTH,2); } return(Comm); } //-------------------------------------------------------------------- string TakeProfitLowTD(int L1,int L2,int Step,int Col, double &high[], double &low[], double &close[],datetime &Time[])/*Draw Sell TD Price Projection(s)*/ { int i,ii,j=0; string Comm=""; double kL,LC1,LC2,LC3,k,St; kL=(low[L1]-low[L2])/(L2-L1); while(NormalizeDouble(_Point,j)==0)j++; k=0; for(i=L1;i>0;i--) if(close[i]0) { Comm=Comm+"LTD_Line ("+DoubleToString(low[L2]+kL*L2,j)+") broken at "+DoubleToString(k,j)+", downtargets:\n"; ii=ArrayMaximum(high,i,L2-i)+i; LC1=high[ii]-(low[L2]+kL*(L2-ii)); LC2=close[ii]-(low[L2]+kL*(L2-ii)); i=ArrayMaximum(close,i,L2-i)+i; LC3=close[ii]-(low[L2]+kL*(L2-ii)); St=TrendLineStyle;/*Original STYLE_SOLID*/ } else { k=low[L2]+kL*L2; Comm=Comm+"LTD_Line ("+DoubleToString(k,j)+"), probable downbreak targets:\n"; ii=ArrayMaximum(high,0,L2); LC1=high[ii]-(low[L2]+kL*(L2-ii)); LC2=close[ii]-(low[L2]+kL*(L2-ii)); ii=ArrayMaximum(close,0,L2); LC3=close[ii]-(low[L2]+kL*(L2-ii)); St=TrendLineStyle;/*Original STYLE_DASHDOT*/ } ObjectSetInteger(0,"LL_"+Step,OBJPROP_STYLE,St); Comm=Comm+"T1="+DoubleToString(k-LC1,j)+" ("+DoubleToString(LC1/_Point,0)+"pts.)\n";//changed "pts.)" to "pts.)\n" //Comm=Comm+" T2="+DoubleToStr(k-LC2,j)+" ("+DoubleToStr(LC2/Point,0)+"pts.)"; //Comm=Comm+" T3="+DoubleToStr(k-LC3,j)+" ("+DoubleToStr(LC3/Point,0)+"pts.)\n"; ObjectSetInteger(0,"LC1_"+Step,OBJPROP_TIME,Time[L1]);ObjectSetInteger(0,"LC1_"+Step,OBJPROP_TIME,1,Time[0]); ObjectSetDouble(0,"LC1_"+Step,OBJPROP_PRICE,k-LC1);ObjectSetDouble(0,"LC1_"+Step,OBJPROP_PRICE,1,k-LC1); ObjectSetInteger(0,"LC1_"+Step,OBJPROP_COLOR,Col);ObjectSetInteger(0,"LC1_"+Step,OBJPROP_STYLE,St); //ObjectSet("LC2_"+Step,OBJPROP_TIME1,Time[L1]);ObjectSet("LC2_"+Step,OBJPROP_TIME2,Time[0]); //ObjectSet("LC2_"+Step,OBJPROP_PRICE1,k-LC2);ObjectSet("LC2_"+Step,OBJPROP_PRICE2,k-LC2); //ObjectSet("LC2_"+Step,OBJPROP_COLOR,Col);ObjectSet("LC2_"+Step,OBJPROP_STYLE,St); //ObjectSet("LC3_"+Step,OBJPROP_TIME1,Time[L1]);ObjectSet("LC3_"+Step,OBJPROP_TIME2,Time[0]); //ObjectSet("LC3_"+Step,OBJPROP_PRICE1,k-LC3);ObjectSet("LC3_"+Step,OBJPROP_PRICE2,k-LC3); //ObjectSet("LC3_"+Step,OBJPROP_COLOR,Col);ObjectSet("LC3_"+Step,OBJPROP_STYLE,St); if(Step==1) { ObjectSetInteger(0,"LC1_"+Step,OBJPROP_WIDTH,ProjectionLinesWidth);/*Original OBJPROP_WIDTH,2*/ ObjectSetInteger(0,"LC1_"+Step,OBJPROP_STYLE,ProjectionLinesStyle);/*This Line of code added from original. TD Lower Projection Line Style*/ //ObjectSet("LC2_"+Step,OBJPROP_WIDTH,2); //ObjectSet("LC3_"+Step,OBJPROP_WIDTH,2); } else { ObjectSetInteger(0,"LC1_"+Step,OBJPROP_WIDTH,2); //ObjectSet("LC2_"+Step,OBJPROP_WIDTH,2); //ObjectSet("LC3_"+Step,OBJPROP_WIDTH,2); } return(Comm); } //+------------------------------------------------------------------+