#property copyright "Seichi Oda" #property link "http://dreamgatefx.com/top/" #include extern int MagicNumber = 20091030; extern double Lots = 0.1; extern double Leverage = 0.0; extern int SlipPage = 5; extern int StopLoss = 110; extern int TakeProfit = 10; int gi_108 = 20; int g_period_112 = 7; int gi_116 = 2; int gi_120 = 11; int gi_124 = 13; int gi_128 = 13; int gi_132 = 11; extern bool SummerTime = FALSE; int gi_140 = 22; int gi_144 = 1; int gi_148 = 3; extern bool SoundFlag = FALSE; extern bool MailFlag = FALSE; double g_minlot_160; double g_maxlot_168; double g_lotsize_176; double gd_184; string gs_192; string gs_200; string g_acc_number_208; string gs_216; int OrderCheck() { int li_0 = BandsCheck(); int li_4 = BandsCheck2(); if (DayOfWeek() == 5 && Hour() >= gi_140) return (0); if (TimeHour(TimeCurrent()) >= gi_140 || TimeHour(TimeCurrent()) <= gi_144 && li_0 == 1) return (1); if (TimeHour(TimeCurrent()) >= gi_140 || TimeHour(TimeCurrent()) <= gi_144 && li_0 == -1) return (-1); if (TimeHour(TimeCurrent()) == gi_148 && li_4 == 1) return (2); if (TimeHour(TimeCurrent()) == gi_148 && li_4 == -1) return (-2); return (0); } int BandsCheck() { double l_ibands_0 = iBands(NULL, PERIOD_M15, g_period_112, gi_116, 0, PRICE_CLOSE, MODE_LOWER, 1); double l_ibands_8 = iBands(NULL, PERIOD_M15, g_period_112, gi_116, 0, PRICE_CLOSE, MODE_UPPER, 1); if (Bid < l_ibands_0 && l_ibands_8 - l_ibands_0 >= gi_120 * Point) return (1); if (Bid > l_ibands_8 && l_ibands_8 - l_ibands_0 >= gi_124 * Point) return (-1); return (0); } int BandsCheck2() { double l_ibands_0 = iBands(NULL, PERIOD_M15, g_period_112, gi_116, 0, PRICE_CLOSE, MODE_LOWER, 1); double l_ibands_8 = iBands(NULL, PERIOD_M15, g_period_112, gi_116, 0, PRICE_CLOSE, MODE_UPPER, 1); if (Bid > l_ibands_8 && l_ibands_8 - l_ibands_0 >= gi_128 * Point) return (1); if (Bid < l_ibands_0 && l_ibands_8 - l_ibands_0 >= gi_132 * Point) return (-1); return (0); } int start() { int li_0 = 0; if (SettingCheck() == 0) return (0); double ld_4 = MyCurrentOrders(6, MagicNumber); if (DayOfWeek() == 5 && Hour() >= gi_140 - 1 && ld_4 != 0.0) { MyOrderClose(); return (0); } li_0 = OrderCheck(); if (li_0 == 1 && ld_4 <= 0.0) { Print("新規買い"); if (ld_4 < 0.0) MyOrderClose(); MyOrderSend(OP_BUY); } else { if (li_0 == -1 && ld_4 >= 0.0) { Print("新規売り"); if (ld_4 > 0.0) MyOrderClose(); MyOrderSend(OP_SELL); } else { if (li_0 == 2 && ld_4 < 0.0) { Print("売り決済"); MyOrderClose(); } else { if (li_0 == -2 && ld_4 > 0.0) { Print("買い決済"); MyOrderClose(); } } } } return (0); } int MyOrderSend(int a_cmd_0) { double l_price_4; double l_price_12; double l_price_20; string l_comment_28; string ls_36; string ls_44; int l_error_56; int li_52 = GetTickCount(); while (true) { if (GetTickCount() - li_52 > 1000 * gi_108) { Print("OrderSend timeout. Check the experts log."); return (0); } if (IsTradeAllowed() == TRUE) { RefreshRates(); if (a_cmd_0 == OP_BUY) { l_price_4 = NormalizeDouble(Ask, Digits); if (StopLoss > 0) l_price_12 = NormalizeDouble(Ask - StopLoss * Point, Digits); else l_price_12 = 0; if (TakeProfit > 0) l_price_20 = NormalizeDouble(Ask + TakeProfit * Point, Digits); else l_price_20 = 0; l_comment_28 = "DreamGateFX_ZERO BUY"; if (OrderSend(Symbol(), a_cmd_0, Lots(), l_price_4, SlipPage, l_price_12, l_price_20, l_comment_28, MagicNumber, 0, Blue) != -1) { ls_36 = "DGFX_ZERO Buy Mail"; ls_44 = l_price_4 + " Buy"; MySendMail(ls_36, ls_44); MyPlaySound(); return (1); } } else { if (a_cmd_0 == OP_SELL) { l_price_4 = NormalizeDouble(Bid, Digits); if (StopLoss > 0) l_price_12 = NormalizeDouble(Bid + StopLoss * Point, Digits); else l_price_12 = 0; if (TakeProfit > 0) l_price_20 = NormalizeDouble(Bid - TakeProfit * Point, Digits); else l_price_20 = 0; l_comment_28 = "DreamGateFX_ZERO SELL"; if (OrderSend(Symbol(), a_cmd_0, Lots(), l_price_4, SlipPage, l_price_12, l_price_20, l_comment_28, MagicNumber, 0, Red) != -1) { ls_36 = "DGFX_ZERO Sell Mail"; ls_44 = l_price_4 + " Sell"; MySendMail(ls_36, ls_44); MyPlaySound(); return (1); } } } l_error_56 = GetLastError(); Print("[OrderSendError] : ", l_error_56, " ", ErrorDescription(l_error_56)); if (l_error_56 == 129/* INVALID_PRICE */) break; if (l_error_56 == 130/* INVALID_STOPS */) break; } Sleep(100); } return (0); } int MyOrderClose() { double l_price_0; string ls_8; string ls_16; int l_cmd_32; int l_error_40; int l_ticket_24 = 0; for (int l_pos_28 = 0; l_pos_28 < OrdersTotal(); l_pos_28++) { if (OrderSelect(l_pos_28, SELECT_BY_POS) == FALSE) break; if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; l_cmd_32 = OrderType(); if (l_cmd_32 == OP_BUY || l_cmd_32 == OP_SELL) { l_ticket_24 = OrderTicket(); break; } } if (l_ticket_24 == 0) return (0); int li_36 = GetTickCount(); while (true) { if (GetTickCount() - li_36 > 1000 * gi_108) { Print("OrderClose timeout. Check the experts log."); return (0); } if (IsTradeAllowed() == TRUE) { RefreshRates(); if (l_cmd_32 == OP_BUY) { l_price_0 = NormalizeDouble(Bid, Digits); if (OrderClose(l_ticket_24, OrderLots(), l_price_0, SlipPage, Green) == 1) { ls_8 = "DGFX_ZERO Close Mail"; ls_16 = l_price_0 + " Close"; MySendMail(ls_8, ls_16); MyPlaySound(); return (1); } } else { if (l_cmd_32 == OP_SELL) { l_price_0 = NormalizeDouble(Ask, Digits); if (OrderClose(l_ticket_24, OrderLots(), l_price_0, SlipPage, Green) == 1) { ls_8 = "DGFX_ZERO Close Mail"; ls_16 = l_price_0 + " Close"; MySendMail(ls_8, ls_16); MyPlaySound(); return (1); } } } l_error_40 = GetLastError(); Print("[OrderCloseError] : ", l_error_40, " ", ErrorDescription(l_error_40)); if (l_error_40 == 129/* INVALID_PRICE */) break; } Sleep(100); } return (0); } double MyCurrentOrders(int ai_0, int a_magic_4) { double ld_ret_8 = 0.0; for (int l_pos_16 = 0; l_pos_16 < OrdersTotal(); l_pos_16++) { if (OrderSelect(l_pos_16, SELECT_BY_POS) == FALSE) break; if (OrderSymbol() != Symbol() || OrderMagicNumber() != a_magic_4) continue; switch (ai_0) { case 0: if (OrderType() == OP_BUY) ld_ret_8 += OrderLots(); break; case 1: if (OrderType() == OP_SELL) ld_ret_8 -= OrderLots(); break; case 2: if (OrderType() == OP_BUYLIMIT) ld_ret_8 += OrderLots(); break; case 3: if (OrderType() == OP_SELLLIMIT) ld_ret_8 -= OrderLots(); break; case 4: if (OrderType() == OP_BUYSTOP) ld_ret_8 += OrderLots(); break; case 5: if (OrderType() == OP_SELLSTOP) ld_ret_8 -= OrderLots(); break; case 6: if (OrderType() == OP_BUY) ld_ret_8 += OrderLots(); if (OrderType() == OP_SELL) ld_ret_8 -= OrderLots(); break; case 7: if (OrderType() == OP_BUYLIMIT) ld_ret_8 += OrderLots(); if (OrderType() == OP_SELLLIMIT) ld_ret_8 -= OrderLots(); break; case 8: if (OrderType() == OP_BUYSTOP) ld_ret_8 += OrderLots(); if (OrderType() == OP_SELLSTOP) ld_ret_8 -= OrderLots(); break; case 9: if (OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP) ld_ret_8 += OrderLots(); if (OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP) ld_ret_8 -= OrderLots(); break; case 10: if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP) ld_ret_8 += OrderLots(); break; case 11: if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP) ld_ret_8 -= OrderLots(); break; case 12: if (OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP) ld_ret_8 += OrderLots(); if (OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP) ld_ret_8 -= OrderLots(); break; default: Print("[CurrentOrdersError] : Illegel order type(" + ai_0 + ")"); } if (ld_ret_8 != 0.0) break; } return (ld_ret_8); } int SettingCheck() { if (IsTradeAllowed() == FALSE) { Print("トレードが許可されていません"); return (0); } if (!IsTesting() && !IsDemo() && gs_216 != gs_200) { 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 (Leverage > gd_184) { MessageBox("レバレッジは", gd_184, "倍以下にして下さい"); Print("レバレッジは", gd_184, "倍以下にして下さい"); 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 (Leverage > 0.0) ld_ret_0 = NormalizeDouble(AccountFreeMargin() * Leverage / g_lotsize_176, 2); else ld_ret_0 = NormalizeDouble(Lots, 2); if (ld_ret_0 < g_minlot_160) ld_ret_0 = g_minlot_160; if (ld_ret_0 > g_maxlot_168) ld_ret_0 = g_maxlot_168; 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_160 = MarketInfo(Symbol(), MODE_MINLOT); g_maxlot_168 = MarketInfo(Symbol(), MODE_MAXLOT); g_lotsize_176 = MarketInfo(Symbol(), MODE_LOTSIZE); gd_184 = AccountLeverage(); gs_192 = WindowExpertName(); StringSplit(gs_192, "_", lsa_0); gs_200 = lsa_0[2]; g_acc_number_208 = AccountNumber(); string ls_4 = StringSubstr(g_acc_number_208, 3, 1); string ls_12 = StringSubstr(g_acc_number_208, 4, 1); gs_216 = StrToInteger(ls_4 + ls_12) * 2; if (SummerTime == TRUE) { gi_140++; gi_144++; gi_148++; } return (0); }