Time: 2015-01-05 | Download file:e-BreakBBon3CCIc-iCustom().mq4
//+------------------------------------------------------------------+ //| e-BreakBBon3CCIc.mq4 | //| Ким Игорь В. aka KimIV | //| http://www.kimiv.ru | //| | //| 09.01.2006 Пробой Bollinger Bands по сигналу от i-3CCI-h.mq4. | //+------------------------------------------------------------------+ #property copyright "Ким Игорь В. aka KimIV" #property link "http://www.kimiv.ru" #define MAGIC 20060109 //------- Внешние параметры советника -------------------------------- extern string _P1 = "----------- Параметры Bollinger Bands"; extern int BB_Period = 20; // Период BB extern int BB_Deviation = 2; // Отклонение BB extern double WidthChannel = 30; // Ширина канала BB extern string _P2 = "----------- Параметры 3CCI"; extern int CCI_Period_0 = 14; // Период CCI для текущего ТФ extern int Level_0 = 100; // Уровень CCI для текущего ТФ extern int TF_1 = 60; // Количество минут первого ТФ extern int CCI_Period_1 = 14; // Период CCI для первого ТФ extern int Level_1 = 100; // Уровень CCI для первого ТФ extern int TF_2 = 240; // Количество минут второго ТФ extern int CCI_Period_2 = 14; // Период CCI для второго ТФ extern int Level_2 = 100; // Уровень CCI для второго ТФ extern string _P3 = "----------- Параметры торговли"; extern int HourClosePos = 22; // Час закрытия позиций extern int StopLoss = 30; extern int TakeProfit = 85; //---- Глобальные переменные советника ------------------------------- double Lots = 0.1; int Slippage = 3; color clOpenBuy = LightBlue; color clOpenSell = LightCoral; color clModifyBuy = Aqua; color clModifySell = Tomato; color clCloseBuy = Blue; color clCloseSell = Red; int prevTimeBar; void deinit() { Comment(""); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ void start() { if (prevTimeBar!=Time[0]) OpenPositions(); if (Hour()==HourClosePos) CloseAllPositions(); prevTimeBar=Time[0]; } //+------------------------------------------------------------------+ //| Открытие позиций | //+------------------------------------------------------------------+ 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); } } } //+------------------------------------------------------------------+ //| Возвращает торговый сигнал | //+------------------------------------------------------------------+ int GetTradeSignal() { double bu1=iBands(NULL,0,BB_Period,BB_Deviation,0,PRICE_CLOSE,MODE_UPPER,2); double bd1=iBands(NULL,0,BB_Period,BB_Deviation,0,PRICE_CLOSE,MODE_LOWER,1); int cci=iCustom(NULL,0,"i-3CCI-h",CCI_Period_0,Level_0,TF_1,CCI_Period_1,Level_1,TF_2,CCI_Period_2,Level_2,0,0); int bs=0; if (bu1-bd10) bs=1; if (cci<0) 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); } } } } } //+------------------------------------------------------------------+