/*[[ 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 := 15 ]]*/ Var: bull(0),bear(0); Define: slippage(2),MM(1),Risk(7.5); Var: sl(0),tp(0),cnt(0),b(0),s(0), I(0),Opentrades(0),lotsi(0), OpenSell(0),OpenBuy(0), ITB(0),ITS(0); var: Mode(0); Var: PriceOpen(0); bull = iBullsPower(5,PRICE_CLOSE,1); bear = iBearsPower(5,PRICE_CLOSE,1); comment("bull+bear= ",bull + bear,"\n I Blue ",ITB,"\n I Red ",ITS); ////////////////////////////////////////////////// ///////////// Manage multiple trades ///////////// ////////////////////////////////////////////////// OpenSell = 0; OpenBuy = 0; Opentrades=0; For I=1 to TotalTrades Begin If OrderValue(I,Val_Symbol)=Symbol then { Opentrades=Opentrades+1; }; Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == Symbol then { //Calculates how many Sell we have for the current Symbol if Mode == OP_SELL then { OpenSell++; }; //Calculates how many Buy we have for the current Symbol if Mode == OP_BUY then { OpenBuy++; }; }; End; ////////////////////////////////////////////////// ///////////// Money Manager ///////////// ////////////////////////////////////////////////// if mm<>0 then Lotsi=Ceil(Balance*risk/10000)/10 else Lotsi=Lots; if Opentrades = 0 then { if bull + bear > 0 and iCustom("Butterfly",MODE_SECOND,0) !=0 then { sl = Ask - StopLoss * Point; tp = Bid + TakeProfit * Point; SetOrder(OP_BUY,Lotsi,Ask,slippage,sl,tp,Blue); Exit; } if bull + bear < 0 and iCustom("butterfly",MODE_FIRST,0) !=0 then { sl = Bid + StopLoss * Point; tp = Ask - TakeProfit * Point; SetOrder(OP_SELL,Lotsi,Bid,slippage,sl,tp,Red); Exit; } } b = 1 * Point + iATR(5,1) * 1.5; s = 1 * Point + iATR(5,1) * 1.5; for I = 1 to TotalTrades { if OrderValue(I,VAL_TYPE) == 0 and OrderValue(I,VAL_SYMBOL) == Symbol then { if OrderValue(I,VAL_OPENPRICE) > OrderValue(I,VAL_STOPLOSS) and Bid - OrderValue(I,VAL_OPENPRICE) > StopLoss * Point then { ModifyOrder(OrderValue(I,VAL_TICKET),OrderValue(I,VAL_OPENPRICE),OrderValue(I,VAL_OPENPRICE),OrderValue(I,VAL_TAKEPROFIT),SlateBlue); Exit; } if Bid - OrderValue(I,VAL_OPENPRICE) > b then { if OrderValue(I,VAL_STOPLOSS) < Bid - b then { ModifyOrder(OrderValue(I,VAL_TICKET),OrderValue(I,VAL_OPENPRICE),Bid - b,OrderValue(I,VAL_TAKEPROFIT),SlateBlue); Exit; } } } if OrderValue(I,VAL_TYPE) == 1 and OrderValue(I,VAL_SYMBOL) == Symbol then { if OrderValue(I,VAL_OPENPRICE) < OrderValue(I,VAL_STOPLOSS) and OrderValue(I,VAL_OPENPRICE) - Ask > StopLoss * Point then { ModifyOrder(OrderValue(I,VAL_TICKET),OrderValue(I,VAL_OPENPRICE),OrderValue(I,VAL_OPENPRICE),OrderValue(I,VAL_TAKEPROFIT),Red); Exit; } if OrderValue(I,VAL_OPENPRICE) - Ask > s then { if OrderValue(I,VAL_STOPLOSS) > Ask + s then { ModifyOrder(OrderValue(I,VAL_TICKET),OrderValue(I,VAL_OPENPRICE),Ask + s,OrderValue(I,VAL_TAKEPROFIT),Red); Exit; } } } } /////////////////////////////////////////// // Trade Management ///////////////////////////////////////////////// for I = 1 to TotalTrades { Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == Symbol then { If OpenBuy > 0 then { if bull + bear < 0 and iCustom("Butterfly",MODE_FIRST,0) !=0 then { Alert("TREND CHANGE *** Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), PRICEBID, Slippage, yellow); Exit; }; If OpenSell > 0 then { if bull + bear > 0 and iCustom("Butterfly",MODE_SECOND,0) !=0 then { Alert("TREND CHANGE *** Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), PRICEASK, Slippage, yellow); Exit; }; }; }; }; };