/*[[ Name := Multi Lot Scapler Author := Copyright © 2005 Alejandro Galindo Link := http://elCactus.com Lots := 0.10 Stop Loss := 0 Take Profit := 10 Trailing Stop := 20 ]]*/ Define: MaxTrades(5); Define: Pips(4); Define: SecureProfit(10); Define: AccountProtection(1); Define: OrderstoProtect(3); Define: ReverseCondition(0); Define: EURUSDPipValue(10); Define: GBPUSDPipValue(10); Define: USDCHFPipValue(7.94); Define: USDJPYPipValue(9.03); //Define: ReduceProfit(1); // if cero or one the profit target will be the same // >1 then the profit for last 3 orders will be reduced to Profit/ReduceProfit Define: StartYear(2006); Define: StartMonth(1); Define: EndYear(2006); Define: EndMonth(12); Define: EndHour(22); Define: EndMinute(30); //Define: EndDayofWeek(7); Define: mm(0); Define: risk(12); Define: AccountisNormal(0); Var: OpenOrders(0), cnt(0); Var: slippage(5); Var: sl(0), tp(0); Var: BuyPrice(0), SellPrice(0); Var: lotsi(0), mylotsi(0); Var: mode(0), OrderType(0); Var: ContinueOpening(True); Var: LastPrice(0); Var: PreviousOpenOrders(0); Var: Profit(0); Var: LastTicket(0), LastType(0), LastClosePrice(0), LastLots(0); Var: Pivot(0); Var: PipValue(0); Var: Reversed(False); Var: text(""); Var: text2(""); if AccountisNormal==1 then { if mm<>0 then lotsi=Ceil(Balance*risk/10000) else lotsi=Lots; } else { // then is mini if mm<>0 then lotsi=Ceil(Balance*risk/10000)/10 else lotsi=Lots; }; if lotsi>100 then lotsi=100; OpenOrders=0; For cnt=1 to TotalTrades { If Ord(cnt,Val_Symbol)==Symbol then { OpenOrders++; }; }; if (OpenOrders<1) then { If TimeYear(time)EndYear then Exit; If TimeMonth(Time)>EndMonth then Exit; }; Switch Symbol() Begin Case "EURUSD": PipValue=EURUSDPipValue; Case "GBPUSD": PipValue=GBPUSDPipValue; Case "USDJPY": PipValue=USDJPYPipValue; Case "USDCHF": PipValue=USDCHFPipValue; Default: PipValue=5.00; End; if PreviousOpenOrders>OpenOrders then { For cnt=TotalTrades Downto 1 { mode=Ord(cnt,VAL_TYPE); if (Ord(cnt,VAL_SYMBOL)==Symbol) then { if (mode==OP_BUY) then CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),ord(cnt,VAL_CLOSEPRICE),Slippage,Blue); if (mode==OP_SELL) then CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),ord(cnt,VAL_CLOSEPRICE),Slippage,Red); Exit; }; }; }; PreviousOpenOrders=OpenOrders; if (OpenOrders>=MaxTrades) then { ContinueOpening=False; } else { ContinueOpening=True; }; if (LastPrice==0) then { for cnt=1 to TotalTrades { mode=Ord(cnt,VAL_TYPE); if (Ord(cnt,VAL_SYMBOL) == Symbol) then { LastPrice=Ord(cnt,VAL_OPENPRICE); if mode==OP_BUY then OrderType=2; if mode==OP_SELL then OrderType=1; }; }; }; if (OpenOrders<1) then { OrderType=0; }; if (OpenOrders>=1)and mode==OP_SELL then { OrderType=1; }; if (OpenOrders>=1)and mode==OP_BUY then { OrderType=2; }; // if we have opened positions we take care of them for cnt=TotalTrades Downto 1 { if OrderValue(cnt,VAL_SYMBOL) == Symbol and Reversed==False then { if OrderValue(cnt,VAL_TYPE) == OP_SELL then { If TrailingStop>0 then { If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>=TrailingStop*Point+Pips*Point then { if OrderValue(cnt,VAL_STOPLOSS)>(Ask+Point*TrailingStop) OR OrderValue(cnt,VAL_STOPLOSS)==0 then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Ask+Point*TrailingStop,OrderValue(cnt,VAL_CLOSEPRICE)-TakeProfit*Point-TrailingStop*Point,Purple); Exit; }; }; }; }; if OrderValue(cnt,VAL_TYPE) == OP_BUY then { If TrailingStop>0 then { If (Bid-OrderValue(cnt,VAL_OPENPRICE))>=TrailingStop*Point+Pips*Point then { If OrderValue(cnt,VAL_STOPLOSS)<(Bid-Point*TrailingStop) then { ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE),Bid-Point*TrailingStop,OrderValue(cnt,VAL_CLOSEPRICE)+TakeProfit*Point+TrailingStop*Point,Yellow); Exit; }; }; }; }; }; }; Profit=0; LastTicket=0; LastType=0; LastClosePrice=0; LastLots=0; For cnt=1 to TotalTrades { if (Ord(cnt,VAL_SYMBOL)==Symbol()) then { LastTicket=Ord(cnt,VAL_TICKET); if (Ord(cnt,VAL_TYPE)==OP_BUY) then LastType=OP_BUY; if (Ord(cnt,VAL_TYPE)==OP_SELL) then LastType=OP_SELL; LastClosePrice=Ord(cnt,VAL_CLOSEPRICE); LastLots=Ord(cnt,VAL_LOTS); if (LastType==OP_BUY) then { //Profit=Profit+(Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))*PipValue*Ord(cnt,VAL_LOTS); if (Ord(cnt,VAL_CLOSEPRICE)Ord(cnt,VAL_OPENPRICE)) then Profit=Profit+(Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))*Ord(cnt,VAL_LOTS)/Point; }; if (LastType==OP_SELL) then { //Profit=Profit+(Ord(cnt,VAL_OPENPRICE)-Ord(cnt,VAL_CLOSEPRICE))*PipValue*Ord(cnt,VAL_LOTS); if (Ord(cnt,VAL_CLOSEPRICE)>Ord(cnt,VAL_OPENPRICE)) then Profit=Profit-(Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))*Ord(cnt,VAL_LOTS)/Point; if (Ord(cnt,VAL_CLOSEPRICE)=(MaxTrades-OrderstoProtect) and AccountProtection==1) then { if OrderType=2 and bid == TP then { CloseOrder(LastTicket,LastLots,LastClosePrice,Slippage,Yellow); ContinueOpening=False; Exit; }; if OrderType=1 and ask == TP then { CloseOrder(LastTicket,LastLots,LastClosePrice,Slippage,Yellow); ContinueOpening=False; Exit; }; }; //if (!IsTesting) then //{ // if (OrderType==3) then text="No conditions to open trades" // else text=" "; comment("Account: ",AccNum," - ",AccName,"\nLastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,"\nContinue opening=",ContinueOpening," OrderType=",OrderType,"\n",text2 ," Balance: ",NumberToStr(Balance,2),"\nLots=",lotsi,"\n",text); //}; //if (Equity=Pips*Point) then { SellPrice=Bid; LastPrice=0; if TakeProfit==0 then tp=0 else tp=SellPrice-TakeProfit*Point; if StopLoss==0 then sl=0 else sl=SellPrice+StopLoss*Point; SetOrder(OP_SELL,mylotsi,SellPrice,Slippage,sl,tp,red); //SetArrow(CurTime, High + 10 * Point, 234, MediumVioletRed); Exit; }; }; if (OrderType==2 and ContinueOpening ) then { if ((LastPrice-Ask)>=Pips*Point) then { BuyPrice=Ask; LastPrice=0; if TakeProfit==0 then tp=0 else tp=BuyPrice+TakeProfit*Point; if StopLoss==0 then sl=0 else sl=BuyPrice-StopLoss*Point; SetOrder(OP_BUY,mylotsi,BuyPrice,Slippage,sl,tp,Blue); //SetArrow(CurTime, Low - 10 * Point, 233, MediumBlue); Exit; }; }; Exit;