/*[[ Name := 9-18-EMA Author := FAB4X c 2005 Link := Notes := RUN A 1 hr CHART. Lots := 1.00 Stop Loss :=0 Take Profit := 65 Trailing Stop := 0 ]]*/ ///////////////////////////////////////////////////// // Defines ///////////////////////////////////////////////////// Defines: Slippage(3); // Slippage Defines: TradesPerCurrency(1), BreakEvenSL(11); // Number of lots to trade DEFINES: StopYear(2005), StopMonth(1); DEFINES: Start_Time(15), End_Time(20); Defines: OrderKillInSeconds(1800); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: OpenSell(0); // Sell Trades Counter var: OpenBuy(0); // Buy Trades Counter var: BuyOrders(0); var: SellOrders(0); var: OpenTrades(0); // Sell and Buy Counters var: PriceOpen(0); // Price Open var: I(0),vTime(0); // Misc Counter var: Mode(0),TS(0),TS1(0); // Squirl the Mode variable for multiple use ///////////////////////////////////////////////// // Main Script Conditions ///////////////////////////////////////////////// If Curtime - LastTradeTime < 10 then Exit; If FreeMargin < 500 then Exit; if year < StopYear then exit; if month < StopMonth and year <> 2005 then exit; //If (DayOfWeek <2 or DayOfWeek >6 or hour < Start_Time or hour > End_Time) then exit; //If Hour < 7 Or Hour > 20 then Exit;// about 0600 till 1500 GMT? ///////////////////////////////////////////////////// // Calculations / Setting Values ///////////////////////////////////////////////////// OpenSell = 0; OpenBuy = 0; BuyOrders = 0; SellOrders = 0; OpenTrades = 0; for I = 1 to TotalTrades { Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == Symbol then { //Calculates how many Sell we have for the current Symbol if Mode == OP_SELL then { OpenSell++; }; //Calculates how many Buy we have for the current Symbol if Mode == OP_BUY then { OpenBuy++; }; If mode == OP_SELLSTOP or mode == OP_SELLLIMIT then { SellOrders++; }; If mode == OP_BUYSTOP or mode == OP_BUYLIMIT then { BuyOrders++; }; OpenTrades++; }; }; If CurTime - LastTradeTime < 3600 and OpenTrades > 1 then Exit; ///////////////////////////////////////////////// // CUSTOM INDICATORS ///////////////////////////////////////////////// TS=iSAR(0.02,0.2,0); TS1=iSAR(0.02,0.2,1); ///////////////////////////////////////////////// // Long/Short Entry and Re-entry Trades ///////////////////////////////////////////////// If OpenBuy < TradesPerCurrency then { if vTime != Time[0] then { IF iMA(18, MODE_EMA, 1)< iMA(9, MODE_EMA, 1) THEN { //Alert(Symbol, " BUY ALERT. Buy at ", PRICEASK , " or better."); comment(" TREND NOW LONG "); SetOrder(OP_BUYSTOP, Lots,ASK+25*POINT, Slippage,TS ,ASK +TakeProfit * Point , BLUE); vTime = Time[0]; Exit; }; }; }; If OpenSell < TradesPerCurrency then { if vTime != Time[0] then { IF iMA(18, MODE_EMA, 1) > iMA(9, MODE_EMA, 1) THEN { //Alert(Symbol, " SELL ALERT. Sell at ", PRICEBID , " or better."); comment(" TREND NOW SHORT " ); SetOrder(OP_SELLSTOP, Lots,BID-25*POINT, Slippage,TS,BID-TakeProfit * Point, RED); vTime = Time[0]; Exit; }; }; }; ///////////////////////////////////////////////// // Trade Management ///////////////////////////////////////////////// for I = 1 to TotalTrades { Mode = ord(I, VAL_TYPE); if ord(I, VAL_SYMBOL) == 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 { if mode == OP_BUYSTOP and iMA(18, MODE_EMA, 0) < iMA(9, MODE_EMA, 0) or mode == OP_SELLSTOP and iMA(18, MODE_EMA, 0) > iMA(9, MODE_EMA, 0) 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(I, VAL_OPENTIME)) > OrderKillInSeconds then { DeleteOrder(OrderValue(I, VAL_TICKET), RED); exit; }; }; }; If OpenBuy > 0 then { comment("Profit $ ",ord(I, VAL_PROFIT)); if iMA(18,MODE_EMA,0) > iMA(9,MODE_EMA,0) then { Alert("TREND CHANGE *** Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), PRICEBID, Slippage, Orange); Exit; }; // If 10 pips profit, move Stop to BreakEven if PRICEBID - ord(I, VAL_OPENPRICE) >= BreakEvenSL * Point and ord(I, VAL_STOPLOSS) < ord(I, VAL_OPENPRICE)) then { ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), ord(I, VAL_OPENPRICE), ord(I, VAL_TAKEPROFIT), Cyan); Exit; }; // PSAR Stop...MOVING TRAILING STOP if TS > TS1 and ord(I, VAL_STOPLOSS) != TS and (Bid - TS) and (TS < Bid) then { ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), TS, ord(I, VAL_TAKEPROFIT), BlueViolet); Exit; }; //Automatic Trailing Stop If (Bid - Ord(I, VAL_OPENPRICE)) > (TrailingStop * Point) then { If Ord(I, VAL_STOPLOSS) < (Bid - TrailingStop * Point) then { ModifyOrder(Ord(I, VAL_TICKET), Ord(I, VAL_OPENPRICE), Bid - TrailingStop * Point, Ord(I, VAL_TAKEPROFIT), Red); Exit; }; }; // NOT SURE WHY YOU HAVE THESE LINES If Ord(I,VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(I,VAL_TICKET),Ord(I,VAL_OPENPRICE), Ord(I,VAL_OPENPRICE)-StopLoss*Point,Ord(I,VAL_OPENPRICE)+TakeProfit*Point,Red); Exit; }; }; If OpenSell > 0 then { comment("Profit $ ",ord(I, VAL_PROFIT)); if iMA(18,MODE_EMA,0) < iMA(9,MODE_EMA,0) then { Alert("TREND CHANGE *** Closing order at market for " + Symbol + " on " + Period + " Period."); CloseOrder(ord(I, VAL_TICKET), ord(I, VAL_LOTS), PRICEASK, Slippage, Orange); Exit; }; // If 10 pips profit, move Stop to BreakEven if ord(I, VAL_OPENPRICE) - PRICEASK >= BreakEvenSL * Point and ord(I, VAL_STOPLOSS) > ord(I, VAL_OPENPRICE)) then { ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), ord(I, VAL_OPENPRICE), ord(I, VAL_TAKEPROFIT), Cyan); Exit; }; // Psar Stop...MOVING TRAILING STOP if (TS < TS1) and (ord(i, VAL_STOPLOSS) != TS) and (TS - Ask ) and (TS > Ask) then { ModifyOrder(ord(I, VAL_TICKET), ord(I, VAL_OPENPRICE), TS , ord(I, VAL_TAKEPROFIT), BlueViolet); Exit; }; //Automatic Trailing Stop If (Ord(I, VAL_OPENPRICE) - Ask) > (TrailingStop * Point) then { If Ord(I, VAL_STOPLOSS) > (Ask + TrailingStop * Point) or Ord(I, VAL_STOPLOSS) = 0 then { ModifyOrder(Ord(I, VAL_TICKET), Ord(I, VAL_OPENPRICE), Ask + TrailingStop * Point, Ord(I, VAL_TAKEPROFIT), Red); Exit; }; }; // NOT SURE WHY YOU HAVE THESE LINES If Ord(I, VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(I,VAL_TICKET),Ord(I,VAL_OPENPRICE), Ord(I,VAL_OPENPRICE)+StopLoss*Point,Ord(I,VAL_OPENPRICE)-TakeProfit*Point,Red); Exit; }; }; }; };