/*[[ Name := Turtle-TR Author := Bill Godfrey-/-greybeard_xlx@yahoo.com modified by TR (TR_n00btrader@frisurf.no) Link := http://finance.groups.yahoo.com/group/MetaTrader_Experts_and_Indicators/ Lots := 1.00 Stop Loss := 80 Take Profit := 300 Trailing Stop := 0 ]]*/ Defines: SarStepA(0.02), SarStepB(0.02), TSmultiplier(6), BB(85), Dev(2), Shift(2), risk(10), mm(0), slip(10); var: mode(0), Ilo(0), cnt(0), b(0), R(0), orders(0), sym(0), SignalMode(""), PositionAlreadyOpen(False); //Uncomment and edit the below lines to limit backtesting period if year < 2004 then exit; if month < 5 then exit; If year=2004 and month>5 then { if TotalTrades <>0 then { For cnt=1 to TotalTrades Begin If OrderValue(cnt,VAL_SYMBOL)=Symbol then CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,50,WHITE); End; } exit; }; If CurTime < LastTradeTime + 20 Then exit; If Bars 100 then { Ilo = 100; }; } else { Ilo = lots; }; if mm > 0 then { Ilo = ceil(Balance*Risk/10000)/10; If Ilo > 1 then { Ilo = ceil(Ilo); }; If Ilo < 1 then { Ilo = 1; }; If Ilo > 100 then { Ilo = 100; }; }; //== OPEN POSITION IF SIGNAL IS ACTIVE============== If SignalMode <> "" then { Switch SignalMode Begin Case "OPEN LONG": SignalMode = ""; SetOrder(OP_BUY,Ilo,ask,Slip,ask-StopLoss*point,ask+TakeProfit*Point,Lime); Exit; Case "OPEN SHORT": SignalMode = ""; SetOrder(OP_SELL,Ilo,bid,Slip,bid+StopLoss*point,bid-TakeProfit*Point,HotPink); Exit; Default: Alert("Unrecognised SignalMode set"); End; }; //== ENTRY POINT ============================================================== if ((iSAR(SarStepA,0.2,6)>O[6] & iSAR(SarStepA,0.2,0)O[6] & iSAR(SarStepB,0.2,0)0 then { For cnt=1 to TotalTrades Begin If OrderValue(cnt,VAL_TYPE)=OP_SELL & OrderValue(cnt,VAL_SYMBOL)=Symbol then { CloseOrder( OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS), Ask, Slip, WHITE); SignalMode = "OPEN LONG"; exit; }; If OrderValue(cnt,VAL_TYPE)=OP_BUY & OrderValue(cnt,VAL_SYMBOL)=Symbol then PositionAlreadyOpen=True; End; } If PositionAlreadyOpen=False then SignalMode = "OPEN LONG"; }; if ((iSAR(SarStepA,0.2,6)O[0]) OR (iSAR(SarStepB,0.2,6)O[0])) & (iMAEx(1,MODE_SMA,0,PRICE_High,0) > iBandsEx(BB,Dev,Shift,PRICE_MEDIAN,MODE_HIGH,2) OR iMAEx(1,MODE_SMA,0,PRICE_High,0) > iBandsEx(BB+5,Dev,Shift,PRICE_MEDIAN,MODE_HIGH,2) OR iMAEx(1,MODE_SMA,0,PRICE_High,0) > iBandsEx(BB-5,Dev,Shift,PRICE_MEDIAN,MODE_HIGH,2)) then { PositionAlreadyOpen=False; if TotalTrades <>0 then { For cnt=1 to TotalTrades Begin If OrderValue(cnt,VAL_TYPE)=OP_BUY & OrderValue(cnt,VAL_SYMBOL)=Symbol then { CloseOrder( OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS), Ask, Slip, WHITE); SignalMode = "OPEN SHORT"; exit; }; If OrderValue(cnt,VAL_TYPE)=OP_SELL & OrderValue(cnt,VAL_SYMBOL)=Symbol then PositionAlreadyOpen=True; End; } If PositionAlreadyOpen=False then SignalMode = "OPEN SHORT"; }; /********************************************Order Control***************************************/ b = iatr(4,0)*TSmultiplier; For cnt=1 to TotalTrades Begin If OrderValue(cnt,VAL_TYPE)=OP_BUY & OrderValue(cnt,VAL_SYMBOL)=Symbol then { // TRAILING STOP ON BUY ORDER 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), LimeGREEN); Exit; }; }; }; If OrderValue(cnt,VAL_TYPE)=OP_SELL & OrderValue(cnt,VAL_SYMBOL)=Symbol then { //TRAILING STOP ON SELL ORDER If (OrderValue(cnt,VAL_OPENPRICE)-Ask)>(b) then { If OrderValue(cnt,VAL_STOPLOSS)>(Ask+b) then { ModifyOrder( OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_OPENPRICE), Ask+b, OrderValue(cnt,VAL_TAKEPROFIT), Yellow); Exit; }; }; }; End;