//+------------------------------------------------------------------+ //| e-NightTrade.mq4 | //| Ким Игорь В. aka KimIV | //| http://www.kimiv.ru | //| | //| 06.02.2006 Ночная торговля. | //+------------------------------------------------------------------+ #property copyright "Ким Игорь В. aka KimIV" #property link "http://www.kimiv.ru" //------- Внешние параметры советника -------------------------------- extern string _Parameters_Trade = "----- Параметры торговли"; extern int nDayOfWeek = 1; // Номер дня недели extern int HourOpenPos = 23; // Час открытия позиции extern int MinuteOpenPos = 0; // Минуты открытия позиции extern int DepthHistory = 14; // Глубина в барах extern int RangeCutOff = 19; // Диапазон отсечки extern int StopLoss = 68; // Размер стопа extern int TakeProfit = 25; // Размер тэйка extern bool UseClosePos = True; // Использовать закрытие позиции extern int HourClosePos = 3; // Час закрытия позиции //---- Глобальные переменные советника ------------------------------- double Lots = 0.1; int Slippage = 3; int MAGIC = 20060206; color clOpenBuy = LightBlue; color clOpenSell = LightCoral; color clCloseBuy = Blue; color clCloseSell = Red; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ void start() { if (DayOfWeek()==nDayOfWeek && Hour()==HourOpenPos && Minute()>=MinuteOpenPos && Minute()<=MinuteOpenPos+4) OpenPositions(); if (UseClosePos && Hour()==HourClosePos) CloseAllPositions(); } //+------------------------------------------------------------------+ //| Открытие позиций | //+------------------------------------------------------------------+ void OpenPositions() { double ldStop=0, ldTake=0; int bs=GetTradeSignal(); if (!ExistPosition()) { if (bs>0) { if (StopLoss!=0) ldStop=Ask-StopLoss*Point; if (TakeProfit!=0) ldTake=Ask+TakeProfit*Point; OpenPosition(OP_BUY, ldStop, ldTake); } if (bs<0) { if (StopLoss!=0) ldStop=Bid+StopLoss*Point; if (TakeProfit!=0) ldTake=Bid-TakeProfit*Point; OpenPosition(OP_SELL, ldStop, ldTake); } } } //+------------------------------------------------------------------+ //| Возвращает торговый сигнал: | //| 1 - покупай | //| 0 - сиди, кури бамбук | //| -1 - продавай | //+------------------------------------------------------------------+ int GetTradeSignal() { int nb, bs=0; nb=Highest(NULL, 0, MODE_HIGH, DepthHistory, 1); if (High[nb]-Close[1]>RangeCutOff*Point) { bs=1; } nb=Lowest(NULL, 0, MODE_LOW, DepthHistory, 1); if (Close[1]-Low[nb]>RangeCutOff*Point) { bs=-1; } return(bs); } //+------------------------------------------------------------------+ //| Возвращает флаг существования позиции | //+------------------------------------------------------------------+ bool ExistPosition() { bool Exist=False; for (int i=0; i=0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) { if (OrderType()==OP_BUY) { OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, clCloseBuy); } if (OrderType()==OP_SELL) { OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, clCloseSell); } } } } } //+------------------------------------------------------------------+