#property copyright "Copyright ゥ 2008, SPYDER" #property link "http://www.metaquotes.net" extern bool SignalAlert = TRUE; extern bool SignalMail = FALSE; double g_pips_84 = 10.0; double g_pips_92 = 80.0; extern bool Lot_Control = TRUE; extern double Fixed_Lots = 0.0; double gd_112 = 10.0; double gd_120 = 1.0; double g_slippage_128 = 5.0; bool gi_136 = TRUE; double gd_unused_140 = 30.0; bool gi_148 = TRUE; double g_pips_152 = 18.0; int gi_160 = 2; int gi_164 = 10; int g_period_168 = 15; double gd_172 = 0.3; double gd_180 = 0.5; int g_period_188 = 650; int gi_192 = 2; int gi_196 = 80; double gd_unused_200 = 0.7; double gd_unused_208 = 0.7; double gd_unused_216 = 0.7; double gd_224 = 78.0; double gd_232 = 32.0; bool gi_240 = FALSE; double gd_244 = 1.9; int g_period_252 = 25; bool gi_256 = TRUE; int g_period_260 = 2; double gd_264 = 0.6; double gd_272 = 1.0; double gd_280 = 1.0; double gd_288 = 1.0; double gd_296 = 1.0; double gd_304 = 1.0; double gd_312 = 1.0; int gi_unused_324 = 1; int gi_328; int gi_332; double gd_336; int g_ticket_356; double g_price_360; int gi_368; int gi_372; double gd_376; int gi_384 = 4; int gi_388 = 0; int gi_392; int gi_396 = 80; double gd_400 = 0.8; int gi_408 = 3; int gi_412 = 0; int gi_416; bool gi_420; bool gi_424; int gia_428[2]; int init() { gi_368 = MagicfromSymbol() + 12345; gd_376 = Take_Profit(); return (0); } int deinit() { return (0); } int start() { int li_48; double ld_60; int l_datetime_100; double l_ord_open_price_104; int li_unused_0 = 0; int l_count_4 = 0; int l_count_8 = 0; bool li_12 = FALSE; bool li_16 = FALSE; bool li_20 = FALSE; bool li_24 = FALSE; int l_datetime_28 = TimeCurrent(); int l_hour_32 = TimeHour(l_datetime_28); int l_minute_36 = TimeMinute(l_datetime_28); HideTestIndicators(TRUE); if (IsTesting()) { Comment("The backing test cannot be done. "); return (-1); } string ls_40 = "Demo account version"; if (IsDemo()) { Print("I work at a demo account"); Comment(ls_40); } else { Alert("It is not possible to use it by a real account. "); return (-1); } switch (Period()) { case PERIOD_M1: li_48 = 1 * gi_396; break; case PERIOD_M5: li_48 = gi_396 / 5; break; case PERIOD_M15: li_48 = gi_396 / 15; break; case PERIOD_H1: li_48 = gi_396 / 60; break; case PERIOD_H4: li_48 = gi_396 / 240; } for (int li_56 = 1; li_56 <= li_48; li_56++) if (ld_60 < Close[li_56] - Bid) ld_60 = Close[li_56] - Bid; if (MathAbs(ld_60) > gd_400 && gi_412 == FALSE) { gi_412 = TRUE; gi_416 = TimeCurrent() + 3600 * gi_408; Comment(gi_396, "分以内に", 100.0 * gd_400, "pip変動したため", TimeToStr(gi_392), "迄売買停止します"); } if (gi_412 == TRUE) if (TimeCurrent() >= gi_416) gi_412 = FALSE; if (OrdersTotal() == 2) { gi_424 = TRUE; for (int l_pos_68 = 0; l_pos_68 < OrdersTotal(); l_pos_68++) { if (OrderSelect(l_pos_68, SELECT_BY_POS, MODE_TRADES) == TRUE) { if (OrderMagicNumber() == gi_368) { gia_428[l_pos_68] = OrderTicket(); if (OrderTicket() != 0) Print("Order_no", OrderTicket()); } } } } if (gi_424 == TRUE) { if (OrdersTotal() == 1) { if (OrderSelect(0, SELECT_BY_POS, MODE_TRADES) == TRUE) { if (OrderMagicNumber() == gi_368) if (gia_428[0] == OrderTicket()) gi_420 = TRUE; } } } if (gi_420 == TRUE) if (OrdersTotal() == 0) gi_420 = FALSE; double ld_unused_72 = 0; int l_hist_total_84 = OrdersHistoryTotal(); for (int l_pos_80 = 0; l_pos_80 < l_hist_total_84; l_pos_80++) { if (OrderSelect(l_pos_80, SELECT_BY_POS, MODE_HISTORY) == TRUE) { if (l_pos_80 == l_hist_total_84 - 1) { if (OrderProfit() < 0.0) { gi_388 = FALSE; gi_392 = OrderCloseTime() + 3600 * gi_384; Comment("損切り=", OrderProfit(), "時間=", TimeToStr(OrderCloseTime()), "再開=", TimeToStr(gi_392)); } } } } if (gi_388 == TRUE) if (TimeCurrent() >= gi_392) gi_388 = FALSE; if (!IsTradeAllowed()) return (0); int li_88 = OrdersHistoryTotal() - 1; int l_count_92 = 0; for (int l_pos_96 = li_88; l_pos_96 >= 0; l_pos_96--) { if (OrderSelect(l_pos_96, SELECT_BY_POS, MODE_HISTORY) == TRUE) { if (OrderMagicNumber() != gi_368) continue; l_datetime_100 = OrderCloseTime(); l_ord_open_price_104 = OrderOpenPrice(); l_count_92++; } if (l_ord_open_price_104 > 0.0) break; } int l_hour_112 = TimeHour(l_datetime_28 - l_datetime_100); if (l_hour_112 >= 1 || l_count_92 == 0 || Ask <= l_ord_open_price_104 - g_pips_152 * Point) li_20 = TRUE; if (l_hour_112 >= 1 || l_count_92 == 0 || Bid >= l_ord_open_price_104 + g_pips_152 * Point) li_24 = TRUE; if (!gi_256) { li_20 = TRUE; li_24 = TRUE; } double l_ord_open_price_116 = 0; double l_ord_profit_124 = 0; for (int l_pos_132 = 0; l_pos_132 < OrdersTotal(); l_pos_132++) { if (OrderSelect(l_pos_132, SELECT_BY_POS, MODE_TRADES) == TRUE) { if (OrderMagicNumber() == gi_368) { if (OrderType() == OP_BUY) l_count_4++; if (OrderType() == OP_SELL) l_count_8++; l_ord_profit_124 = OrderProfit(); l_ord_open_price_116 = OrderOpenPrice(); } } } int li_136 = l_count_4 + l_count_8; if (li_136 == 0 || li_136 > gi_372) gi_372 = li_136; double l_ima_140 = iMA(NULL, 0, g_period_168, gi_328, MODE_SMA, PRICE_OPEN, 0); double l_ima_148 = iMA(NULL, 0, 25, 0, MODE_EMA, PRICE_OPEN, 0); double l_ima_156 = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_OPEN, 0); double l_ima_164 = iMA(NULL, 0, 80, 0, MODE_EMA, PRICE_OPEN, 0); double l_ima_172 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_OPEN, 0); double l_ima_180 = iMA(NULL, 0, 300, 0, MODE_EMA, PRICE_OPEN, 0); double l_ima_188 = iMA(NULL, 0, 600, 0, MODE_EMA, PRICE_OPEN, 0); double ld_196 = iMA(NULL, 0, 10, 0, MODE_SMA, PRICE_OPEN, 0) * (gd_172 / 100.0); double ld_204 = ld_196 + l_ima_140; double ld_212 = l_ima_140 - ld_196; double ld_220 = (gd_180 / 100.0 + 1.0) * l_ima_140; double ld_228 = (1 - gd_180 / 100.0) * l_ima_140; double ld_236 = High[iHighest(NULL, 0, MODE_CLOSE, gi_196, 0)]; double ld_244 = Low[iLowest(NULL, 0, MODE_CLOSE, gi_196, 0)]; double l_irsi_252 = iRSI(NULL, 0, 9, PRICE_CLOSE, 0); double l_ima_260 = iMA(NULL, 0, g_period_188, gi_332, MODE_SMMA, PRICE_OPEN, 0); double ld_268 = (ld_236 - ld_244) / (l_ima_260 / 100.0); double l_istddev_276 = iStdDev(NULL, PERIOD_H4, g_period_252, 0, MODE_EMA, PRICE_CLOSE, 0); double l_iatr_284 = iATR(NULL, 0, g_period_260, 0); double l_istochastic_292 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0); double l_istochastic_300 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0); bool li_308 = FALSE; bool li_312 = FALSE; if (!li_12 && l_count_4 < gi_160 && ld_268 >= gd_336 && l_irsi_252 <= gd_232 && ld_212 >= Ask && l_iatr_284 <= gd_264 && Ask <= l_ord_open_price_116 - g_pips_152 * Point || l_count_4 == 0) li_308 = TRUE; if (!li_20 || (!gi_240 && l_istddev_276 >= gd_244)) li_308 = FALSE; if (l_ima_188 > l_ima_180 && l_ima_180 > l_ima_172 && l_ima_172 > l_ima_164 && l_ima_164 > l_ima_156 && l_ima_156 > l_ima_148) li_308 = FALSE; if (!li_12 && li_20 && l_count_4 < gi_160 && l_ima_188 < l_ima_180 && l_ima_180 < l_ima_172 && l_ima_172 < l_ima_164 && l_ima_164 < l_ima_148 && ld_228 >= Ask && Ask <= l_ord_open_price_116 - g_pips_152 * Point || l_count_4 == 0) li_308 = TRUE; if (li_308 == TRUE && gi_388 == FALSE && gi_412 == FALSE && gi_420 == FALSE) { ClosePositions(1, 4, gi_368); OrderPositions(1, l_count_4, l_count_8, gi_368); li_308 = FALSE; li_20 = FALSE; return (0); } if (!li_12 && l_count_8 < gi_160 && ld_268 >= gd_336 && l_irsi_252 >= gd_224 && l_iatr_284 <= gd_264 && ld_204 <= Bid && Bid >= l_ord_open_price_116 + g_pips_152 * Point || l_count_8 == 0) li_312 = TRUE; if (!li_24 || (!gi_240 && l_istddev_276 > gd_244)) li_312 = FALSE; if (l_ima_188 < l_ima_180 && l_ima_180 < l_ima_172 && l_ima_172 < l_ima_164 && l_ima_164 < l_ima_156 && l_ima_156 < l_ima_148) li_312 = FALSE; if (!li_12 && li_24 && l_count_8 < gi_160 && l_ima_188 > l_ima_180 && l_ima_180 > l_ima_172 && l_ima_172 > l_ima_164 && l_ima_164 > l_ima_148 && ld_220 <= Bid && Bid >= l_ord_open_price_116 + g_pips_152 * Point || l_count_8 == 0) li_312 = TRUE; if (li_312 == TRUE && gi_388 == FALSE && gi_412 == FALSE && gi_420 == FALSE) { ClosePositions(1, 3, gi_368); OrderPositions(2, l_count_4, l_count_8, gi_368); li_312 = FALSE; li_24 = FALSE; return (0); } double ld_316 = Bid - l_ord_open_price_116; if (gi_148 && l_count_4 > 0 && gd_376 > g_pips_84 * Point && ld_316 > g_pips_84 * Point) ClosePositions(0, 3, gi_368); double ld_324 = l_ord_open_price_116 - Ask; if (gi_148 && l_count_8 > 0 && gd_376 > g_pips_84 * Point && ld_324 > g_pips_84 * Point) ClosePositions(0, 4, gi_368); switch (gi_372) { case 4: if (l_count_4 == 1) ClosePositions(1, 3, gi_368); if (l_count_8 == 1) ClosePositions(1, 4, gi_368); case 0: case 1: case 2: case 3: break; } if (l_count_4 > 0 && ld_236 - Bid <= gi_192 * Point || ld_204 < Bid || li_16) { ClosePositions(1, 3, gi_368); return (0); } if (l_count_8 > 0 && Ask - ld_244 <= gi_192 * Point || ld_212 > Ask || li_16) { ClosePositions(1, 4, gi_368); return (0); } return (0); } double lotSizeCalc(int ai_0) { int li_4 = 1; double ld_ret_8 = 0; int li_16 = 0; double l_lotsize_20 = MarketInfo(Symbol(), MODE_LOTSIZE); double l_maxlot_28 = MarketInfo(Symbol(), MODE_MAXLOT); double l_minlot_36 = MarketInfo(Symbol(), MODE_MINLOT); double l_free_magrin_44 = AccountFreeMargin(); string ls_52 = AccountCurrency(); if (ls_52 == "JPY") li_4 = 100; if (ls_52 == "USD") li_4 = 1; double ld_60 = l_free_magrin_44 * gd_120 / (li_4 * l_lotsize_20); if (l_minlot_36 >= 1.0) li_16 = 0; else { if (l_minlot_36 >= 0.1) li_16 = 1; else if (l_minlot_36 >= 0.01) li_16 = 2; } switch (ai_0) { case 0: ld_ret_8 = NormalizeDouble(ld_60 * gd_272, li_16); break; case 1: ld_ret_8 = NormalizeDouble(ld_60 * gd_280, li_16); break; case 2: ld_ret_8 = NormalizeDouble(ld_60 * gd_288, li_16); break; case 3: ld_ret_8 = NormalizeDouble(ld_60 * gd_296, li_16); break; case 4: ld_ret_8 = NormalizeDouble(ld_60 * gd_304, li_16); break; default: ld_ret_8 = NormalizeDouble(ld_60 * gd_312, li_16); } if (ld_ret_8 < l_minlot_36) ld_ret_8 = l_minlot_36; if (ld_ret_8 > l_maxlot_28) ld_ret_8 = l_maxlot_28; if (ld_ret_8 > gd_112) ld_ret_8 = gd_112; return (ld_ret_8); } int MagicfromSymbol() { int li_ret_0 = 0; for (int li_4 = 0; li_4 < 5; li_4++) li_ret_0 = 3 * li_ret_0 + StringGetChar(Symbol(), li_4); li_ret_0 = 3 * li_ret_0 + Period(); return (li_ret_0); } double Take_Profit() { int l_stoplevel_0 = MarketInfo(Symbol(), MODE_STOPLEVEL); int l_freezelevel_4 = MarketInfo(Symbol(), MODE_FREEZELEVEL); if (l_stoplevel_0 > g_pips_84) gd_376 = l_stoplevel_0; else gd_376 = g_pips_84; if (l_freezelevel_4 > gd_376) gd_376 = l_freezelevel_4; return (gd_376); } void ClosePositions(int ai_0, int ai_4, int a_magic_8) { int l_error_12; int l_cmd_20; RefreshRates(); for (int l_pos_16 = OrdersTotal() - 1; l_pos_16 >= 0; l_pos_16--) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES) == FALSE) break; if (OrderMagicNumber() == a_magic_8) { l_cmd_20 = OrderType(); if ((l_cmd_20 == OP_BUY && ai_4 == 3) || (l_cmd_20 == OP_SELL && ai_4 == 4)) { switch (l_cmd_20) { case OP_BUY: OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_128, MediumSeaGreen); l_error_12 = GetLastError(); if (l_error_12 != 0/* NO_ERROR */) Print("Close Positions Error OrderTicket = ", OrderTicket()); else { if (SignalMail) SendMail("[ALART]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy"); if (SignalAlert) Alert("[ALART]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy"); } if (ai_0 == 0) return; break; case OP_SELL: OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_128, DarkOrange); l_error_12 = GetLastError(); if (l_error_12 != 0/* NO_ERROR */) Print("Close Positions Error OrderTicket = ", OrderTicket()); else { if (SignalMail) SendMail("[ALART]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "Close Sell"); if (SignalAlert) Alert("[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "Close Sell"); } if (ai_0 == 0) return; } } } } } void OrderPositions(int ai_0, int ai_4, int ai_8, int a_magic_12) { double ld_unused_16 = 0; double l_price_24 = 0; int li_32 = MathAbs(ai_4 - ai_8); double ld_36 = 0; if (Lot_Control) ld_36 = lotSizeCalc(li_32); else ld_36 = Fixed_Lots; if (ai_0 == 1) { g_ticket_356 = 0; if (AccountFreeMarginCheck(Symbol(), OP_BUY, ld_36) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return; } if (gi_136) l_price_24 = Ask - g_pips_92 * Point; else l_price_24 = 0.0; if (gi_148) g_price_360 = Ask + gd_376 * Point; else g_price_360 = 0.0; for (int li_44 = 1; li_44 <= gi_164; li_44++) { g_ticket_356 = OrderSend(Symbol(), OP_BUY, ld_36, Ask, g_slippage_128 * Point, l_price_24, g_price_360, "Buy(#" + a_magic_12 + ")", a_magic_12, 0, DodgerBlue); if (g_ticket_356 > 0) { if (OrderSelect(g_ticket_356, SELECT_BY_TICKET, MODE_TRADES)) { Print("BUY order opened : ", OrderOpenPrice()); if (SignalMail) SendMail("[ALART]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "@" + DoubleToStr(ld_36, 2) + "@ Open Buy"); if (!(SignalAlert)) break; Alert("[ALART]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + "@" + DoubleToStr(ld_36, 2) + "@ Open Buy"); break; } if (SignalAlert) Alert("Error opening BUY order : ", GetLastError()); Sleep(5000); } } } if (ai_0 == 2) { g_ticket_356 = 0; if (AccountFreeMarginCheck(Symbol(), OP_SELL, ld_36) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */) Print("We have no money. Free Margin = ", AccountFreeMargin()); else { if (gi_136) l_price_24 = Bid + g_pips_92 * Point; else l_price_24 = 0.0; if (gi_148) g_price_360 = Bid - gd_376 * Point; else g_price_360 = 0.0; for (int li_48 = 1; li_48 <= gi_164; li_48++) { g_ticket_356 = OrderSend(Symbol(), OP_SELL, ld_36, Bid, g_slippage_128 * Point, l_price_24, g_price_360, "Sell(#" + a_magic_12 + ")", a_magic_12, 0, DeepPink); if (g_ticket_356 > 0) { if (OrderSelect(g_ticket_356, SELECT_BY_TICKET, MODE_TRADES)) { Print("SELL order opened : ", OrderOpenPrice()); if (SignalMail) SendMail("[ALART]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "@" + ld_36 + "@ Open Sell"); if (!(SignalAlert)) break; Alert("[ALART]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + "@" + ld_36 + "@ Open Sell"); return; } if (SignalAlert) Alert("Error opening SELL order : ", GetLastError()); Sleep(5000); } } } } }