#property copyright "Seichi Oda" #property link "http://dreamgatefx.com/top/" #include extern int MagicNumber = 20090830; extern double Lots = 0.1; extern double Leverage = 0.0; extern int SlipPage = 5; extern int StopLoss = 60; int gi_104 = 0; extern int TrailingStop = 14; int gi_unused_112 = 10; int gi_unused_116 = 40; int gi_unused_120 = 12; int gi_unused_124 = 26; int gi_unused_128 = 9; int g_period_132 = 19; int gi_136 = 2; int gi_140 = 15; int gi_144 = 15; int gi_148 = 15; int gi_152 = 15; extern bool SummerTime = FALSE; int gi_160 = 22; int gi_164 = 1; int gi_168 = 3; extern bool SoundFlag = FALSE; extern bool MailFlag = FALSE; double g_minlot_180; double g_maxlot_188; double g_lotsize_196; double g_leverage_204; string gs_unused_208; string gs_212; string gs_220; string g_acc_number_228; string gs_236; int init() { string lsa_0[]; HideTestIndicators(TRUE); g_minlot_180 = MarketInfo(Symbol(), MODE_MINLOT); g_maxlot_188 = MarketInfo(Symbol(), MODE_MAXLOT); g_lotsize_196 = MarketInfo(Symbol(), MODE_LOTSIZE); g_leverage_204 = AccountLeverage(); gs_212 = WindowExpertName(); StringSplit(gs_212, "_", lsa_0); gs_220 = lsa_0[2]; g_acc_number_228 = AccountNumber(); string ls_4 = StringSubstr(g_acc_number_228, 3, 1); string ls_12 = StringSubstr(g_acc_number_228, 4, 1); gs_236 = StrToInteger(ls_4 + ls_12) * 2; if (SummerTime == TRUE) { gi_160++; gi_164++; gi_168++; } return (0); } int start() { int l_cmd_20; double l_price_24; int l_slippage_32; double l_price_36; double l_price_44; string l_comment_60; color l_color_68; string ls_72; string ls_80; int li_88; int l_ticket_0 = 0; int li_4 = 0; int li_unused_8 = 0; int l_ticket_12 = 0; int l_error_16 = 0; if (TimeHour(TimeCurrent()) == gi_160 && TimeMinute(TimeCurrent()) == 0) li_88 = 0; if (SettingCheck() == 0) return (0); int li_92 = 0; for (int l_pos_96 = 0; l_pos_96 < OrdersTotal(); l_pos_96++) { if (OrderSelect(l_pos_96, SELECT_BY_POS, MODE_TRADES) == TRUE) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) { if (Bid - OrderOpenPrice() > TrailingStop * Point && OrderStopLoss() < Bid - TrailingStop * Point) { RefreshRates(); OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - TrailingStop * Point / 2.0, Digits), OrderTakeProfit(), 0, Green); li_92 = 1; } } if (OrderType() == OP_SELL) { if (OrderOpenPrice() - Ask > TrailingStop * Point && OrderStopLoss() > Ask + TrailingStop * Point) { RefreshRates(); OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStop * Point / 2.0, Digits), OrderTakeProfit(), 0, White); li_92 = -1; } } if (OrderType() == OP_BUY || OrderType() == OP_SELL) l_ticket_0 = OrderTicket(); if (OrderType() == OP_BUY || OrderType() == OP_SELL) l_ticket_0 = OrderTicket(); } } } if (li_92 != 0) return (0); if (l_ticket_0 != 0) { OrderSelect(l_ticket_0, SELECT_BY_TICKET); li_4 = OrderCheck(); if (OrderType() == OP_BUY && li_4 == -1 || li_4 == -2) { if (SoundFlag == TRUE) PlaySound("alert.wav"); if (li_4 == -1) Print("買い決済"); if (li_4 == -1) li_88 = -1; else if (li_4 == -2) Print("買い決済"); RefreshRates(); OrderClose(l_ticket_0, OrderLots(), NormalizeDouble(Bid, Digits), SlipPage, Green); Sleep(3000); l_ticket_0 = 0; l_error_16 = GetLastError(); if (l_error_16 > 0/* NO_ERROR */) { ToError(l_error_16); return (0); } ls_72 = "【DGFX】買い決済メール"; ls_80 = NormalizeDouble(Bid, Digits) + "で買い決済"; if (MailFlag == TRUE) SendMail(ls_72, ls_80); } else { if (OrderType() == OP_SELL && li_4 == 1 || li_4 == 2) { if (SoundFlag == TRUE) PlaySound("alert.wav"); if (li_4 == 1) Print("売り決済"); if (li_4 == 1) li_88 = 1; else if (li_4 == 2) Print("売り決済"); RefreshRates(); OrderClose(l_ticket_0, OrderLots(), NormalizeDouble(Ask, Digits), SlipPage, Green); Sleep(3000); l_ticket_0 = 0; l_error_16 = GetLastError(); if (l_error_16 > 0/* NO_ERROR */) { ToError(l_error_16); return (0); } ls_72 = "【DGFX】売り決済メール"; ls_80 = NormalizeDouble(Ask, Digits) + "で売り決済"; if (MailFlag == TRUE) SendMail(ls_72, ls_80); } } if (DayOfWeek() == 5 && Hour() >= gi_160 - 1 && l_ticket_0 != 0) { if (OrderType() == OP_BUY) { if (SoundFlag == TRUE) PlaySound("alert.wav"); Print("時間切れ買い決済"); RefreshRates(); OrderClose(l_ticket_0, OrderLots(), NormalizeDouble(Bid, Digits), SlipPage, Green); Sleep(3000); l_ticket_0 = 0; l_error_16 = GetLastError(); if (l_error_16 > 0/* NO_ERROR */) { ToError(l_error_16); return (0); } ls_72 = "【DGFX】時間切れ買い決済メール"; ls_80 = NormalizeDouble(Bid, Digits) + "で時間切れ買い決済"; if (MailFlag == TRUE) SendMail(ls_72, ls_80); } else { if (OrderType() == OP_SELL) { if (SoundFlag == TRUE) PlaySound("alert.wav"); Print("時間切れ売り決済"); RefreshRates(); OrderClose(l_ticket_0, OrderLots(), NormalizeDouble(Ask, Digits), SlipPage, Green); Sleep(3000); l_ticket_0 = 0; l_error_16 = GetLastError(); if (l_error_16 > 0/* NO_ERROR */) { ToError(l_error_16); return (0); } ls_72 = "【DGFX】時間切れ売り決済メール"; ls_80 = NormalizeDouble(Ask, Digits) + "で時間切れ売り決済"; if (MailFlag == TRUE) SendMail(ls_72, ls_80); } } } } if (l_ticket_0 == 0 && li_88 == 0) { li_4 = OrderCheck(); if (li_4 == 1) { Print("新規買い"); RefreshRates(); l_cmd_20 = 0; l_price_24 = NormalizeDouble(Ask, Digits); l_slippage_32 = SlipPage; if (StopLoss > 0) l_price_36 = NormalizeDouble(Ask - StopLoss * Point, Digits); else l_price_36 = 0; if (gi_104 > 0) l_price_44 = NormalizeDouble(Ask + gi_104 * Point, Digits); else l_price_44 = 0; l_comment_60 = "BUY"; l_color_68 = Blue; ls_72 = "【DGFX】新規買いメール"; ls_80 = NormalizeDouble(Ask, Digits) + "で新規買い"; } else { if (li_4 == -1) { Print("新規売り"); RefreshRates(); l_cmd_20 = 1; l_price_24 = NormalizeDouble(Bid, Digits); l_slippage_32 = SlipPage; if (StopLoss > 0) l_price_36 = NormalizeDouble(Bid + StopLoss * Point, Digits); else l_price_36 = 0; if (gi_104 > 0) l_price_44 = NormalizeDouble(Bid - gi_104 * Point, Digits); else l_price_44 = 0; l_comment_60 = "SELL"; l_color_68 = Red; ls_72 = "【DGFX】新規売りメール"; ls_80 = NormalizeDouble(Bid, Digits) + "で新規売り"; } } if (li_4 == 1 || li_4 == -1) { if (SoundFlag == TRUE) PlaySound("alert.wav"); l_ticket_12 = OrderSend(Symbol(), l_cmd_20, Lots(), l_price_24, l_slippage_32, l_price_36, l_price_44, l_comment_60, MagicNumber, 0, l_color_68); Sleep(3000); l_error_16 = GetLastError(); if (l_error_16 > 0/* NO_ERROR */) { ToError(l_error_16); return (0); } if (MailFlag == TRUE) SendMail(ls_72, ls_80); } } return (0); } int OrderCheck() { int li_0 = MA3Check(); int li_4 = MACDCheck(); int li_8 = BandsCheck(); int li_12 = BandsCheck2(); if (DayOfWeek() == 5 && Hour() >= gi_160) return (0); if (li_0 + li_4 + li_8 == 1) return (1); if (li_0 + li_4 + li_8 == -1) return (-1); if (li_0 + li_4 + li_12 == 1) return (2); if (li_0 + li_4 + li_12 == -1) return (-2); return (0); } 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_196, 2); else ld_ret_0 = NormalizeDouble(Lots, 2); if (ld_ret_0 < g_minlot_180) ld_ret_0 = g_minlot_180; if (ld_ret_0 > g_maxlot_188) ld_ret_0 = g_maxlot_188; return (ld_ret_0); } int MACDCheck() { return (0); } int MA3Check() { return (0); } int BandsCheck() { double l_ibands_0 = iBands(NULL, PERIOD_M15, g_period_132, gi_136, 0, PRICE_CLOSE, MODE_LOWER, 1); double l_ibands_8 = iBands(NULL, PERIOD_M15, g_period_132, gi_136, 0, PRICE_CLOSE, MODE_UPPER, 1); if (TimeHour(TimeCurrent()) >= gi_160 || TimeHour(TimeCurrent()) <= gi_164 && Bid < l_ibands_0 && l_ibands_8 - l_ibands_0 >= gi_140 * Point) return (1); if (TimeHour(TimeCurrent()) >= gi_160 || TimeHour(TimeCurrent()) <= gi_164 && Bid > l_ibands_8 && l_ibands_8 - l_ibands_0 >= gi_144 * Point) return (-1); return (0); } int BandsCheck2() { double l_ibands_0 = iBands(NULL, PERIOD_M15, g_period_132, gi_136, 0, PRICE_CLOSE, MODE_LOWER, 1); double l_ibands_8 = iBands(NULL, PERIOD_M15, g_period_132, gi_136, 0, PRICE_CLOSE, MODE_UPPER, 1); if (TimeHour(TimeCurrent()) == gi_168 && Bid > l_ibands_8 && l_ibands_8 - l_ibands_0 >= gi_148 * Point) return (1); if (TimeHour(TimeCurrent()) == gi_168 && Bid < l_ibands_0 && l_ibands_8 - l_ibands_0 >= gi_152 * Point) return (-1); return (0); } void ToError(int ai_0) { Alert("エラーが発生しました。詳細はExpertsを参照下さい"); Print("error(", ai_0, "): ", ErrorDescription(ai_0)); Comment("error(", ai_0, "): ", ErrorDescription(ai_0)); } int SettingCheck() { if (IsTradeAllowed() == FALSE) { Print("トレードを許可して下さい"); return (0); } if (!IsTesting() && !IsDemo() && gs_236 != gs_220) { 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 > g_leverage_204) { MessageBox("レバレッジは", g_leverage_204, "倍以下にして下さい"); Print("レバレッジは", g_leverage_204, "倍以下にして下さい"); return (0); } return (1); } 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 deinit() { return (0); }