/*[[ Name := LongTrend (GoldenGoose) Author := Copyright © 2004, Amir Modified by:= Amir Link := Lots := 1.00 Stop Loss := 30 Take Profit := 100 Trailing Stop := 50 ]]*/ /* Revision logs: 6 March 2005: Autofx - Pyramiding added, external trailing stop control added, modified cosmetics to taste, gave alernate name "GoldenGoose" */ define: Autotrade(1),Margincutoff(2000),mm(1),Risk(5); var: cnt(0), Current(0),TradesInThisSymbol(0); var: OrderText(""); var: Autst(0); var: lotMM(0); var: ts(0); var: LiveTrading(False); var: AccountIsMini(False); // See comments near assignment statement below. ts = TrailingStop*Point; // ==================================================================================================== // DATE CHOKE - for testing // ==================================================================================================== if TimeYear(time[0]) < 2004 then Exit; // ==================================================================================================== // PYRAMIDING - LINEAR // Money management risk exposure compounding // ==================================================================================================== LiveTrading = False; AccountIsMini = False; // Change to False for real trading w/ 100k/regular account // or for all backtesting, since backtests allow // fractional lots. // Change to True for real trading w/ mini account if mm <> 0 then { lotMM = Ceil(Balance * risk / 10000) / 10; if lotMM < 0.1 then lotMM = Lots; if lotMM > 1.0 then lotMM = Ceil(lotMM); // Enforce lot size boundaries if LiveTrading then { if AccountIsMini then lotMM = lotMM * 10; if !AccountIsMini and lotMM < 1.0 then lotMM = 1.0; } if lotMM > 100 then lotMM = 100; } else { lotMM = Lots; // Change mm to 0 if you want the Lots parameter to be in effect }; // ==================================================================================================== // ORDER CLOSURES and MODIFICATIONS // ==================================================================================================== TradesInThisSymbol = 0; for cnt = 1 to TotalTrades begin if Ord(cnt,VAL_TYPE) = OP_BUY and OrderValue(cnt,VAL_SYMBOL) = Symbol then { TradesInThisSymbol += 1; if iCustom("I_XO_A_H",MODE_SECOND,0) < 0 and iCustom("I_XO_A_H",MODE_FIRST,0) == 0 and iWPR(14,0) < iWPR(14,1) and iCustom("itrend",MODE_SECOND,0) < 0 then { CloseOrder(OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS),Bid,3,Violet); Exit; } if (hour == 23) then { CloseOrder(OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS),Ask,3,Violet); Exit; } if Bid - Ord(cnt,VAL_OPENPRICE) > ts and Ord(cnt,VAL_STOPLOSS) < Bid - ts then { ModifyOrder(Ord(cnt,VAL_TICKET), Ord(cnt,VAL_OPENPRICE), Bid - ts, Ord(cnt,VAL_TAKEPROFIT), Red); Exit; } } if Ord(cnt,VAL_TYPE) = OP_SELL and OrderValue(cnt,VAL_SYMBOL) = Symbol then { TradesInThisSymbol += 1; if iCustom("I_XO_A_H",MODE_FIRST,0) > 0 and iCustom("I_XO_A_H",MODE_SECOND,0) == 0 and iWPR(14,0) > iWPR(14,1) and iCustom("itrend",MODE_FIRST,0) > 0 then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); Exit; } if (hour == 23) then { CloseOrder(OrderValue(cnt,VAL_TICKET),OrderValue(cnt,VAL_LOTS),Ask,3,Violet); Exit; } if Ord(cnt,VAL_OPENPRICE) - Ask > ts and Ord(cnt,VAL_STOPLOSS) > Ask + ts then { ModifyOrder(Ord(cnt,VAL_TICKET), Ord(cnt,VAL_OPENPRICE), Ask + ts, Ord(cnt,VAL_TAKEPROFIT), Red); Exit; } } end; // ==================================================================================================== // MARKET ORDERS // ==================================================================================================== if FreeMargin < Margincutoff then Exit; if TradesInThisSymbol > 0 then Exit; OrderText = ""; //Must be blank before going into the main section if (hour == 23) then { if (Autotrade == 0) then { Autst = 1; } else { Autst = 0; } } // Is current bar a bull candle? if (iWPR(14,0) > iWPR(14,1) and iCustom("I_XO_A_H",MODE_FIRST,0) > 0) or (iWPR(14,0) > iWPR(14,1) and iCustom("itrend",MODE_FIRST,0) > 0) then { OrderText = "BUY"; } // Is current bar a bear candle? if (iWPR(14,0) < iWPR(14,1) and iCustom("I_XO_A_H",MODE_SECOND,0) < 0) or (iWPR(14,0) < iWPR(14,1) and iCustom("itrend",MODE_SECOND,0) < 0) then { OrderText = "SELL"; } if (OrderText <> "" and TotalTrades < 3 and TradesInThisSymbol == 0 and hour > 0 and hour < 23 and Autst == 0) then { Switch OrderText Begin Case "BUY": SetArrow(time, ask, 216, yellow); SetOrder(OP_BUY, lotMM, Ask, 3, Ask - StopLoss*Point, Ask + TakeProfit*Point, Green); Exit; Case "SELL": SetArrow(time, bid, 216, red); SetOrder(OP_SELL, lotMM, Bid, 3, Bid + StopLoss*Point, Bid - TakeProfit*Point, Red); Exit; Default: Exit; End; }