//+------------------------------------------------------------------+ //| 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-bd1<WidthChannel*Point) { if (cci>0) bs=1; if (cci<0) bs=-1; } return(bs); } //+------------------------------------------------------------------+ //| Âîçâðàùàåò ôëàã ñóùåñòâîâàíèÿ ïîçèöèè ïî íîìåðó | //+------------------------------------------------------------------+ bool ExistPosition() { bool Exist=False; for (int i=0; i<OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) { if (OrderType()==OP_BUY || OrderType()==OP_SELL) { Exist=True; break; } } } } return(Exist); } //+------------------------------------------------------------------+ //| Îòêðûòèå ïîçèöèè | //| Ïàðàìåòðû: | //| op - îïåðàöèÿ | //| ldStop - óðîâåíü ñòîï | //| ldTake - óðîâåíü òåéê | //+------------------------------------------------------------------+ void OpenPosition(int op, double ldStop, double ldTake) { color clOpen; double pp; if (op==OP_BUY) { clOpen=clOpenBuy; pp=Ask; } else { clOpen=clOpenSell; pp=Bid; } OrderSend(Symbol(),op,Lots,pp,Slippage,ldStop,ldTake,"",MAGIC,0,clOpen); } //+------------------------------------------------------------------+ //| Çàêðûòèå âñåõ ïîçèöèé ïî ðûíî÷íîé öåíå | //+------------------------------------------------------------------+ void CloseAllPositions() { for (int i=OrdersTotal()-1; 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); } } } } } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Bollinger bands indicator
Custom Indicators Used:
i-3CCI-h
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself
Other Features: