#property copyright "Seichi Oda" #property link "http://dreamgatefx.com/top/" #include extern int MagicNumber = 20091230; extern double Lots = 0.01; int gi_88 = 1; int gi_92 = 5; int gi_96 = 10; int gi_100 = 100; extern int SlipPage = 5; double gd_108 = 0.0; int gi_116 = 240; int gi_120 = 240; int gi_124 = 240; int gi_unused_128 = 240; int gi_132 = 0; double g_pips_136 = 10.0; double g_pips_144 = 15.0; double g_pips_152 = 15.0; double g_pips_160 = 15.0; int gi_168 = 20; int g_period_172 = 16; int gi_176 = 2; int gi_180 = 15; int gi_184 = 15; int gi_unused_188 = 15; int gi_unused_192 = 15; extern bool SummerTime = FALSE; int gi_200 = 22; int gi_204 = 8; int gi_208 = 3; extern bool SoundFlag = FALSE; extern bool MailFlag = FALSE; double g_minlot_220; double g_maxlot_228; double g_lotsize_236; double gd_244; string gs_252; string gs_260; string g_acc_number_268; string gs_276; int OrderCheck() { int li_0 = MACheck(); int li_4 = MACheck2(); int li_8 = BandsCheck(); if (TimeHour(TimeCurrent()) >= gi_200 || TimeHour(TimeCurrent()) <= gi_204 && li_8 == 1) return (1); if (TimeHour(TimeCurrent()) >= gi_200 || TimeHour(TimeCurrent()) <= gi_204 && li_8 == -1) return (-1); return (0); } int BandsCheck() { double l_ibands_0 = iBands(NULL, PERIOD_M15, g_period_172, gi_176, 0, PRICE_CLOSE, MODE_LOWER, 1); double l_ibands_8 = iBands(NULL, PERIOD_M15, g_period_172, gi_176, 0, PRICE_CLOSE, MODE_UPPER, 1); if (Bid < l_ibands_0 && l_ibands_8 - l_ibands_0 >= gi_180 * Point) return (1); if (Bid > l_ibands_8 && l_ibands_8 - l_ibands_0 >= gi_184 * Point) return (-1); return (0); } int MACheck() { double l_ima_0 = iMA(NULL, PERIOD_M5, 10, 0, MODE_SMA, PRICE_CLOSE, 1); double l_ima_8 = iMA(NULL, PERIOD_M5, 20, 0, MODE_SMA, PRICE_CLOSE, 1); int li_ret_16 = 0; if (l_ima_0 > l_ima_8) li_ret_16 = -1; if (l_ima_0 < l_ima_8) li_ret_16 = 1; return (li_ret_16); } int MACheck2() { double l_ima_0 = iMA(NULL, PERIOD_M15, 50, 0, MODE_SMA, PRICE_CLOSE, 1); double l_ima_8 = iMA(NULL, PERIOD_M15, 100, 0, MODE_SMA, PRICE_CLOSE, 1); int li_ret_16 = 0; if (l_ima_0 > l_ima_8) li_ret_16 = -1; if (l_ima_0 < l_ima_8) li_ret_16 = 1; return (li_ret_16); } int start() { double l_ord_open_price_12; int li_0 = 0; if (SettingCheck() == 0) return (0); double ld_20 = Lots() * gi_88; double ld_28 = Lots() * gi_92; double ld_36 = Lots() * gi_96; double ld_44 = Lots() * gi_100; int li_52 = 0; int li_56 = 0; int li_60 = 0; int li_64 = 0; int li_unused_68 = 0; for (int l_pos_72 = OrdersTotal() - 1; l_pos_72 >= 0; l_pos_72--) { if (OrderSelect(l_pos_72, SELECT_BY_POS, MODE_TRADES) == TRUE) { if (OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY && OrderLots() == ld_20) { l_ord_open_price_12 = OrderOpenPrice(); li_56 = 1; if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) > NormalizeDouble(g_pips_136 * Point, Digits)) li_52 = -1; } if (OrderType() == OP_BUY && OrderLots() == ld_28) { li_60 = 1; if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) > NormalizeDouble(g_pips_144 * Point, Digits)) li_52 = -1; } if (OrderType() == OP_BUY && OrderLots() == ld_36) { li_64 = 1; if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) > NormalizeDouble(g_pips_152 * Point, Digits)) li_52 = -1; } if (OrderType() == OP_BUY && OrderLots() == ld_44) { li_unused_68 = 1; if (NormalizeDouble(Bid - OrderOpenPrice(), Digits) > NormalizeDouble(g_pips_160 * Point, Digits)) li_52 = -1; } if (OrderType() == OP_SELL && OrderLots() == ld_20) { l_ord_open_price_12 = OrderOpenPrice(); li_56 = -1; if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) > NormalizeDouble(g_pips_136 * Point, Digits)) li_52 = 1; } if (OrderType() == OP_SELL && OrderLots() == ld_28) { li_60 = -1; if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) > NormalizeDouble(g_pips_144 * Point, Digits)) li_52 = 1; } if (OrderType() == OP_SELL && OrderLots() == ld_36) { li_64 = -1; if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) > NormalizeDouble(g_pips_152 * Point, Digits)) li_52 = 1; } if (OrderType() == OP_SELL && OrderLots() == ld_44) { li_unused_68 = -1; if (NormalizeDouble(OrderOpenPrice() - Ask, Digits) > NormalizeDouble(g_pips_160 * Point, Digits)) li_52 = 1; } } } } if (li_52 != 0) { for (int l_pos_76 = OrdersTotal() - 1; l_pos_76 >= 0; l_pos_76--) { if (OrderSelect(l_pos_76, SELECT_BY_POS, MODE_TRADES) == TRUE) if (OrderMagicNumber() == MagicNumber) MyOrderClose(); } } li_0 = OrderCheck(); if (OrdersTotal() == 0 && li_0 == 1 && li_56 == 0) MyOrderSend(OP_BUY, ld_20, gi_116); if (OrdersTotal() == 1 && li_56 == 1 && li_60 == 0 && Ask < l_ord_open_price_12 - 50.0 * Point) MyOrderSend(OP_BUY, ld_28, gi_120); if (OrdersTotal() == 2 && li_56 == 1 && li_60 == 1 && li_64 == 0 && Ask < l_ord_open_price_12 - 100.0 * Point) MyOrderSend(OP_BUY, ld_36, gi_124); if (OrdersTotal() == 0 && li_0 == -1 && li_56 == 0) MyOrderSend(OP_SELL, ld_20, gi_116); if (OrdersTotal() == 1 && li_56 == -1 && li_60 == 0 && Bid > l_ord_open_price_12 + 50.0 * Point) MyOrderSend(OP_SELL, ld_28, gi_120); if (OrdersTotal() == 2 && li_56 == -1 && li_60 == -1 && li_64 == 0 && Bid > l_ord_open_price_12 + 100.0 * Point) MyOrderSend(OP_SELL, ld_36, gi_124); return (0); } int MyOrderSend(int a_cmd_0, double a_lots_4, double a_pips_12) { double l_price_20; double l_price_28; string l_comment_36; string ls_44; string ls_52; int l_error_64; int li_60 = GetTickCount(); while (true) { if (GetTickCount() - li_60 > 1000 * gi_168) { Print("OrderSend timeout. Check the experts log."); return (0); } if (IsTradeAllowed() == TRUE) { RefreshRates(); if (a_cmd_0 == OP_BUY) { l_price_20 = NormalizeDouble(Ask, Digits); if (a_pips_12 > 0.0) a_pips_12 = NormalizeDouble(Ask - a_pips_12 * Point, Digits); else a_pips_12 = 0; if (gi_132 > 0) l_price_28 = NormalizeDouble(Ask + gi_132 * Point, Digits); else l_price_28 = 0; l_comment_36 = "DreamGateFX_SEVEN BUY"; if (OrderSend(Symbol(), a_cmd_0, a_lots_4, l_price_20, SlipPage, a_pips_12, l_price_28, l_comment_36, MagicNumber, 0, Blue) != -1) { ls_44 = "DGFX_SEVEN Buy Mail"; ls_52 = l_price_20 + " Buy"; MySendMail(ls_44, ls_52); MyPlaySound(); return (1); } } else { if (a_cmd_0 == OP_SELL) { l_price_20 = NormalizeDouble(Bid, Digits); if (a_pips_12 > 0.0) a_pips_12 = NormalizeDouble(Bid + a_pips_12 * Point, Digits); else a_pips_12 = 0; if (gi_132 > 0) l_price_28 = NormalizeDouble(Bid - gi_132 * Point, Digits); else l_price_28 = 0; l_comment_36 = "DreamGateFX_SEVEN SELL"; if (OrderSend(Symbol(), a_cmd_0, a_lots_4, l_price_20, SlipPage, a_pips_12, l_price_28, l_comment_36, MagicNumber, 0, Red) != -1) { ls_44 = "DGFX_SEVEN Sell Mail"; ls_52 = l_price_20 + " Sell"; MySendMail(ls_44, ls_52); MyPlaySound(); return (1); } } } l_error_64 = GetLastError(); Print("[OrderSendError] : ", l_error_64, " ", ErrorDescription(l_error_64)); if (l_error_64 == 129/* INVALID_PRICE */) break; if (l_error_64 == 130/* INVALID_STOPS */) break; } Sleep(100); } return (0); } int MyOrderClose() { double l_price_0; string ls_8; string ls_16; int l_error_36; int l_ticket_24 = 0; int l_cmd_28 = OrderType(); if (l_cmd_28 == OP_BUY || l_cmd_28 == OP_SELL) l_ticket_24 = OrderTicket(); if (l_ticket_24 == 0) return (0); int li_32 = GetTickCount(); while (true) { if (GetTickCount() - li_32 > 1000 * gi_168) { Print("OrderClose timeout. Check the experts log."); return (0); } if (IsTradeAllowed() == TRUE) { RefreshRates(); if (l_cmd_28 == OP_BUY) { l_price_0 = NormalizeDouble(Bid, Digits); if (OrderClose(l_ticket_24, OrderLots(), l_price_0, SlipPage, Green) == 1) { ls_8 = "DGFX_SEVEN Close Mail"; ls_16 = l_price_0 + " Close"; MySendMail(ls_8, ls_16); MyPlaySound(); return (1); } } else { if (l_cmd_28 == OP_SELL) { l_price_0 = NormalizeDouble(Ask, Digits); if (OrderClose(l_ticket_24, OrderLots(), l_price_0, SlipPage, Green) == 1) { ls_8 = "DGFX_SEVEN Close Mail"; ls_16 = l_price_0 + " Close"; MySendMail(ls_8, ls_16); MyPlaySound(); return (1); } } } l_error_36 = GetLastError(); Print("[OrderCloseError] : ", l_error_36, " ", ErrorDescription(l_error_36)); if (l_error_36 == 129/* INVALID_PRICE */) break; } Sleep(100); } return (0); } int SettingCheck() { if (IsTradeAllowed() == FALSE) { Print("トレードが許可されていません"); return (0); } if (!IsTesting() && !IsDemo() && gs_276 != gs_260) { MessageBox("設定と違う口座番号です"); Print("設定と違う口座番号です"); return (0); } if (AccountCompany() != "FXDirectDealer") { MessageBox("FXブローカーはFXDDのみです"); Print("FXブローカーはFXDDのみです"); return (0); } if (Bars <= 100) { MessageBox("チャートの表\示数が少ないです"); Print("チャートの表\示数が少ないです"); return (0); } if (AccountBalance() == 0.0) { MessageBox("口座の残高がありません"); Print("口座の残高がありません"); return (0); } if (gd_108 > gd_244) { MessageBox("レバレッジは", gd_244, "倍以下にして下さい"); Print("レバレッジは", gd_244, "倍以下にして下さい"); return (0); } return (1); } void MySendMail(string as_0, string as_8) { if (MailFlag == TRUE) SendMail(as_0, as_8); } void MyPlaySound() { if (SoundFlag == TRUE) PlaySound("alert.wav"); } double Lots() { double ld_ret_0 = 0.0; double ld_unused_8 = 0.0; double ld_unused_16 = 0.0; if (gd_108 > 0.0) { ld_ret_0 = NormalizeDouble(AccountFreeMargin() * gd_108 / g_lotsize_236, 2); ld_ret_0 = NormalizeDouble(AccountBalance() * gd_108 / g_lotsize_236, 2); } else ld_ret_0 = NormalizeDouble(Lots, 2); if (ld_ret_0 < g_minlot_220) ld_ret_0 = g_minlot_220; if (ld_ret_0 > g_maxlot_228) ld_ret_0 = g_maxlot_228; return (ld_ret_0); } void StringSplit(string as_0, string as_8, string &asa_16[]) { int l_arr_size_32; string ls_20 = as_0; ArrayResize(asa_16, 0); int li_28 = 0; while (true) { li_28 = StringFind(ls_20, as_8, 0); l_arr_size_32 = ArraySize(asa_16); ArrayResize(asa_16, l_arr_size_32 + 1); if (li_28 == -1) { asa_16[l_arr_size_32] = ls_20; return; } if (li_28 == 0) asa_16[l_arr_size_32] = ""; else asa_16[l_arr_size_32] = StringSubstr(ls_20, 0, li_28); ls_20 = StringSubstr(ls_20, li_28 + StringLen(as_8)); } } int init() { string lsa_0[]; HideTestIndicators(TRUE); g_minlot_220 = MarketInfo(Symbol(), MODE_MINLOT); g_maxlot_228 = MarketInfo(Symbol(), MODE_MAXLOT); g_lotsize_236 = MarketInfo(Symbol(), MODE_LOTSIZE); gd_244 = AccountLeverage(); gs_252 = WindowExpertName(); StringSplit(gs_252, "_", lsa_0); gs_260 = lsa_0[2]; g_acc_number_268 = AccountNumber(); string ls_4 = StringSubstr(g_acc_number_268, 3, 1); string ls_12 = StringSubstr(g_acc_number_268, 4, 1); gs_276 = StrToInteger(ls_4 + ls_12) * 2; if (SummerTime == TRUE) { gi_200++; gi_204++; gi_208++; } return (0); }