//------------------------------------------------------------------/ // Indicator-advisor based on Demark threory with additions // Some part of the code was taken from Ind-TD-DeMark-3-1.mq4 [Kara ©] //------------------------------------------------------------------/ #property copyright "GreenDog" #property link "krot@inbox.ru" // v2.3 #property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Blue extern int showBars=3000; // if showBars= 0 so the indicator will be shown for all the chart extern int LevDP=2; // Demar Pint Levels; 2 = central bar will be higher (lower) then 2 bars on the left side and 2 bars on the right one. extern int qSteps=1; // number of steps/ no more than 3 extern int BackStep=0; // number of staps back extern int startBar=0; // ifstartBar=0 so we have recommendation for the current bar, if 1 - for possible next bar extern bool TrendLine=false; // false = no trend lines extern bool HorizontLine=false; // true = break levels extern bool ChannelLine=false; // true = channels which is parallel with trend lines extern bool TakeLines=false; // true = take profit lines extern bool Comments=false; // true = comments extern int Trend=0; // 1 = for UpTrendLines only, -1 = for DownTrendLines only, 0 = for all TrendLines extern bool ShowArrows=true; extern bool CustomFeatures=true; extern color UpTrendColor=Green; extern color DownTrendColor=Red; extern int TrendlineWidth=3; extern bool ShowAlerts=false; extern bool EmailAlert=false; int trendwidth; color trendcol; //int ColNum[]; double Buf1[]; double Buf2[]; string Col[]={"Red","DarkBlue","Coral","DodgerBlue","SaddleBrown","MediumSeaGreen"}; //int ColNum[1]=coll1; //={coll1,coll2,coll3,coll4,coll5,coll6}; int ColNum[]={Red,DeepSkyBlue,Coral,Aqua,SaddleBrown,MediumSeaGreen}; //DeepSkyBlue int qPoint=0; // переменная для нормализации цены int qBars; double qTime=0; // переменные для ликвидации глюков при загрузке int init() { qBars=Bars; qSteps=MathMin(3,qSteps); while (NormalizeDouble(Point,qPoint)==0)qPoint++; int code=161; string Rem="DLines © GameOver"; IndicatorShortName(Rem); if (ShowArrows){ SetIndexStyle(0,DRAW_ARROW); SetIndexStyle(1,DRAW_ARROW); } SetIndexArrow(0,code); SetIndexArrow(1,code); SetIndexBuffer(0,Buf1); SetIndexBuffer(1,Buf2); SetIndexEmptyValue(0,0.0); SetIndexEmptyValue(1,0.0); SetIndexLabel(0,Rem); SetIndexLabel(1,Rem); return(0); } int deinit() { ObjectsDeleteAll(); Comment(""); ArrayInitialize(Buf1,0.0); ArrayInitialize(Buf2,0.0); for(int i=1;i<=LevDP;i++){ ObjectDelete("HA_"+i);ObjectDelete("LA_"+i); ObjectDelete("HL_"+i);ObjectDelete("LL_"+i); ObjectDelete("HHL_"+i);ObjectDelete("HLL_"+i); ObjectDelete("HCL_"+i);ObjectDelete("LCL_"+i); for(int j=0;j<4;j++) {ObjectDelete("HTL_"+i+j);ObjectDelete("LTL_"+i+j);} } } int start(){ if (qBars!=Bars){ deinit(); Sleep(1000); qBars=Bars; qTime=0; return(0);} if (qTime==Time[0]) return(0); qTime=Time[0]; // запускаеца тока на 1м тике // заполнили и отобразили точки демарка if (showBars==0) showBars=Bars-LevDP; for (int cnt=showBars;cnt>LevDP;cnt--) { Buf1[cnt]=DemHigh(cnt,LevDP); Buf2[cnt]=DemLow(cnt,LevDP); } string Comm; double j; int m,s,k; m=Time[0]+Period()*60-CurTime(); j=m/60.0; s=m%60; m=(m-m%60)/60; Comm=Comm+"Demark with alerts"; Comm=Comm+( m + " minutes " + s + " seconds left to bar end")+"\n"; if (Comments){Comment(Comm);}else{Comment("Demark with alerts" + "\n" + m + " minutes " + s + " seconds left to bar end" +"\n");} Comm=Comm+"Trend Line["+On(TrendLine)+"]; Channel ["+On(ChannelLine)+ "]; Breakout level ["+On(HorizontLine)+"]; Targets ["+On(TakeLines)+"]\n"; for(cnt=1;cnt<=qSteps;cnt++) Comm=Comm+(TDMain(cnt)); Comm=Comm+"———— © GameOver ————"; if (Comments==true) Comment(Comm); return(0); } string TDMain(int Step){ int H1,H2,L1,L2,qExt,i,col; double tmp,qTL,qLevel,HT[4],LT[4]; bool isHitch; string Comm="»—»—» Step "+Step+" of "+qSteps+" (BackStep "+BackStep+")\n",Text,Rem,qp; static datetime timealertupper, timealertlower; // для DownTrendLines if (Trend<=0){ Comm=Comm+"» "+Col[Step*2-2]+" DownTrendLine "; col=ColNum[Step*2-2]; H1=GetTD(Step+BackStep,Buf1); H2=GetNextHighTD(H1); qTL=(High[H2]-High[H1])/(H2-H1); qExt=Lowest(NULL,0,MODE_LOW,H2-H1-1,H1+1); // локальный минимум между точками qLevel=High[H2]-qTL*(H2); if (Step+BackStep==1) qLevel=qLevel-qTL*startBar; if (H1<0 || H2<0) Comm=Comm+"not enough points on the chart for construction\n"; else { Comm=Comm+"["+DoubleToStr(High[H2],qPoint)+"»"+DoubleToStr(High[H1],qPoint)+"]"; Comm=Comm+"; Level "+DoubleToStr(qLevel,qPoint); if (Step+BackStep==1) { if (startBar>0) Comm=Comm+"; Future Bar "+UpHitch(-1,qLevel); else Comm=Comm+"; Last Bar "+UpHitch(startBar,qLevel); } Comm=Comm+"\n"; // Анализ - был ли пробой трендовой линии i=H1;isHitch=false;Text=""; while(i>0 && isHitch==false){ tmp=High[H2]-qTL*(H2-i); Rem="HA_"+Step; if (Close[i]>tmp){ qp=UpHitch(i,tmp); if (qp!=""){ isHitch=true; Text=Text+"Source "+DoubleToStr(tmp,qPoint)+" "+qp; if (timealertupper!=Time[i]){ if (ShowAlerts){ Alert ("MOUTEKI: Upper trendline broken on " + Symbol() + " TF: " + Period() + " @ " + Bid); } ObjectCreate(Rem,OBJ_ARROW,0,0,0,0,0); ObjectSet(Rem,OBJPROP_COLOR,col); ObjectSet(Rem,OBJPROP_PRICE1,Low[i]-Point); ObjectSet(Rem,OBJPROP_TIME1,Time[i]); ObjectSet(Rem,OBJPROP_ARROWCODE,241); //} if (EmailAlert){ SendMail("MOUTEKI: Upper trendline broken on " + Symbol() + " TF: " + Period() + " @ " + Bid, "MOUTEKI: Upper trendline broken on " + Symbol() + " TF: " + Period() + " @ " + Bid + "\n" + "Alerts by LightKeeper. martkoz@optusnet.com.au"); } timealertupper=Time[i]; } ///////////////////////////////////// ObjectCreate(Rem,OBJ_ARROW,0,0,0,0,0); ObjectSet(Rem,OBJPROP_COLOR,col); ObjectSet(Rem,OBJPROP_PRICE1,Low[i]-Point); ObjectSet(Rem,OBJPROP_TIME1,Time[i]); ObjectSet(Rem,OBJPROP_ARROWCODE,241); //////////////////////////////////// if (ShowArrows==true){ while(i>0){ // пробой отменен, если после пробоя был новый лоу или закрытие ниже i--; if (Low[i]