/*[[ Name := 2Extreme4U - Double Take MA Author := 2Extreme4U Link := www.OmnicientTraders.com Lots := 1.00 Stop Loss := 49 Take Profit := 225 Trailing Stop := 69 ]]*/ ///////////////////////////////////////////////// // Notes ///////////////////////////////////////////////// /* Optimal Settings found with the expert when backtesting! GBPUSD Setup (Last Verified 06/10/2004): Time Frame = 30M Stop Loss = 49 Take Profit = 200 Trailing Stop = 49 OrderKillInSecond = 1800 Differential = 8 TrendMA = 51 PrimaryTarget = 41 EURUSD Setup (Last Verified 06/16/2004): Time Frame = 30M Stop Loss = 49 Take Profit = 225 Trailing Stop = 69 OrderKillInSecond = 1800 Differential = 8 TrendMA = 51 PrimaryTarget = 91 USDCAD Setup (Last Verified 06/10/2004): (THIS PAIR DOESNT WORK WELL IN LIVE TRADING) Time Frame = 30M Stop Loss = 69 Take Profit = 139 Trailing Stop = 41 OrderKillInSecond = 1800 Differential = 8 TrendMA = 54 PrimaryTarget = 41 USDJPY Setup (Last Verified 06/10/2004): Time Frame = 30M Stop Loss = 71 Take Profit = 300 Trailing Stop = 59 OrderKillInSecond = 2600 Differential = 9 TrendMA = 65 PrimaryTarget = 41 USDCHF Setup (Last Verified 06/10/2004): Time Frame = 30M Stop Loss = 39 Take Profit = 250 Trailing Stop = 59 OrderKillInSecond = 1800 Differential = 9 TrendMA = 55 PrimaryTarget = 59 USDAUD Setup (Last Verified 06/10/2004): Time Frame = 30M Stop Loss = 89 Take Profit = 119 Trailing Stop = 41 OrderKillInSecond = 1800 Differential = 8 TrendMA = 60 PrimaryTarget = 31 EURJPY Setup (Last Verified 06/22/2004): Time Frame = 30M Stop Loss = 71 Take Profit = 200 Trailing Stop = 59 OrderKillInSecond = 1800 Differential = 8 TrendMA = 65 PrimaryTarget = 81 *** IMPORTANT INFO *** In Live Trading, it is impossible to execute stop order at less than 8 PIPS differential... */ ///////////////////////////////////////////////// // Variable section ///////////////////////////////////////////////// DEFINES : FastMA(5), SlowMA(13), TrendMA(62); DEFINES : Slippage(10), Play%(15), MoneyManagement(0), PartialLots(0); DEFINES : PrimaryTarget(29), Differential(8), OrderKillInSeconds(1800); VAR : cnt(0), Mode(0), FXSymbol(""), ILO(0), I(0); VAR : SlowMAVal(0), SlowMAValPrev(0), FastMAVal(0), FastMAValPrev(0), TrendMAVal(0), TrendMAValPrev(0); VAR : IsAlreadyInPlay(False), OpenTrades(0), OpenOrders(0); ///////////////////////////////////////////////// // Main Script Conditions ///////////////////////////////////////////////// If Bars < 350 then Exit; if FreeMargin < 1000 then Exit; if Curtime - LastTradeTime < 10 then exit; ///////////////////////////////////////////////// // Money Management ///////////////////////////////////////////////// If MoneyManagement <> 0 then { ILO = ceil(equity*PLAY%/100/100)/10; IF PartialLots = 0 then { If Ilo < 1 then Ilo = 1; If Ilo > 1 then Ilo= ceil(ilo); } } else ILO = lots; ///////////////////////////////////////////////// // Calculation/Settings ///////////////////////////////////////////////// SlowMAVal = imaEx(SLOWMA, MODE_EMA, 0, PRICE_CLOSE, 0); SlowMAValPrev = imaEx(SLOWMA, MODE_EMA, 0, PRICE_CLOSE, 1); FastMAVal = imaEx(FASTMA, MODE_EMA, 0, PRICE_CLOSE, 0); FastMAValPrev = imaEx(FASTMA, MODE_EMA, 0, PRICE_CLOSE, 1); TrendMAVal = imaEx(TRENDMA, MODE_EMA, 0, PRICE_CLOSE, 0); TrendMAValPrev = imaEx(TRENDMA, MODE_EMA, 0, PRICE_CLOSE, 1); IsAlreadyInPlay = False; OpenTrades = 0; OpenOrders = 0; for cnt=1 to TotalTrades { FXSymbol = OrderValue(cnt, VAL_SYMBOL); Mode = OrderValue(cnt, VAL_TYPE); //Calculates how many trade we have for the current Symbol if FXSymbol == Symbol and (Mode == OP_SELL or Mode == OP_BUY) then { OpenTrades++; } //Calcule the number of pending orders for the Symbol if FXSymbol == Symbol and Mode <> OP_SELL and Mode <> OP_BUY then { OpenOrders++; } } if (OpenOrders == 2) or (OpenTrades == 2) or (OpenOrders == 1 and OpenTrades == 1) or (OpenOrders == 0 and OpenTrades == 1) then { IsAlreadyInPlay = True; } ///////////////////////////////////////////////// // Comment on the chart ///////////////////////////////////////////////// if IsAlreadyInPlay then { If OpenOrders == 2 then { Comment("In Play - Awaiting Entry Points"); } If OpenTrades == 2 Then { Comment("In Play - Signal Executed"); } If OpenOrders == 1 and OpenTrades == 1 then { Comment("In Play - Half Orders entered"); } If OpenOrders == 0 and OpenTrades == 1 then { Comment("In Play - Primary Target Met. Trailing Stop"); } } else { Comment("Not In Play"); } ///////////////////////////////////////////////// // Long/Short Trade Opening ///////////////////////////////////////////////// If OpenOrders < 2 and OpenTrades = 0 then { //We enter a trade if the bid price is lower than the trendMA... if TrendMAVal >= Bid and TrendMAValPrev < Close[1] then { SetOrder(OP_SELLSTOP, ILO, Bid - (Differential * Point), Slippage, Bid + (StopLoss * Point), Bid - (TakeProfit * Point), MediumVioletRed); Exit; } if TrendMAVal <= Ask and TrendMAValPrev > Close[1] then { SetOrder(OP_BUYSTOP, ILO, Ask + (Differential * Point), Slippage, Ask - (StopLoss * Point), Ask + (TakeProfit * Point), MediumPurple); Exit; } } ///////////////////////////////////////////////// // Trade Management ///////////////////////////////////////////////// for cnt=1 to TotalTrades { Mode = OrderValue(cnt, VAL_TYPE); FXSymbol = OrderValue(cnt, VAL_SYMBOL); if FXSymbol == Symbol then { // An OPEN order (Not executed) cannot be valid more than a defined period of time after which it should be canceled If Mode <> OP_SELL and Mode <> OP_BUY then { // check how long it exists in the trading terminal. Time is counted in seconds. // 10 minutes = 600 seconds, 30 minutes = 1800, 1 hour = 3600, 1 day = 86400 If (CurTime - OrderValue(cnt, VAL_OPENTIME)) > OrderKillInSeconds then { DeleteOrder(OrderValue(cnt, VAL_TICKET), RED); exit; } } //If we still have both orders opened. We need to check if primary target meets criteria if OpenTrades = 2 then { If Mode = OP_BUY then { //If Primary target is met, close half play and move stop to 0 for other lot. if (Bid - OrderValue(cnt, VAL_OPENPRICE)) >= PrimaryTarget * Point then { Alert("Primary Target met. BID = " + Bid + ". Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(OrderValue(cnt, VAL_TICKET), OrderValue(cnt, VAL_LOTS), Bid, Slippage, Orange); exit; } } If Mode = OP_SELL then { //If Primary target is met, close half play and move stop to 0 for other lot. if (OrderValue(cnt, VAL_OPENPRICE) - Ask) >= PrimaryTarget * Point then { Alert("Primary Target met. Ask = " + Ask + ". Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(OrderValue(cnt, VAL_TICKET), OrderValue(cnt, VAL_LOTS), Ask, Slippage, PowderBlue); exit; } } } else { //Automatic Trailing Stop If Ord(cnt, VAL_TYPE) = OP_BUY then { If (Bid - Ord(cnt, VAL_OPENPRICE)) > (TrailingStop * Point) then { If Ord(cnt, VAL_STOPLOSS) < (Bid - TrailingStop * Point) then { ModifyOrder(Ord(cnt, VAL_TICKET), Ord(cnt, VAL_OPENPRICE), Bid - TrailingStop * Point, Ord(cnt, VAL_TAKEPROFIT), BLUE); Exit; } } } //Automatic Trailing Stop If Ord(cnt, VAL_TYPE) = OP_SELL then { If (Ord(cnt, VAL_OPENPRICE) - Ask) > (TrailingStop * Point) then { If Ord(cnt, VAL_STOPLOSS) > (Ask + TrailingStop * Point) or Ord(cnt, VAL_STOPLOSS) = 0 then { ModifyOrder(Ord(cnt, VAL_TICKET), Ord(cnt, VAL_OPENPRICE), Ask + TrailingStop * Point, Ord(cnt, VAL_TAKEPROFIT), Red); Exit; } } } } } };