/*[[ Name := Moneymaker Author := Forex Trade Corp. Notes := eur/usd m30 Lots := 1 Stop Loss := 30 Take Profit := 0 Trailing Stop := 25 ]]*/ //problems so far, EA waits about 15 min before setting stop, Stop is 36 pips not 20 as I want // If I close out trade EA automaticly SAR, there is no code for SAR // EA has no direction, needs a trend direction to be made to work for top performance defines: YY(2004),MM(1),DD(01),HH(00), K(7.5), Slippage(3), Risk(0); var: pb(0),pts(10),tm(600),ls(0),sl(0),i(0), HD(0),LD(0),cnt(0), EMA24_Prev1(0),SMA24_Prev1(0); var: candle_time(0); candle_time = Time; 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 TimeMonth(time) > 12 and TimeYear(time) >= 2004 then K=1; if TotalTrades>0 and Ord(1,VAL_TYPE)=OP_BUY Then pb=1; if TotalTrades>0 and Ord(1,VAL_TYPE)=OP_SELL Then pb=0; HD=0; LD=0; for i=1 to pts { HD+=H[i-1] and (SMA24_Prev1 < EMA24_Prev1); LD+=L[i-1] and (SMA24_Prev1 > EMA24_Prev1); }; sl=k*sqrt((HD-LD)/pts/Point)*Point ; if CurTime>LastTradeTime+10 then { if TotalTrades<1 then { if risk<>0 then ls=Normalize(Balance*risk/100/10/5/sl*Point,1) else ls=Lots; if ls > 10 then ls=Floor(ls); if ls<1 then ls=1; if pb=0 then {SetOrder(OP_BUY,ls,bid,5,0,0,Blue); }; if pb=1 then {SetOrder(OP_SELL,ls,ask,5,0,0,Red); }; }; }; If TotalTrades<1 or (CurTime-LastTradeTime)(TrailingStop*Point) then { // we have won already not less than 'TrailingStop' pips! If OrderValue(cnt,VAL_STOPLOSS)<(Bid-TrailingStop*Point) or OrderValue(cnt,VAL_STOPLOSS)=0 then { // move the trailing stop (Stop Loss) to the level 'TrailingStop' from the market ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Bid-Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Turquoise); }; If Ord(1,VAL_TYPE)=OP_SELL and OrderValue(1,VAL_SYMBOL)=Symbol then { If Ord(1,VAL_StopLoss)>Ask+sl+10*Point or Ord(1,VAL_StopLoss)=0 then {ModifyOrder(Ord(1,VAL_TICKET),Ord(1,VAL_OPENPRICE),Ask+sl,0,0); }; }; // we have won already not less than 'TrailingStop' pips! If OrderValue(cnt,VAL_STOPLOSS)>(Ask+TrailingStop*Point) or OrderValue(cnt,VAL_STOPLOSS)=0 then { // move the trailing stop (Stop Loss) to the level 'TrailingStop' from the market ModifyOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_OPENPRICE), Ask+Point*TrailingStop,OrderValue(cnt,VAL_TAKEPROFIT),Red); //Exit; }; candle_time = Time + 1; // if Stop Loss < Open Price then Set Takeprofit if OrderValue(cnt,VAL_STOPLOSS) <= OrderValue(cnt,VAL_OPENPRICE) then { ModifyOrder(OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_OPENPRICE), OrderValue(cnt,VAL_STOPLOSS), Bid - TakeProfit * Point, BLUE); If DayofWeek=6 and Hour >15 then { // Don't leave any open positions over the weekend. CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Bid,Slippage,Purple); Exit; }; }; };