extern string explanationTT = "取引時間"; extern int starthour = 0; extern int endhour = 24; extern string explanationCT = "強制終了の時間"; extern int closehour = -1; extern int closeminute = 30; extern double Lots = 0.1; extern int StopLoss = 60; extern int TakeProfit = 0; extern int Trailling = 0; extern int Magic = 219426; extern string Indicator_Setting = "---------- Indicator Setting"; extern int TimeFrame = 0; extern int Length = 5; extern int Method = 3; extern int Smoothing = 1; extern int Filter = 5; extern string explanationSignshift = "シグナル確定のみの場合はsignshift=1"; extern int signshift = 1; int g_bars_172; int gi_176; int g_bars_180; int init() { return (0); } int deinit() { return (0); } int start() { double l_lots_72; double l_price_80; double l_price_88; if (IsTesting() != TRUE) { Alert("I am for testing"); return (0); } double l_ima_0 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_HIGH, signshift); double l_ima_8 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_LOW, signshift); double l_ima_16 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_OPEN, signshift); double l_ima_24 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_CLOSE, signshift); double l_ima_32 = iMA(NULL, TimeFrame, Length, 0, Method, PRICE_CLOSE, signshift + Smoothing); double ld_40 = MathAbs(((l_ima_24 - l_ima_32) / MathMax(l_ima_0 - l_ima_8, MathMax(l_ima_0 - l_ima_32, l_ima_32 - l_ima_8)) + (l_ima_24 - l_ima_16) / (l_ima_0 - l_ima_8)) / 2.0) * ((l_ima_24 - l_ima_32 + (l_ima_24 - l_ima_16)) / 2.0); double l_iclose_56 = iClose(NULL, TimeFrame, 2); double ld_48 = l_iclose_56 + ld_40; if (Filter > 0) if (MathAbs(ld_48 - l_iclose_56) < Filter * Point) ld_48 = l_iclose_56; if (gi_176 != 1 && g_bars_180 != Bars && ld_48 > l_iclose_56) { gi_176 = 1; g_bars_180 = Bars; } if (gi_176 != -1 && g_bars_180 != Bars && ld_48 < l_iclose_56) { gi_176 = -1; g_bars_180 = Bars; } int l_pos_64 = -1; for (int l_pos_68 = OrdersTotal() - 1; l_pos_68 >= 0; l_pos_68--) { OrderSelect(l_pos_68, SELECT_BY_POS); if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) l_pos_64 = l_pos_68; } if (l_pos_64 < 0) { if (starthour <= endhour) if (TimeHour(TimeCurrent()) < starthour || TimeHour(TimeCurrent()) >= endhour) return (0); if (starthour > endhour) if (TimeHour(TimeCurrent()) >= endhour && TimeHour(TimeCurrent()) < starthour) return (0); l_lots_72 = Lots; if (g_bars_172 != Bars && g_bars_180 == Bars && gi_176 == 1) { if (TakeProfit > 0) l_price_80 = Ask + TakeProfit * Point; else l_price_80 = 0; if (StopLoss > 0) l_price_88 = Ask - StopLoss * Point; else l_price_88 = 0; if (OrderSend(Symbol(), OP_BUY, l_lots_72, Ask, 3, l_price_88, l_price_80, "", Magic, 0, Blue) > 0) g_bars_172 = Bars; } if (g_bars_172 != Bars && g_bars_180 == Bars && gi_176 == -1) { if (TakeProfit > 0) l_price_80 = Bid - TakeProfit * Point; else l_price_80 = 0; if (StopLoss > 0) l_price_88 = Bid + StopLoss * Point; else l_price_88 = 0; if (OrderSend(Symbol(), OP_SELL, l_lots_72, Bid, 3, l_price_88, l_price_80, "", Magic, 0, Red) > 0) g_bars_172 = Bars; } } else { OrderSelect(l_pos_64, SELECT_BY_POS); if ((OrderType() == OP_BUY && g_bars_180 == Bars && gi_176 == -1) || (OrderType() == OP_SELL && g_bars_180 == Bars && gi_176 == 1) || (TimeHour(TimeCurrent()) == closehour && TimeMinute(TimeCurrent()) >= closeminute)) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0, Black); if (Trailling != 0 && OrderType() == OP_SELL) { if (Ask < OrderOpenPrice() - Trailling * Point && OrderStopLoss() > Ask + Trailling * Point || OrderStopLoss() == 0.0) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Trailling * Point, OrderTakeProfit(), 0, Purple); return (0); } } if (Trailling != 0 && OrderType() == OP_BUY) { if (Bid > OrderOpenPrice() + Trailling * Point && OrderStopLoss() < Bid - Trailling * Point) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Trailling * Point, OrderTakeProfit(), 0, Yellow); return (0); } } } return (0); }