/*[[ Name := AdaptTS Notes := eur/usd m15 Lots := 1 Stop Loss := 0 Take Profit := 70 Trailing Stop := 0 ]]*/ defines: YY(2004),MM(1),DD(01),HH(00),//year, month, day, hour - the beginning of the checking Timer(600), //inteval between the modifications PerTS(10),//period ATR for calculation TS/SL Kts(7.5), //ATR for calculating the level TS/SL risk(13), //% risk from available capital MiniForex(1), Slippage(5); var: lotsi(0),Stoplos(0),Bal(0),i(0), HD(0),LD(0),DolPunkt(0),PrBuy(0); if TimeYear(time) < YY then exit; if TimeMonth(time) < MM and TimeYear(time) = YY then exit; if TimeDay(time) < DD and TimeMonth(time) = MM and TimeYear(time) = YY then exit; if TimeHour(time) < HH and TimeDay(time) = DD and TimeMonth(time) = MM and TimeYear(time) = YY then exit; if TotalTrades>0 and Ord(1,VAL_TYPE)=OP_BUY Then PrBuy=1; if TotalTrades>0 and Ord(1,VAL_TYPE)=OP_SELL Then PrBuy=0; HD=0; LD=0; for i=1 to PerTS //StopLoss & TralingStop { HD+=H[i-1]; LD+=L[i-1]; }; StopLos=Kts*sqrt((HD-LD)/PerTS/Point)*Point ; switch Symbol begin case "EURUSD" : DolPunkt = 10; case "GBPUSD" : DolPunkt = 7; end; if CurTime>LastTradeTime+10 then { if TotalTrades<1 then { if risk<>0 then lotsi=Normalize(Balance*risk/100/DolPunkt/StopLos*Point,1) else lotsi=Lots; if lotsi > 10 then lotsi=Floor(lotsi); if lotsi<0.1 and MiniForex<>0 then lotsi=0.1; if lotsi<1 and MiniForex=0 then lotsi=1; Comment("lotsi - ",lotsi,"\n","\n","lotsi - ",lotsi,"\n","\n","Buy - ",Prbuy); if PrBuy=0 then {SetOrder(OP_BUY,lotsi,bid,Slippage,bid-StopLos,0,Lime); exit; }; if PrBuy=1 then {SetOrder(OP_SELL,lotsi,ask,Slippage,ask+StopLos,0,Blue); exit; }; }; }; If TotalTrades<1 or (CurTime-LastTradeTime)Ask+STOPLOS+10*Point or Ord(1,VAL_STOPLOSS)=0 then {ModifyOrder(Ord(1,VAL_TICKET),Ord(1,VAL_OPENPRICE), Ask+STOPLOS,0,Yellow); exit; }; };