/*[[ Name := 10points Author := Copyright © 2005 Alejandro Galindo Link := http://elCactus.com Notes := Lots := 0.10 Stop Loss := 0 Take Profit := 10 Trailing Stop := 5 ]]*/ Define: MaxTrades(5); Define: Pips(2); 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(2010); Define: EndMonth(12); Define: EndHour(22); Define: EndMinute(30); //Define: EndDayofWeek(7); Define: mm(0); Define: risk(12); Define: AccountisNormal(0); Define: TimeZoneofData(0); Var: OpenOrders(0), cnt(0); Var: slippage(2); 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(""); Var: myl(0); Var: myh(0); Var: myC(0); Var: myO(0); Var: mypivot(0); Var: Today(0); Var: RefDate(0); Var: LastBarOfDay(0); Var: FirstBarOfDay(0); Var: Loop(0); Var: myyh(0); Var: myyl(0); Var: myyc(0); Var: p(0); Var: flp(0); Var: feh(0); Var: fel(0); Var: ph(0); Var: pl(0); Var: gap(0); 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; }; myh = High[0]; myl = Low[0]; myC = Close[0]; myO = Open[0]; myyh = High[1]; myyl = Low[1]; myyc = Close[1]; p = (myyh + myyl + myyc + myO) / 4; ph = (myyh + myh + myyc + myO) / 4; pl = (myyl + myl + myyc + myO) / 4; flp = (myh + myl + myC) / 3; gap = Abs(p - flp) * 10000; MoveObject("P",OBJ_HLINE,Time[0],p,Time[0],p,Gold,1,STYLE_SOLID); SetObjectText("P_txt","Pivot Zone","Arial",7,White); MoveObject("P_txt",OBJ_TEXT,Time[0],p,Time[0],p,White); if Ask > p and Ask > flp then { MoveObject("FLP",OBJ_HLINE,Time[0],flp,Time[0],flp,LimeGreen,1,STYLE_SOLID); SetObjectText("FLP_txt","Floating Trend Direction - LONG","Arial",7,White); MoveObject("FLP_txt",OBJ_TEXT,Time[0],flp,Time[0],flp,White); 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,"Trend Bias -- LONG"); } if Bid < p and Bid < flp then { MoveObject("FLP",OBJ_HLINE,Time[0],flp,Time[0],flp,Red,1,STYLE_SOLID); SetObjectText("FLP_txt","Floating Trend Direction - SHORT","Arial",7,White); MoveObject("FLP_txt",OBJ_TEXT,Time[0],flp,Time[0],flp,White); 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,"Trend Bias -- SHORT"); } 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=3; //if (iMACD(14,26,9,MODE_MAIN,0)>0 and iMACD(14,26,9,MODE_MAIN,0)>iMACD(14,26,9,MODE_MAIN,1)) then OrderType=2; if (iMACD(14,26,9,MODE_MAIN,0)>iMACD(14,26,9,MODE_MAIN,1)) then OrderType=2; //if (iMACD(14,26,9,MODE_MAIN,0)<0 and iMACD(14,26,9,MODE_MAIN,0)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 (Profit>=SecureProfit) 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("LastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,"\nContinue opening=",ContinueOpening," OrderType=",OrderType,"\n",text2,"\nLots=",lotsi,"\n",text); }; //if (Equity=Pips*Point OR OpenOrders<1) 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; if OpenOrders<>0 then { mylotsi=lotsi; for cnt=1 to OpenOrders { if (MaxTrades>12) then mylotsi=Normalize(mylotsi*1.5,1) else mylotsi=Normalize(mylotsi*2,1); }; } else mylotsi=lotsi; if mylotsi>100 then mylotsi=100; 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 OR OpenOrders<1) 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; if OpenOrders<>0 then { mylotsi=lotsi; for cnt=1 to OpenOrders { if (MaxTrades>12) then mylotsi=Normalize(mylotsi*1.5,1) else mylotsi=Normalize(mylotsi*2,1); }; } else mylotsi=lotsi; if mylotsi>100 then mylotsi=100; SetOrder(OP_BUY,mylotsi,BuyPrice,Slippage,sl,tp,Blue); //SetArrow(CurTime, Low - 10 * Point, 233, MediumBlue); Exit; }; }; Exit;