/*[[ Name := Robot_PowerM5_demo Author := MT Link := http://www.metexinvest.com/ Notes := M5 for all majors Lots := 1.00 Stop Loss := 30 Take Profit := 150 Trailing Stop := 5 ]]*/ Var: bull(0),bear(0); Define: slippage(2),MM(1),Risk(7.5); Var: sl(0),tp(0),cnt(0),b(0),s(0),Opentrades(0),lotMM(0),ITB(0),ITS(0),AccountIsMini(1),MarginCutoff(0),LiveTrading(1); Var: GlobalName(""),Direction(0); ITB=icustom("itrend",0,0,0,20,2,14,mode_first,1); ITS=icustom("itrend",0,0,0,20,2,14,mode_second,1); GlobalName = "Gb1_Wk_"+Symbol+"_Direction"; Direction=GetGlobalVariable(GlobalName); bull = iBullsPower(5,PRICE_CLOSE,1); bear = iBearsPower(5,PRICE_CLOSE,1); comment("Bull + Bear = ",bull + bear,"\nI-Trend Blue ",ITB,"\nI-Trend Red ",ITS,"\nDirection from longer TF = ",Direction,"\nLots traded ",lotMM); // ==================================================================================================== // PYRAMIDING - LINEAR // Money management risk exposure compounding // ==================================================================================================== if AccountIsMini == 0 then MarginCutoff = 1000; if AccountIsMini == 1 then MarginCutoff = 100; if FreeMargin < Margincutoff then Exit; if mm <> 0 then { lotMM = Ceil(Balance * risk / 10000) / 10; if lotMM < 0.1 then lotMM = Lots; if lotMM > 1.0 then lotMM = Ceil(lotMM); // Enforce lot size boundaries if LiveTrading == 1 then { if AccountIsMini == 1 then lotMM = lotMM * 10; if AccountIsMini == 0 and lotMM < 1.0 then lotMM = 1.0; } if lotMM > 100 then lotMM = 100; } else { lotMM = Lots; // Change mm to 0 if you want the Lots parameter to be in effect }; ////////////////////////////////////////////////// ///////////// 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 { if bull + bear > 0 and ITB = 1 and ITS = 0 and Direction = 1 then { SetOrder(OP_BUY,lotMM,Ask,slippage,Ask-StopLoss*Point, Ask+TakeProfit*Point,Blue); Exit; } if bull + bear < 0 and ITS = -1 and ITB = 0 and Direction = -1 then { SetOrder(OP_SELL,lotMM,Bid,slippage,Bid + StopLoss * Point,Bid-TakeProfit*Point,Red); Exit; } } b = 1 * Point + iATR(5,1) * 1.5; s = 1 * Point + iATR(5,1) * 1.5; for cnt = 1 to TotalTrades { if OrderValue(cnt,VAL_TYPE) == 0 and OrderValue(cnt,VAL_SYMBOL) == Symbol then { if OrderValue(cnt,VAL_OPENPRICE) > OrderValue(cnt,VAL_STOPLOSS) and Bid - OrderValue(cnt,VAL_OPENPRICE) > StopLoss * Point then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),OrderValue(cnt,VAL_OPENPRICE),OrderValue(cnt,VAL_TAKEPROFIT),SlateBlue); Exit; } if Bid - OrderValue(cnt,VAL_OPENPRICE) > b then { if OrderValue(cnt,VAL_STOPLOSS) < Bid - b then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Bid - b,OrderValue(cnt,VAL_TAKEPROFIT),SlateBlue); Exit; } } } if OrderValue(cnt,VAL_TYPE) == 1 and OrderValue(cnt,VAL_SYMBOL) == Symbol then { if OrderValue(cnt,VAL_OPENPRICE) < OrderValue(cnt,VAL_STOPLOSS) and OrderValue(cnt,VAL_OPENPRICE) - Ask > StopLoss * Point then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),OrderValue(cnt,VAL_OPENPRICE),OrderValue(cnt,VAL_TAKEPROFIT),Red); Exit; } if OrderValue(cnt,VAL_OPENPRICE) - Ask > s then { if OrderValue(cnt,VAL_STOPLOSS) > Ask + s then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Ask + s,OrderValue(cnt,VAL_TAKEPROFIT),Red); Exit; } } } }