/*[[ 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); ///////////////////////////////////////////////////// // Variables ///////////////////////////////////////////////////// var: OpenSell(0); // Sell Trades Counter var: OpenBuy(0); // Buy Trades Counter var: PriceOpen(0); // Price Open var: I(0),cnt(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? If CurTime-LastTradeTime>3600 and TotalTrades<1 then// Dont trade again till 1Hour after last Exit. { ///////////////////////////////////////////////////// // Calculations / Setting Values ///////////////////////////////////////////////////// OpenSell = 0; OpenBuy = 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++; }; }; }; ///////////////////////////////////////////////// // CUSTOM INDICATORS ///////////////////////////////////////////////// TS=iSAR(0.02,0.2,0); TS1=iSAR(0.02,0.2,1); ///////////////////////////////////////////////// // Comment on the chart ///////////////////////////////////////////////// ///////////////////////////////////////////////// // 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 { 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; }; If (Minute>58) then//if the current time ignoring hours is greater than 58minutes cancel the open order(allowing new one to place). { DeleteOrder(OrderValue(I,VAL_TICKET),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; }; If (Minute>58) then//if the current time ignoring hours is greater than 58minutes cancel the open order(allowing new one to place). { DeleteOrder(OrderValue(I,VAL_TICKET),RED); Exit; }; }; // }; }; ////////////////////////////////////////////////////////// /////////////////////////Trailing Stop Code ///////////////////// ////////////////////////////////////////////////////////// If TotalTrades > 0 then { for cnt = 1 to TotalTrades Begin If Ord(cnt,VAL_TYPE)=OP_BUY then { /////////////////// If Ord(cnt,VAL_SYMBOL)= Symbol then { If Ord(cnt,VAL_OPENPRICE) + TrailingStop*Point < Bid 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),Red); Exit; }; }; If Ord(cnt,VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Ord(cnt,VAL_OPENPRICE)-StopLoss*Point,Ord(cnt,VAL_OPENPRICE)+TakeProfit*Point,Red); Exit; }; }; };// End of BUY If Ord(cnt,VAL_TYPE)=OP_SELL then { /////////////////// If Ord(cnt,VAL_SYMBOL)= Symbol then { If Ord(cnt,VAL_OPENPRICE) - TrailingStop*Point > Ask Then { If Ord(cnt,VAL_STOPLOSS)>(Ask+TrailingStop*Point) then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE),Ask+TrailingStop*Point, Ord(cnt,VAL_TAKEPROFIT),White); Exit; }; }; If Ord(cnt,VAL_TAKEPROFIT) = 0 Then { ModifyOrder(Ord(cnt,VAL_TICKET),Ord(cnt,VAL_OPENPRICE), Ord(cnt,VAL_OPENPRICE)+StopLoss*Point,Ord(cnt,VAL_OPENPRICE)-TakeProfit*Point,Red); Exit; }; }; };//End of Sell End; }; };