#include extern double lots = 0.01; extern string timeframe = "M30"; extern double Symbol.Max.Profit = 1.5; double gd_unused_100 = 150.0; extern double Maxrisk = 1500.0; extern int pips_to_lose = 25; extern double Max.Lots = 0.08; extern bool close_on_friday = TRUE; extern int close_hour = 15; extern bool allow_hedging = TRUE; extern int slippage = 2; extern int magic = 3; int g_period_148 = 3; int g_period_152 = 5; int g_period_156 = 25; int gi_unused_160 = 3; string gs_164 = ""; string gs_172; int gi_180 = 3; int gi_184 = 0; int gi_188 = 0; int gi_192 = 0; int gi_196 = 0; int gi_200 = 0; double gda_204[18]; double gda_208[18]; string gs_unused_212 = "EURUSD"; string gs_unused_220 = "EURCHF"; string gs_unused_228 = "USDCAD"; string gsa_236[18]; string gsa_240[18]; string gsa_244[18]; string gsa_unused_248[18]; string gsa_252[18]; string gsa_256[18]; string gsa_260[18]; string gsa_264[18]; string gsa_268[18]; string gsa_272[18]; string gsa_276[18]; string gsa_280[18]; string gsa_284[18]; double gda_288[18]; double gda_292[18]; double gda_unused_296[18]; int gia_300[18]; int gia_304[18]; string gsa_308[18]; int gia_312[18]; double g_ima_316 = 0.0; double g_ima_324 = 0.0; double g_ima_332 = 0.0; double g_ima_340 = 0.0; double g_ima_348 = 0.0; double g_ima_356 = 0.0; double gd_unused_364 = 0.0; double gd_unused_372 = 0.0; double gd_unused_380 = 0.0; double gd_unused_388 = 0.0; double gd_unused_396 = 0.0; double gd_unused_404 = 0.0; double gd_unused_412 = 0.0; double gd_unused_420 = 0.0; double gd_428 = 0.0; double gd_unused_436 = 0.0; double gd_444 = 0.0; int gi_452 = 1; int gi_unused_456 = 0; int g_timeframe_460 = 0; int gi_unused_464 = 0; int init() { gsa_236[0] = Symbol(); for (int l_index_0 = 0; l_index_0 < gi_452; l_index_0++) { gda_204[l_index_0] = 0; gda_208[l_index_0] = 0; gda_288[l_index_0] = 0; gda_292[l_index_0] = 0; gia_300[l_index_0] = 0; gia_304[l_index_0] = 0; gsa_308[l_index_0] = ""; gia_312[l_index_0] = TimeCurrent(); } gd_428 = GetEquity(); g_timeframe_460 = enumeration(timeframe); return (0); } int enumeration(string as_0) { int li_ret_8; if (as_0 == "MN1" || as_0 == "mn1") li_ret_8 = 43200; if (as_0 == "W1" || as_0 == "w1") li_ret_8 = 10080; if (as_0 == "D1" || as_0 == "d1") li_ret_8 = 1440; if (as_0 == "H4" || as_0 == "h4") li_ret_8 = 240; if (as_0 == "H1" || as_0 == "h1") li_ret_8 = 60; if (as_0 == "M30" || as_0 == "m30") li_ret_8 = 30; if (as_0 == "M15" || as_0 == "m15") li_ret_8 = 15; if (as_0 == "M5" || as_0 == "m5") li_ret_8 = 5; if (as_0 == "M1" || as_0 == "m1") li_ret_8 = 1; return (li_ret_8); } int deinit() { return (0); } void start() { string ls_0; int li_8; int li_12; int li_16; gs_172 = "\n----------------------------------------------------------------"; isCorrectTime(); if (gi_200 == TRUE) Initialize(); for (int l_index_20 = 0; l_index_20 < gi_452; l_index_20++) { gs_164 = ""; ls_0 = gsa_236[l_index_20]; CheckEntry(ls_0, l_index_20); gia_300[l_index_20] = GetPips_sym(gsa_236[l_index_20], OP_BUY); gia_304[l_index_20] = GetPips_sym(gsa_236[l_index_20], OP_SELL); if (gsa_308[l_index_20] == "Y" && TimeCurrent() - gia_312[l_index_20] > 7200) gsa_308[l_index_20] = ""; li_8 = CalculateOrders_sym(ls_0, OP_BUY); li_12 = CalculateOrders_sym(ls_0, OP_SELL); if (gi_200 == TRUE && li_8 == 0 && gs_164 == "BUY" && gsa_308[l_index_20] == "") if (allow_hedging || (!allow_hedging && li_12 == 0)) openOrder(gs_164, ls_0, lots); li_16 = 0; li_16 = FindPreviousOrders(ls_0, OP_BUY); if (!li_16 && li_8 > 0 && gia_300[l_index_20] <= (-1 * li_8) * pips_to_lose) { if (MathPow(2, li_8) * lots > Max.Lots) gd_444 = Max.Lots; else gd_444 = MathPow(2, li_8) * lots; openOrder("BUY", ls_0, gd_444); } if (gi_200 == TRUE && li_12 == 0 && gs_164 == "SELL" && gsa_308[l_index_20] == "") if (allow_hedging || (!allow_hedging && li_8 == 0)) openOrder(gs_164, ls_0, lots); li_16 = 0; li_16 = FindPreviousOrders(ls_0, OP_SELL); if (!li_16 && li_12 > 0 && gia_304[l_index_20] <= (-1 * li_12) * pips_to_lose) { if (MathPow(2, li_12) * lots > Max.Lots) gd_444 = Max.Lots; else gd_444 = MathPow(2, li_12) * lots; openOrder("SELL", ls_0, gd_444); } } for (int l_index_24 = 0; l_index_24 < gi_452; l_index_24++) { gda_288[l_index_24] = GetEquity_sym(gsa_236[l_index_24], OP_BUY); gda_292[l_index_24] = GetEquity_sym(gsa_236[l_index_24], OP_SELL); trail_basket_sym(gsa_236[l_index_24], l_index_24, 0); trail_basket_sym(gsa_236[l_index_24], l_index_24, 1); CheckMaxRisk(gsa_236[l_index_24], OP_BUY, l_index_24); CheckMaxRisk(gsa_236[l_index_24], OP_SELL, l_index_24); } if (close_on_friday == TRUE && DayOfWeek() == 5 && TimeHour(TimeCurrent()) >= close_hour) CloseOrders(); PrintSignals(); gs_172 = gs_172 + "\n----------------------------------------------------------------"; gs_172 = gs_172 + "\n" + "Number of Orders = " + gi_184; gs_172 = gs_172 + "\n" + "Number of times Profit reached = " + gi_188; gs_172 = gs_172 + "\n" + "Number of times Stoploss reached = " + gi_192; gs_172 = gs_172 + "\n" + "Number of times Max risk reached = " + gi_196; Comment(gs_172); } void Initialize() { for (int l_index_0 = 0; l_index_0 < gi_452; l_index_0++) { gsa_240[l_index_0] = "No Signal"; gsa_244[l_index_0] = "No Signal"; gsa_252[l_index_0] = "No Signal"; gsa_256[l_index_0] = "No Signal"; gsa_268[l_index_0] = "No Signal"; gsa_272[l_index_0] = "Within Limits"; gsa_276[l_index_0] = "No Signal"; gsa_280[l_index_0] = "No Signal"; gsa_284[l_index_0] = "No Signal"; gsa_260[l_index_0] = "No Signal"; gsa_264[l_index_0] = "No Signal"; } } void isCorrectTime() { gi_200 = FALSE; if (close_on_friday == TRUE && DayOfWeek() == 5 && TimeHour(TimeCurrent()) >= close_hour) { gs_172 = gs_172 + "\n" + "Closed for the week"; return; } if (TimeCurrent() - Time[0] >= 600) { gi_200 = TRUE; return; } gs_172 = gs_172 + "\n" + "Not the right time " + ((600 - (TimeCurrent() - Time[0]))) + " seconds to go"; } void CheckEntry(string a_symbol_0, int ai_8) { double l_point_12; if (MarketInfo(a_symbol_0, MODE_POINT) == 0.00001) l_point_12 = 0.0001; else { if (MarketInfo(a_symbol_0, MODE_POINT) == 0.001) l_point_12 = 0.01; else l_point_12 = MarketInfo(a_symbol_0, MODE_POINT); } g_ima_316 = iMA(a_symbol_0, g_timeframe_460, g_period_148, 0, MODE_EMA, PRICE_CLOSE, 0); g_ima_324 = iMA(a_symbol_0, g_timeframe_460, g_period_148, 0, MODE_EMA, PRICE_CLOSE, 1); g_ima_332 = iMA(a_symbol_0, g_timeframe_460, g_period_152, 0, MODE_EMA, PRICE_OPEN, 0); g_ima_340 = iMA(a_symbol_0, g_timeframe_460, g_period_152, 0, MODE_EMA, PRICE_OPEN, 1); g_ima_348 = iMA(a_symbol_0, g_timeframe_460, g_period_156, 0, MODE_EMA, PRICE_CLOSE, 0); g_ima_356 = iMA(a_symbol_0, g_timeframe_460, g_period_156, 0, MODE_EMA, PRICE_CLOSE, 1); double l_iopen_20 = iOpen(a_symbol_0, g_timeframe_460, 0); double l_bid_28 = MarketInfo(a_symbol_0, MODE_BID); if (g_ima_316 < g_ima_324 - 2.0 * l_point_12 && g_ima_316 < g_ima_332 - 2.0 * l_point_12 && g_ima_348 < g_ima_356 - 1.0 * l_point_12) gsa_244[ai_8] = "Sell"; else if (g_ima_316 > g_ima_324 + 2.0 * l_point_12 && g_ima_316 > g_ima_332 + 2.0 * l_point_12 && g_ima_348 > g_ima_356 + 1.0 * l_point_12) gsa_244[ai_8] = "Buy"; if (l_bid_28 < l_iopen_20 - 3.0 * l_point_12) gsa_256[ai_8] = "Sell"; else if (l_bid_28 > l_iopen_20 + 3.0 * l_point_12) gsa_256[ai_8] = "Buy"; if (gsa_244[ai_8] == "Sell" && gsa_256[ai_8] == "Sell") { gs_164 = "SELL"; gsa_240[ai_8] = "SELL"; } if (gsa_244[ai_8] == "Buy" && gsa_256[ai_8] == "Buy") { gs_164 = "BUY"; gsa_240[ai_8] = "BUY"; } } int FindPreviousOrders(string a_symbol_0, int a_cmd_8) { int li_12; for (int l_pos_16 = 0; l_pos_16 < OrdersTotal(); l_pos_16++) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber() == magic) { if (OrderSymbol() == a_symbol_0) { if (OrderType() == a_cmd_8) if (OrderOpenTime() > TimeCurrent() - 1800) li_12++; } } } } for (l_pos_16 = OrdersHistoryTotal(); l_pos_16 >= OrdersHistoryTotal() - 200; l_pos_16--) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_HISTORY)) { if (OrderMagicNumber() == magic) { if (OrderSymbol() == a_symbol_0) { if (OrderType() == a_cmd_8) { if (TimeDayOfYear(OrderCloseTime()) == TimeDayOfYear(TimeCurrent())) if (OrderCloseTime() > TimeCurrent() - 60) li_12++; } } } } } if (li_12 > 0) return (1); return (0); } void openOrder(string as_0, string a_symbol_8, double ad_16) { double ld_24 = calculate_points(a_symbol_8); if (as_0 == "BUY") OpenPendingOrder(a_symbol_8, 0, ad_16, MarketInfo(a_symbol_8, MODE_ASK), slippage, 0, 0, 0, magic, 0); if (as_0 == "SELL") OpenPendingOrder(a_symbol_8, 1, ad_16, MarketInfo(a_symbol_8, MODE_BID), slippage, 0, 0, 0, magic, 0); } void CheckMaxRisk(string a_symbol_0, int a_cmd_8, int ai_12) { double ld_16 = 0; for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) { if (OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber() == magic) { if (OrderSymbol() == a_symbol_0) if (OrderType() == a_cmd_8) ld_16 += OrderProfit(); } } } if (ld_16 < -1.0 * Maxrisk) { CloseOrders_sym(a_symbol_0, a_cmd_8); gi_196++; Print("Max risk " + Maxrisk + " reached for " + a_symbol_0 + " ...so closing all orders "); gsa_308[ai_12] = "Y"; gia_312[ai_12] = TimeCurrent(); } } void trail_basket_sym(string as_0, int ai_8, int ai_12) { double ld_16 = 0; if (ai_12 == 0) ld_16 = gda_288[ai_8]; if (ai_12 == 1) ld_16 = gda_292[ai_8]; if (ld_16 >= Symbol.Max.Profit) { Print("before max profit"); CloseOrders_sym(as_0, ai_12); Print("MAX PROFIT HIT. SO CLOSING ALL ORDERS....: " + as_0 + " " + ld_16); gi_188++; ld_16 = 0; } } double GetEquity() { double ld_ret_0; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { if (OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES)) if (OrderMagicNumber() == magic) ld_ret_0 += OrderProfit() + OrderSwap() + OrderCommission(); } return (ld_ret_0); } double GetEquity_sym(string a_symbol_0, int a_cmd_8) { double ld_ret_12; for (int l_pos_20 = 0; l_pos_20 < OrdersTotal(); l_pos_20++) { if (OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES)) { if (magic == OrderMagicNumber()) { if (OrderSymbol() == a_symbol_0) if (OrderType() == a_cmd_8) ld_ret_12 += OrderProfit() + OrderSwap() + OrderCommission(); } } } return (ld_ret_12); } double GetPips_sym(string a_symbol_0, int a_cmd_8) { double ld_ret_12; for (int l_pos_20 = 0; l_pos_20 < OrdersTotal(); l_pos_20++) { if (OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES)) { if (magic == OrderMagicNumber()) { if (OrderSymbol() == a_symbol_0) { if (OrderType() == a_cmd_8) { if (OrderType() == OP_BUY) ld_ret_12 += MarketInfo(a_symbol_0, MODE_BID) - OrderOpenPrice(); if (OrderType() == OP_SELL) ld_ret_12 += OrderOpenPrice() - MarketInfo(a_symbol_0, MODE_ASK); } } } } } ld_ret_12 /= calculate_points(a_symbol_0); return (ld_ret_12); } int CalculateOrders_sym(string a_symbol_0, int a_cmd_8) { int li_ret_12; for (int l_pos_16 = 0; l_pos_16 < OrdersTotal(); l_pos_16++) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == a_symbol_0) { if (OrderMagicNumber() == magic) if (OrderType() == a_cmd_8) li_ret_12++; } } } return (li_ret_12); } void CloseOrders_sym(string a_symbol_0, int a_cmd_8) { int l_ord_delete_12; int l_cmd_16; for (int li_20 = CalculateOrders_sym(a_symbol_0, a_cmd_8); li_20 > 0; li_20 = CalculateOrders_sym(a_symbol_0, a_cmd_8)) { for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) { if (OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber() == magic) { if (OrderSymbol() == a_symbol_0) { if (OrderType() == a_cmd_8) { l_cmd_16 = OrderType(); if (l_cmd_16 == OP_BUY || l_cmd_16 == OP_SELL) l_ord_delete_12 = CloseAtMarket(OrderTicket(), OrderLots()); else l_ord_delete_12 = OrderDelete(OrderTicket()); } } } } } } } int CloseAtMarket(int a_ticket_0, double a_lots_4) { int l_count_12; bool l_ord_close_16 = FALSE; int l_count_20 = 0; OrderSelect(a_ticket_0, SELECT_BY_TICKET, MODE_TRADES); while (!l_ord_close_16 && l_count_20 < 5) { l_count_12 = 0; while (l_count_12 < 5 && !IsTradeAllowed()) { l_count_12++; Sleep(2000); } RefreshRates(); l_ord_close_16 = OrderClose(a_ticket_0, a_lots_4, OrderClosePrice(), slippage, White); l_count_20++; } if (!l_ord_close_16) Print("Error closing order : " + a_ticket_0 + " " + ErrorDescription(GetLastError())); return (0); } void CloseOrders() { int l_ord_delete_0; int l_cmd_4; for (int li_8 = CalculateOrders(); li_8 > 0; li_8 = CalculateOrders()) { for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) { if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber() == magic) { l_cmd_4 = OrderType(); if (l_cmd_4 == OP_BUY || l_cmd_4 == OP_SELL) l_ord_delete_0 = CloseAtMarket(OrderTicket(), OrderLots()); else l_ord_delete_0 = OrderDelete(OrderTicket()); } } } } } int CalculateOrders() { int li_ret_0; for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) { if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) if (OrderMagicNumber() == magic) li_ret_0++; } return (li_ret_0); } int OpenPendingOrder(string a_symbol_0, int ai_8 = 2, double a_lots_12 = 1.0, double a_price_20 = 5.0, int a_slippage_28 = 0, double a_price_32 = 0.0, double a_price_40 = 0.0, string a_comment_48 = "Forex_wealth @ Ebay", int a_magic_56 = 123, int a_datetime_60 = 0, color a_color_64 = 65535) { int l_ticket_68 = 0; if (ai_8 == 0) l_ticket_68 = OrderSend(a_symbol_0, OP_BUY, a_lots_12, a_price_20, a_slippage_28, a_price_32, a_price_40, a_comment_48, a_magic_56, a_datetime_60, a_color_64); if (ai_8 == 1) l_ticket_68 = OrderSend(a_symbol_0, OP_SELL, a_lots_12, a_price_20, a_slippage_28, a_price_32, a_price_40, a_comment_48, a_magic_56, a_datetime_60, a_color_64); if (l_ticket_68 > 0) { if (OrderSelect(l_ticket_68, SELECT_BY_TICKET, MODE_TRADES)) gi_184++; else Print(TimeToStr(TimeCurrent()) + " : Error opening " + GetOrderType(OrderType()) + " order : ", GetLastError()); } else { gi_180++; if (gi_180 <= 3) { Print(TimeToStr(TimeCurrent()) + " : attempts " + gi_180); Sleep(100000); Print(TimeToStr(TimeCurrent()) + " : OpenPendingOrder(" + a_symbol_0 + "," + ai_8 + "," + a_lots_12 + "," + a_price_20 + "," + a_slippage_28 + "," + a_price_32 + "," + a_price_40 + "," + a_comment_48 + "," + a_magic_56 + "," + a_datetime_60 + "," + a_color_64 + ")"); OpenPendingOrder(a_symbol_0, ai_8, a_lots_12, a_price_20, a_slippage_28, a_price_32, a_price_40, a_comment_48, a_magic_56, a_datetime_60, a_color_64); } } return (l_ticket_68); } string GetOrderType(int ai_0) { if (ai_0 == 0) return ("Buying position"); if (ai_0 == 1) return ("Selling position"); if (ai_0 == 2) return ("Buy Limit pending position"); if (ai_0 == 4) return ("Buy Stop pending position"); if (ai_0 == 3) return ("Sell Limit pending position"); if (ai_0 == 5) return ("Sell Stop pending position"); return (""); } double calculate_points(string a_symbol_0) { double l_point_8; if (MarketInfo(a_symbol_0, MODE_POINT) == 0.00001) l_point_8 = 0.0001; else { if (MarketInfo(a_symbol_0, MODE_POINT) == 0.001) l_point_8 = 0.01; else l_point_8 = MarketInfo(a_symbol_0, MODE_POINT); } return (l_point_8); } void PrintSignals() { gs_172 = gs_172 + "\n Symbol Signal ----->>Profit / Loss for Buy----->> Profit / Loss for Sell ----->>Current Profit"; for (int l_index_0 = 0; l_index_0 < gi_452; l_index_0++) { gs_172 = gs_172 + "\n " + gsa_236[l_index_0] + " " + gsa_240[l_index_0] + ": Buy: ----->>" + gda_288[l_index_0] + ": Sell: ----->>" + gda_292[l_index_0]; } }