/*[[ Name := Robot_PowerM5_demo Author := MT Link := http://www.metexinvest.com/ Notes := long if bulls+bears>0:::short if bulls+bears<0 Lots := 1.00 Stop Loss := 45 Take Profit := 150 Trailing Stop := 15 ]]*/ Var: T2TS(0),T1Sig(0),T1Sig2(0),T2Sig(0),T2Sig2(0),T1Direction(0),T2Entry(0),Opentrades(0),Direction(0),Long_Entry(0),Short_Entry(0); Define: slippage(2); Var: sl(0); Var: tp(0); Var: cnt(0); Define: Bar(1); T1Sig = 0; T2Sig = 0; T2Sig2 = 0; T1Sig=icustom("#T1(ASCTrend1)",3,500,mode_first,Bar); T2Sig=icustom("NRTR WATR 1",10,1,500,MODE_FIRST,Bar); T2Sig2=icustom("NRTR WATR 1",10,1,500,MODE_SECOND,Bar); T2Entry=0; T1Direction = 0; Short_Entry=0; Long_Entry=0; Direction = 0; If T1Sig=l[bar] then { T1Direction=1; }; If T1Sig=h[bar] then { T1Direction=-1; }; If T2Sig == 0 and T2Sig2 != 0 then { T2Entry=1; T2TS = T2Sig2; }; If T2Sig != 0 and T2Sig2 == 0 then { T2Entry=-1; T2TS = T2Sig; }; If T1Direction == 1 and T2Entry == 1 then { Short_Entry=0; Long_Entry=1; }; If T1Direction == -1 and T2Entry == -1 then { Short_Entry=1; Long_Entry=0; }; Comment("\n","Day : ",Day," Hour : ",Hour," Min ",Minute," Seconds ", Seconds, "\n","Version 0.8", "\n", "\n","T1 Sig = ",T1Sig," T2 Sig = ",T2Sig," T2 Sig2 = ",T2Sig2," T2 Trailing = ",T2TS, "\n","T1 Direction = ",T1Direction," T2 Entry = ",T2Entry, "\n","Short Entry = ",Short_Entry," Long Entry = ",Long_Entry); Define: StartHour(9),EndHour(14); if TimeHour(CurTime)=EndHour then { Comment("Outside Trading Hours, Exiting...", "\n","Version 0.7", "\n", "\n","T1 Sig = ",T1Sig," T2 Sig = ",T2Sig," T2 Sig2 = ",T2Sig2," T2 Trailing = ",T2TS, "\n","T1 Direction = ",T1Direction," T2 Entry = ",T2Entry, "\n","Short Entry = ",Short_Entry," Long Entry = ",Long_Entry); 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,5,Violet); exit; }; If OrderValue(cnt,VAL_TYPE)=OP_SELL then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,5,Violet); exit; }; }; }; exit; }; ////////////////////////////////////////////////// ///////////// Manage multiple trades ///////////// ////////////////////////////////////////////////// Opentrades=0; For cnt=1 to TotalTrades Begin If OrderValue(cnt,Val_Symbol)=Symbol then { Opentrades=Opentrades+1; }; End; if OpenTrades != 0 then { for cnt = 1 to TotalTrades { if OrderValue(cnt, VAL_SYMBOL) == Symbol then { if (OrderValue(cnt, VAL_TYPE) == OP_BUY) then { // if vSig151 or vSig153 then // { // Exit; // } if T1Direction == -1 then { Alert("Closing Buy position because T1 is showing short"); CloseOrder (OrderValue(cnt, VAL_TICKET),OrderValue(cnt, VAL_LOTS),OrderValue(cnt, VAL_CLOSEPRICE),Slippage,blue); Exit; } } if (OrderValue(cnt, VAL_TYPE) == OP_SELL) then { // if vSig152 or vSig153 then // { // Exit; // } if T1Direction == 1 then { Alert("Closing Sell position because T1 is showing long"); CloseOrder (OrderValue(cnt, VAL_TICKET),OrderValue(cnt, VAL_LOTS),OrderValue(cnt, VAL_CLOSEPRICE),Slippage,red); Exit; } } } } } if TotalTrades < 1 then { if Long_Entry == 1 then { sl = T2TS; If Takeprofit <> 0 then { tp = Bid + TakeProfit * Point; }; If Takeprofit == 0 then { tp = 0; }; Alert("Both T1 and T2, agree to go Long, therefore, long we go!"); SetOrder(OP_BUY,Lots,Ask,slippage,sl,tp,Blue); Exit; } if Short_Entry == 1 then { sl = T2TS; If Takeprofit <> 0 then { tp = Ask - TakeProfit * Point; }; If Takeprofit == 0 then { tp = 0; }; Alert("Both T1 and T2, agree to go Short, therefore, short we go!"); SetOrder(OP_SELL,Lots,Bid,slippage,sl,tp,Red); Exit; } }; for cnt=1 to TotalTrades begin If Ord(cnt,VAL_TYPE)=OP_BUY and OrderValue(cnt,VAL_SYMBOL)= Symbol then { If (Bid-Ord(cnt,VAL_OPENPRICE))>(Bid - T2TS) then { If Ord(cnt,VAL_STOPLOSS)<(T2TS) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), T2TS,Ord(cnt,VAL_TAKEPROFIT),Orange); Exit; }; }; }; If Ord(cnt,VAL_TYPE)=OP_SELL and OrderValue(cnt,VAL_SYMBOL)= Symbol then { If (Ord(cnt,VAL_OPENPRICE)-Ask)>(T2TS - Ask) then { If Ord(cnt,VAL_STOPLOSS)>(T2TS) or Ord(cnt,VAL_STOPLOSS)=0 then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), T2TS,Ord(cnt,VAL_TAKEPROFIT),Orange); Exit; }; }; }; end;