/*[[ Name := EZpipsTR autotrade Author := TR (TR_n00btrader@frisurf.no). Based on Soul_trader2004's EZ pips system (http://www.moneytec.com/forums/showthread.php?s=&threadid=11598&perpage=8&pagenumber=1) Link := Lots := 0.10 Stop Loss := 20 Take Profit := 10 Trailing Stop := 999 ]]*/ Defines: slippage(3), moneym(0), risk(2); Variable: cnt(0), sym(0), mode(0), lotsa(0), enup(0), endown(0); Variable: stom(0), LastCheckedBarTime(0), Opentrades(0), enup1(0), endown1(0),RSI(0); Variable: enup2(0), endown2(0), enup3(0), endown3(0),CL(0),CL1(0), slb(0), sls(0),TriggerPrice(0); Variable: ExpertMode(""); Var: EntryOrderTicket(0), PositionOpen(False), LastBarWithPosOpen(0), LastOpenPositionTP(0), LastOpenPositionSL(0), EntryHitBar(0), Straddles(0), OpenBarHitSL(0); /* If year<>2004 then exit; if month<10 then exit; If month=10 and day < 27 then exit; if month=11 and day > 10 then exit; */ If CurTime < LastTradeTime + 20 Then exit; //------------------------------------- If moneym <> 0 then { lotsa = ceil(Balance*Risk/10000)/10; If lotsa > 100 then { lotsa = 100; } } Else { lotsa = lots; }; if IsTesting then { EntryOrderTicket = 0; PositionOpen = False; For cnt=1 to TotalTrades Begin If (OrderValue(cnt,VAL_TYPE)=OP_BUYSTOP OR OrderValue(cnt,VAL_TYPE)=OP_SELLSTOP) AND OrderValue(cnt,VAL_SYMBOL)=Symbol then EntryOrderTicket = OrderValue(cnt,VAL_TICKET); If (OrderValue(cnt,VAL_TYPE)=OP_BUY OR OrderValue(cnt,VAL_TYPE)=OP_SELL) AND OrderValue(cnt,VAL_SYMBOL)=Symbol then { PositionOpen = True; LastOpenPositionTP=OrderValue(cnt,VAL_TAKEPROFIT); LastOpenPositionSL=OrderValue(cnt,VAL_STOPLOSS); }; End; if PositionOpen = True then { LastBarWithPosOpen=time[0]; If EntryHitBar=0 then EntryHitBar=time[0] Else If EntryHitBar=time[1] then //If position opened in previous bar (and still open) { If LastOpenPositionTP>LastOpenPositionSL then { If l[1]-point*5 <= LastOpenPositionSL then //If bar where position was opened reached SL { OpenBarHitSL++; Alert("Straddles: ",Straddles," OpenBarHitSL: ",OpenBarHitSL); }; } Else { If h[1]+point*5 >= LastOpenPositionSL then { OpenBarHitSL++; Alert("Straddles: ",Straddles," OpenBarHitSL: ",OpenBarHitSL); }; } EntryHitBar=1; //Just so that it's ignored until position is closed and EntryHitBar is reset to 0 below }; } Else If LastBarWithPosOpen = time[1] then { If LastOpenPositionTP>LastOpenPositionSL then { If h[1]+point*5 >= LastOpenPositionTP and l[1]-point*5 <= LastOpenPositionSL then //If bar where position was closed reached both SL and TP { Straddles++; Alert("Straddles: ",Straddles," OpenBarHitSL: ",OpenBarHitSL); }; } Else { If h[1]+point*5 >= LastOpenPositionSL and l[1]-point*5 <= LastOpenPositionTP then { Straddles++; Alert("Straddles: ",Straddles," OpenBarHitSL: ",OpenBarHitSL); }; } LastBarWithPosOpen=0; EntryHitBar=0; }; }; //------------------------------------- Opentrades=0; For cnt=1 to TotalTrades Begin If OrderValue(cnt,Val_Symbol)=Symbol then { Opentrades=Opentrades+1; }; End; //------------------------------------- //Keep these here as they are also used by the closing-positions section! enup1 = iBandsEx(20,2,0,PRICE_CLOSE,MODE_HIGH,1); endown1= iBandsEx(20,2,0,PRICE_CLOSE,MODE_LOW,1); CL1 = iBandsEx(20,2,0,PRICE_CLOSE,MODE_MAIN,1); //CL1 = ima(21,MODE_SMA,1); If LastCheckedBarTime < Time[1] then ExpertMode=""; //Ensures that if the gimme bar is not exceeded by the following bar, no trade taken If ExpertMode="" and Opentrades=0 and LastCheckedBarTime < Time[1] then { //alert(curtime); LastCheckedBarTime = Time[1]; //If Hour>=7 and hour<=19 then If 1=1 then //Yes, it will always be...but this is just here so we can easily enable/disable the above hour check for testing { enup2= iBandsEx(20,2,0,PRICE_CLOSE,MODE_HIGH,2); endown2= iBandsEx(20,2,0,PRICE_CLOSE,MODE_LOW,2); If (C[1]>O[1] AND L[1] <= endown1 AND H[1] >= endown1) OR (C[1]>O[1] AND C[2]= endown2) THEN { If Abs(enup1-endown1 - (iBandsEx(20,2,0,PRICE_CLOSE,MODE_HIGH,6)-iBandsEx(20,2,0,PRICE_CLOSE,MODE_LOW,6))) < point*3 then { // If irsi(9,1)<=30 then //Don't check this indicator until really necessary, very slow for backtest // { TriggerPrice=H[1]+point*1; If CL1-TriggerPrice>=point*5 then ExpertMode="PotentialBuy"; // //Setorder(op_buy,lots,ask,slippage,slb,ask+takeprofit*Point,red); // }; }; }; If (C[1]= enup1 AND L[1] <= enup1) OR (C[1]O[2] AND H[2] >= enup2 AND L[2] <= enup2) THEN { If Abs(enup1-endown1 - (iBandsEx(20,2,0,PRICE_CLOSE,MODE_HIGH,6)-iBandsEx(20,2,0,PRICE_CLOSE,MODE_LOW,6))) < point*3 then { // If irsi(9,1)>=70 then //Don't check this indicator until really necessary, very slow for backtest // { TriggerPrice=L[1]-point*1; If TriggerPrice-CL1>=point*5 then ExpertMode="PotentialSell"; //SetOrder(OP_SELL,lots,bid,slippage,sls,bid-TakeProfit*Point,blue); // }; }; }; }; }; Switch ExpertMode Begin Case "PotentialBuy": //Alert("here"); If CL <= TriggerPrice then { ExpertMode=Expertmode; //Just so the below doesn't cause empty expression error //ExpertMode=""; //If SMA/CL touches triggerprice, fuggetabout the signal. This also helps avoid trends. //Exit; }; If ask-point*2 >= Triggerprice then { //ExpertMode="NoNewSignalsTillTouchesCL"; ExpertMode=""; Setorder(op_sell,lots,bid,slippage,bid+point*StopLoss+point*6,bid-takeprofit*Point+point*6,red); exit; }; Case "PotentialSell": If CL >= TriggerPrice then { ExpertMode=Expertmode; //Just so the below doesn't cause empty expression error //ExpertMode=""; //If SMA/CL touches triggerprice, fuggetabout the signal. This also helps avoid trends. //Exit; }; If bid+point*1 >= Triggerprice then { //ExpertMode="NoNewSignalsTillTouchesCL"; ExpertMode=""; Setorder(op_buy,lots,ask,slippage,ask-point*StopLoss-point*5,ask+takeprofit*Point-point*5,red); exit; }; Case "NoNewSignalsTillTouchesCL": If L[0]<=CL and H[0]>=CL then ExpertMode=""; Default: If ExpertMode <> "" then Alert("Unrecognised ExpertMode!"); end; //----------------------------------------------- /* for cnt=1 to TotalTrades { If ord(cnt,VAL_SYMBOL)=Symbol then { If ord(cnt,VAL_TYPE)=OP_BUY then { If ask-point*1>=enup then //If ask-point*2>=CL then { LastOpenPositionTP=bid; CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),bid,slippage,pink); Exit; }; }; If ord(cnt,val_type)=OP_SELL then { If bid+point*1<=endown then //If bid+point*2<=CL then { CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),Ask,slippage,LightBlue); Exit; }; }; }; }; sym=0; For cnt=1 to TotalTrades begin If Ord(cnt,Val_Symbol)=Symbol then { sym=cnt; mode=Ord(sym,VAL_TYPE); If mode=OP_BUY then { If Ord(sym,VAL_STOPLOSS)<(Bid-TrailingStop*Point) then { ModifyOrder( Ord(sym,VAL_TICKET), Ord(sym,VAL_OPENPRICE), Bid-TrailingStop*Point, Ord(sym,VAL_TAKEPROFIT), LimeGreen); Exit; }; }; If mode=OP_SELL then { If Ord(sym,VAL_STOPLOSS)>(Ask+TrailingStop*Point) then { ModifyOrder( Ord(sym,VAL_TICKET), Ord(sym,VAL_OPENPRICE), Ask+TrailingStop*Point, Ord(sym,VAL_TAKEPROFIT), HotPink); Exit; }; } }; End; //----------------------------------------------- //exit; /* for cnt=1 to TotalTrades { If ord(cnt,VAL_SYMBOL)=Symbol then { If ord(cnt,VAL_TYPE)=OP_BUY then { If ask-point*1>=CL then { //CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),bid,slippage,pink); slb=OrderValue(1,VAL_OPENPRICE)+point*1; If slb > bid-point*7 then slb=bid-point*7; if slb>OrderValue(1,VAL_STOPLOSS) then { ModifyOrder(ord(1,VAL_TICKET),OrderValue(1,VAL_OPENPRICE),slb,OrderValue(cnt,VAL_TAKEPROFIT),LimeGREEN); }; ////If OrderValue(1,VAL_STOPLOSS)<>slb then CloseOrder(ord(1,VAL_TICKET),ord(1,VAL_LOTS),ask,slippage,pink); //Break; }; }; If ord(cnt,val_type)=OP_SELL then { If bid+point*1<=CL then { //CloseOrder(ord(cnt,VAL_TICKET),ord(cnt,VAL_LOTS),ask,slippage,LightBlue); sls=OrderValue(1,VAL_OPENPRICE)-point*1; If sls < ask+point*7 then sls=ask+point*7; if slssls then CloseOrder(ord(1,VAL_TICKET),ord(1,VAL_LOTS),ask,slippage,pink); //Break; }; }; }; };