#property copyright "Copyright © 2008, FXCM Programming Services" #property link "http://www.fxcm.com/strategy-consulting-landing.jsp" extern double StopLoss = 30.0; extern double TakeProfit = 100.0; extern int SMAfast = 20; extern int SMAslow = 40; extern double ExtendCross = 0.5; extern bool fractionalpips = TRUE; extern double NumberOfLots = 1.0; extern double LotSize = 0.1; extern int MagicNumber = 7777777; extern int Slippage = 4; bool gi_136 = TRUE; string g_symbol_140; int gi_unused_148 = 0; int gi_152; int gi_156; int gi_160 = 0; int gi_164 = 0; bool gi_168 = TRUE; void start() { int l_ticket_8; double l_ord_lots_20; double l_ord_open_price_36; double l_price_44; double l_price_52; int l_cmd_4 = -1; double ld_unused_60 = 0; int li_unused_84 = 0; int li_unused_88 = 0; int li_unused_92 = 0; bool li_96 = FALSE; bool li_100 = FALSE; string ls_104 = "FXCM_SMA_Crossover"; if (WindowExpertName() != ls_104) { Comment("" + "\n" + "\n" + " FXCM_SMA_Crossover.ex4 is required to run this script."); return; } Comment("" + "\n" + "FXCM Programming Services SMA Crossover" + "\n"); if (Bars < 50) { Alert("Not enough bars in the window."); return; } if (gi_136 == FALSE) { Alert("Critical error. EA doesnt work."); return; } if (fractionalpips == TRUE) gi_152 = 10; else gi_152 = 1; double l_slippage_12 = Slippage * gi_152; g_symbol_140 = Symbol(); int l_count_0 = 0; for (int li_112 = 1; li_112 <= OrdersTotal(); li_112++) { if (OrderSelect(li_112 - 1, SELECT_BY_POS) == TRUE) { if (OrderSymbol() != g_symbol_140 || OrderMagicNumber() != MagicNumber) continue; if (OrderType() > OP_SELL) { Alert("Pending order detected."); return; } l_count_0++; if (l_count_0 > 1) return; l_ticket_8 = OrderTicket(); l_cmd_4 = OrderType(); l_ord_open_price_36 = OrderOpenPrice(); l_price_44 = OrderStopLoss(); l_price_52 = OrderTakeProfit(); l_ord_lots_20 = OrderLots(); } } RefreshRates(); double l_ima_68 = iMA(Symbol(), 0, SMAfast, 0, MODE_SMA, PRICE_CLOSE, 1); double l_ima_76 = iMA(Symbol(), 0, SMAslow, 0, MODE_SMA, PRICE_CLOSE, 1); gi_156 = CrossedOver(l_ima_68, l_ima_76); if (gi_156 == 1) li_96 = TRUE; else li_96 = FALSE; if (gi_156 == 2) li_100 = TRUE; else li_100 = FALSE; double l_lots_28 = LotSize * NumberOfLots; while (true) { if (l_count_0 == 0 && li_96 == TRUE) { RefreshRates(); l_price_44 = Ask - StopLoss * Point * gi_152; l_price_52 = Ask + TakeProfit * Point * gi_152; l_ticket_8 = OrderSend(g_symbol_140, OP_BUY, l_lots_28, Ask, l_slippage_12, 0, 0, "Automated", MagicNumber, 0, Green); if (l_ticket_8 > 0) { Alert("Opened order Buy ", l_ticket_8); OrderSelect(l_ticket_8, SELECT_BY_TICKET); OrderModify(OrderTicket(), OrderOpenPrice(), l_price_44, l_price_52, 0, Green); return; } if (Fun_Error(GetLastError()) == 1) continue; return; } if (!(l_count_0 == 0 && li_100 == TRUE)) break; RefreshRates(); l_price_44 = Bid + StopLoss * Point * gi_152; l_price_52 = Bid - TakeProfit * Point * gi_152; l_ticket_8 = OrderSend(g_symbol_140, OP_SELL, l_lots_28, Bid, l_slippage_12, 0, 0, "Automated", MagicNumber, 0, Red); if (l_ticket_8 > 0) { Alert("Opened order Sell ", l_ticket_8); OrderSelect(l_ticket_8, SELECT_BY_TICKET); OrderModify(OrderTicket(), OrderOpenPrice(), l_price_44, l_price_52, 0, Red); return; } if (Fun_Error(GetLastError()) == 1) continue; break; } } int Fun_Error(int ai_0) { switch (ai_0) { case 4: Alert("Trade server is busy. Trying once again.."); Sleep(3000); return (1); case 135: Alert("Price changed. Trying once again.."); RefreshRates(); return (1); case 136: Alert("No prices. Waiting for a new tick.."); while (RefreshRates() == FALSE) Sleep(1); return (1); case 137: Alert("Broker is busy. Trying once again.."); Sleep(3000); return (1); case 146: Alert("Trading subsystem is busy. Trying once again.."); Sleep(500); return (1); case 2: Alert("Common error."); return (0); case 5: Alert("Old terminal version."); gi_136 = FALSE; return (0); case 64: Alert("Account blocked."); gi_136 = FALSE; return (0); case 133: Alert("Trading forbidden."); return (0); case 134: Alert("Not enough money to execute operation."); return (0); } Alert("Error occurred: ", ai_0); return (0); } int CrossedOver(double ad_0, double ad_8) { if (fractionalpips == FALSE) gi_152 = 1; else gi_152 = 10; if (gi_168 == TRUE) { gi_168 = FALSE; if (ad_0 > ad_8) { gi_164 = 1; gi_160 = 1; } if (ad_0 < ad_8) { gi_164 = 2; gi_160 = 2; } return (0); } if (ad_0 - ExtendCross * Point * gi_152 > ad_8) gi_164 = 1; if (ad_0 + ExtendCross * Point * gi_152 < ad_8) gi_164 = 2; if (gi_164 != gi_160) { gi_160 = gi_164; return (gi_164); } return (0); }