e-BreakBBon3CCI

Author: ��� ����� �. aka KimIV
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Bollinger bands indicatorCommodity channel index
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
e-BreakBBon3CCI
//+------------------------------------------------------------------+
//|                                              e-BreakBBon3CCI.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);
  double cci0, cci1, cci2;
  int    nb1, nb2;
  int    cci=0;//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;

  nb1=iBarShift(NULL, TF_1, Time[0], False);
  nb2=iBarShift(NULL, TF_2, Time[0], False);

  cci0=iCCI(NULL, 0   , CCI_Period_0, PRICE_CLOSE, 1);
  cci1=iCCI(NULL, TF_1, CCI_Period_1, PRICE_CLOSE, nb1);
  cci2=iCCI(NULL, TF_2, CCI_Period_2, PRICE_CLOSE, nb2);

  if (cci0>Level_0 && cci1>Level_1 && cci2>Level_2) cci=1;
  if (cci0<-Level_0 && cci1<-Level_1 && cci2<-Level_2) cci=-1;

  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);
        }
      }
    }
  }
}
//+------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---