#
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
Home
Forex Forum
+ Add Script
Metastock
Expert Advisors
Explorations
Indicators
Trading Systems
Metatrader
MQL Experts
MQL Indicators
MQ4 Experts
MQ4 Indicators
MQ4 Scripts
Tradestation
Functions
Indicators
PaintBars
ShowMe
Trading Systems
Amibroker
Commentaries
Explorations
Functions
Indicators
Trading Systems
Contact us
Newsletter
Group: Metatrader MQL Experts
Title: DeMark Trend - Auto Trader
Description:
DeMark Trend - Auto Trader
/*[[ Name := DemarkTrendAutoTrader Author := Vladislav Goshkov Link := 4vg@mail.ru Lots := 1.00 Stop Loss := 35 Take Profit := 20 Trailing Stop := 25 ]]*/ Defines: MinTP(20), SetPoint(1),DrawAllLines(1),StepBack (0),maxBarsCount(1000); Defines: Magnitude(1),ColorUp(Blue),ColorDn(Red); defines: Patr(9),Prange(5),Kstop(1.5),kts(2),Vts(2); defines: YY(2004),MM(1),DD(01),HH(00), K(7.5), Risk(0); vars: pb(0),pts(10),tm(600),ls(0),sl(0),cnt(0),Slippage(5), HD(0),LD(0); Vars: DT_Up(0),DT_Dn(0),n_orders(0); Variable: MaxMagnitude(3),mgtd(2),i(1),NP(0),D(0),iP(0),iB_Up(0),iB_Dn(0),PP1(0),PP2(0),PP3(0),S1(0),S2(0); Vars : iP_Up(0),iP_Dn(0); Variable: UpLev(0),DownLev(0),UpV(0),DownV(0); Array: UpB[1,2](0),UpP[1,2](0),UpLevel[1,2](0),UpBT[1,2](0); Array: DownB[1,2](0),DownP[1,2](0),DownLevel[1,2](0),DownBT[1,2](0); Var: nBars(0),OldPeriod(0),value(0),shift(0); SetLoopCount(0);// loop from first bar to current bar (with shift=0) DelArrow(0,0); if nBars <> Bars or Period <> oldPeriod then { for shift = Bars DownTo 0 { value = GetIndexValue(shift); value = GetIndexValue2(shift); }; nBars = Bars ; OldPeriod = Period ; }; if Magnitude <1 then mgtd = 1 else mgtd = Magnitude; if mgtd > MaxMagnitude then mgtd = MaxMagnitude; D=2; NP=0; i=mgtd+1+StepBack; //================================================= //******** ????? ??????? ????? ??????????? ******** //================================================= UpP[1,1] = 0; UpP[1,2] = 0; DownP[1,1] = 1000000000; DownP[1,2] = 1000000000; if mgtd = 1 then { While NP
H[i+1] then { if (H[i]>H[i+1] & H[i]>H[i-1] & H[i]>C[i+2] ) and H[i]> UpP[1,1] then { UpLev = 1; UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); NP=NP+1; } i=i+1; }; if H[i]= H[i+1] then { if (H[i]>H[i+2] & H[i]>H[i-1] & H[i]>C[i+3] ) and H[i]> UpP[1,1] then { UpLev = 1; UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); NP=NP+1; } i=i+1; }; if i>maxBarsCount then { UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];//UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); break; }; End; }; //if mgtd = 1 then { if mgtd = 2 then { While NP
H[i+1] then { if (H[i]>H[i+1] & H[i]>H[i-1] ) and H[i]> UpP[1,1] and (H[i]>H[i+2] & H[i]>H[i-2] & H[i]>C[i+3] ) then { UpLev = 2; UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); NP=NP+1; } i=i+1; }; if H[i]= H[i+1] then { if (H[i]>H[i+2] & H[i]>H[i-1] ) and H[i]> UpP[1,1] and (H[i]>H[i+3] & H[i]>H[i-2] & H[i]>C[i+3] ) then { UpLev = 2; UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); NP=NP+1; } i=i+1; }; if i>maxBarsCount then { UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];//UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); break; }; End; }; //if mgtd = 2 then { if mgtd = 3 then { While NP
H[i+1] then { if (H[i]>H[i+1] & H[i]>H[i-1] ) and H[i]> UpP[1,1] and (H[i]>H[i+2] & H[i]>H[i-2] ) and (H[i]>H[i+3] & H[i]>H[i-3] & H[i]>C[i+4] ) then { UpLev = 3; UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); NP=NP+1; } i=i+1; }; if H[i]= H[i+1] then { if (H[i]>H[i+2] & H[i]>H[i-1] ) and H[i]> UpP[1,1] and (H[i]>H[i+3] & H[i]>H[i-2] ) and (H[i]>H[i+4] & H[i]>H[i-3] & H[i]>C[i+4] ) then { UpLev = 3; UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); NP=NP+1; } i=i+1; }; if i>maxBarsCount then { UpB[1,2]=UpB[1,1];UpB[1,1]=i; UpBT[1,2]=UpBT[1,1];UpBT[1,1]=Time[i]; UpP[1,2]=UpP[1,1];//UpP[1,1]=H[i]; UpLevel[1,2]=UpLevel[1,1];UpLevel[1,1]=UpLev; UpV=(UpP[1,2]-UpP[1,1])/(UpB[1,1]-UpB[1,2]); break; }; End; }; //if mgtd = 3 then { //================================================= //********** ????? ??????? ????? ?????? *********** //================================================= NP=0; i=mgtd+1+StepBack; if mgtd = 1 then { While NP
L[i+1] then { if (L[i]
maxBarsCount then { DownB[1,2]=DownB[1,1];DownB[1,1]=i; DownBT[1,2]=DownBT[1,1];DownBT[1,1]=Time[i]; DownP[1,2]=DownP[1,1];//DownP[1,1]=L[i]; DownLevel[1,2]=DownLevel[1,1];DownLevel[1,1]=DownLev; DownLevel[1,2]=DownLevel[1,1];DownLevel[1,1]=DownLev; DownV=(DownP[1,2]-DownP[1,1])/(DownB[1,1]-DownB[1,2]); break; }; End; }; //if mgtd = 1 then { if mgtd = 2 then { While NP
L[i+1] then { if (L[i]
maxBarsCount then { DownB[1,2]=DownB[1,1];DownB[1,1]=i; DownBT[1,2]=DownBT[1,1];DownBT[1,1]=Time[i]; DownP[1,2]=DownP[1,1];//DownP[1,1]=L[i]; DownLevel[1,2]=DownLevel[1,1];DownLevel[1,1]=DownLev; DownLevel[1,2]=DownLevel[1,1];DownLevel[1,1]=DownLev; DownV=(DownP[1,2]-DownP[1,1])/(DownB[1,1]-DownB[1,2]); break; }; End; }; //if mgtd = 2 then { if mgtd = 3 then { While NP
L[i+1] then { if (L[i]
maxBarsCount then { DownB[1,2]=DownB[1,1];DownB[1,1]=i; DownBT[1,2]=DownBT[1,1];DownBT[1,1]=Time[i]; DownP[1,2]=DownP[1,1];//DownP[1,1]=L[i]; DownLevel[1,2]=DownLevel[1,1];DownLevel[1,1]=DownLev; DownLevel[1,2]=DownLevel[1,1];DownLevel[1,1]=DownLev; DownV=(DownP[1,2]-DownP[1,1])/(DownB[1,1]-DownB[1,2]); break; }; End; }; //if mgtd = 3 then { //================================================= //**** ???? ????? ?????? ? ????????? ????????? **** //================================================= //================================================= //******** ?????? ??????? ????? ? TD-????? ******** //================================================= if setPoint<>0 then { // Time Price Symbol Color SetArrow(Time[UpB[1,1]],UpP[1,1],161, ColorUp); SetArrow(Time[UpB[1,2]],UpP[1,2],161, ColorUp); SetArrow(Time[DownB[1,1]],DownP[1,1],161, ColorDn); SetArrow(Time[DownB[1,2]],DownP[1,2],161, ColorDn); /* SetIndexValue(UpB[1,1],UpP[1,1]); SetIndexValue(UpB[1,2],UpP[1,2]); SetIndexValue(DownB[1,1],DownP[1,1]); SetIndexValue(DownB[1,2],DownP[1,2]); */ }; MoveObject("PP1"+NumberToStr(Magnitude,0),OBJ_HLINE,0,0,0,0,Red,1,STYLE_DOT); MoveObject("PP2"+NumberToStr(Magnitude,0),OBJ_HLINE,0,0,0,0,Blue,1,STYLE_DOT); MoveObject("PP3"+NumberToStr(Magnitude,0),OBJ_HLINE,0,0,0,0,Lime,1,STYLE_DOT); MoveObject("UpTrend"+NumberToStr(Magnitude,0),OBJ_TRENDLINE,0,0,0,0,ColorUp,Magnitude+1,STYLE_SOLID); MoveObject("DownTrend"+NumberToStr(Magnitude,0),OBJ_TRENDLINE,0,0,0,0,ColorDn,Magnitude+1,STYLE_SOLID); if DrawAllLines <> 0 then { MoveObject("UpTrend"+NumberToStr(Magnitude,0),OBJ_TRENDLINE,UpBT[1,1],UpP[1,1],UpBT[1,2],UpP[1,2],ColorUp,1,STYLE_SOLID); MoveObject("DownTrend"+NumberToStr(Magnitude,0),OBJ_TRENDLINE,DownBT[1,1],DownP[1,1],DownBT[1,2],DownP[1,2],ColorDn,1,STYLE_SOLID); }; //======================================================== //*** ???? ???????, ?? ?????? ????? ? ?????? ????????? *** //======================================================== if UpP[1,1] >= UpP[1,2] then { For i=UpB[1,2] DownTo StepBack Begin If C[i]>UpP[1,1]+UpV*(UpB[1,1]-i) & C[i+1]
DownP[1,1]+DownV*(DownB[1,1]-(i+1)) then { iB_Dn=i; iP=DownP[1,1]+DownV*(DownB[1,1]-i); iP_Dn = iP; S1=Highest(MODE_HIGH,DownB[1,1],DownB[1,1]-iB_Dn); S2=Highest(MODE_CLOSE,DownB[1,1],DownB[1,1]-iB_Dn); PP1=iP-(H[S1]-(DownP[1,1]+DownV*(DownB[1,1]-S1))); PP2=iP-(H[S2]-(DownP[1,1]+DownV*(DownB[1,1]-S2))); PP3=iP-(C[S1]-(DownP[1,1]+DownV*(DownB[1,1]-S1))); //SetIndexValue(iB_Dn,iP); DT_Dn = 1; DT_Up = 0; }; end; /* SetGlobalVariable("PP1_mg1",PP1); SetGlobalVariable("PP2_mg1",PP2); SetGlobalVariable("PP3_mg1",PP3); //Comment("DownTrend : Level ",Magnitude," magnitude"); */ MoveObject("DownTrend"+NumberToStr(Magnitude,0),OBJ_TRENDLINE,DownBT[1,1],DownP[1,1],DownBT[1,2],DownP[1,2],ColorDn,2*Magnitude+2,STYLE_SOLID); MoveObject("PP1"+NumberToStr(Magnitude,0),OBJ_HLINE,0,0,0,PP1,Red,1,STYLE_DOT); MoveObject("PP2"+NumberToStr(Magnitude,0),OBJ_HLINE,0,0,0,PP2,Blue,1,STYLE_DOT); MoveObject("PP3"+NumberToStr(Magnitude,0),OBJ_HLINE,0,0,0,PP3,Green,1,STYLE_DOT); //SetIndexValue(iB_Dn,iP); }; // ========================================================= // **** Orders Control **** // ========================================================= HD=0; LD=0; for i=1 to pts { HD+=H[i-1]; LD+=L[i-1]; }; sl=k*sqrt((HD-LD)/pts/Point)*Point ; // ========================================================= // ************* TRAILING STOP ADJUSTMENT ****************** // ========================================================= //------------------------------------------------------- for cnt = 1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL)=Symbol then { If Ord(cnt,VAL_TYPE)=OP_BUY then { if Ord(cnt,VAL_STOPLOSS)
Bid+sl+10*Point or Ord(cnt,VAL_StopLoss)=0 then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Bid+sl,Ord(cnt,VAL_TAKEPROFIT),0); Exit; }; }; }; }; //================================================================================ //**** Trading Entries **** //================================================================================ if DT_Up > 0 // ?????? ??????? ????????? and DT_Dn = 0 then { if TotalTrades <> 0 then { for cnt = 1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL) = Symbol then { if OrderValue(cnt,VAL_TYPE) = OP_SELL then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,Slippage,Red); Exit; }; }; }; n_orders = 0; for cnt = 1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL) = Symbol then { n_orders++; }; }; }; if TotalTrades = 0 or n_orders = 0 then { /* PP1 = GetGlobalVariable("PP1"); PP2 = GetGlobalVariable("PP2"); PP3 = GetGlobalVariable("PP3"); */ if ((PP1+PP2+PP3)/3)-Ask) > MinTP*Point then { SetOrder(OP_BUY,lots,Ask,Slippage,0,Max(Ask+TakeProfit*Point,(PP1+PP2+PP3)/3),Lime); Exit; }; }; }; if DT_Dn > 0 // ?????? ?????? ????????? and DT_Up = 0 then { if TotalTrades <> 0 then { for cnt = 1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL) = Symbol then { if OrderValue(cnt,VAL_TYPE) = OP_BUY then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,Slippage,Red); Exit; }; }; }; n_orders = 0; for cnt = 1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL) = Symbol then { n_orders++; }; }; }; if TotalTrades = 0 or n_orders = 0 then { /* PP1 = GetGlobalVariable("PP1"); PP2 = GetGlobalVariable("PP2"); PP3 = GetGlobalVariable("PP3"); */ if (Bid - (PP1+PP2+PP3)/3)) > MinTP*Point then { SetOrder(OP_SELL,lots,Bid,Slippage,0,Min(Bid-TakeProfit*Point,(PP1+PP2+PP3)/3),Blue); Exit; }; }; }; //======================================================== //*** ???????? ??????? !!!!!!!!!!!!!!!!!!!!!!!!!!!!! *** //========================================================
Author/Source:
Vladislav Goshkov
Forex Directory
|
Forex Trading Systems
|
Privacy
|
Disclaimer
|
Contact