e-PassLevCCI-EMA

Author: Gentor, KimIV
Profit factor:
1.04
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Commodity channel index
0 Views
0 Downloads
0 Favorites
e-PassLevCCI-EMA
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                             e-PassLevCCI-EMA.mq4 |
//|                              Èäåÿ Gentor, ðåàëèçàöèÿ â ÌÒ4 KimIV |
//|                                              http://www.kimiv.ru |
//| Ôèêñàöèÿ ïðèáûëè â ïîðÿäêå ïðèîðèòåòà:                           |
//| 1. TrailingStop                                                  |
//| 2. TakeProfit                                                    |
//| 3. Ïî ñèãíàëó âûõîäà                                             |
//| Ôèëüòð EMA                                                       |
//+------------------------------------------------------------------+
#property copyright "Gentor, KimIV"
#property link      "http://www.kimiv.ru"
#define   MAGIC     20050822

//------- Âíåøíèå ïàðàìåòðû ------------------------------------------
extern double Lots          = 0.1;    // Ðàçìåð òîðãóåìîãî ëîòà
extern int    StopLoss      = 27;     // Ðàçìåð ôèêñèðîâàííîãî ñòîïà
extern bool   UseTakeProfit = True;   // Èñïîëüçîâàòü òýéê
extern int    TakeProfit    = 70;     // Ðàçìåð ôèêñèðîâàííîãî òýéêà
extern bool   UseTrailing   = False;  // Èñïîëüçîâàòü òðàë
extern int    TrailingStop  = 50;     // Ðàçìåð òðàëà
extern int    CCI_Period    = 18;     // Ïåðèîä CCI
extern int    EMA_Period    = 34;     // Ïåðèîä EMA
extern int    BarsForCheck  = 4;      // Êîëè÷åñòâî áàðîâ äëÿ ïðîâåðêè

//------- Ãëîáàëüíûå ïåðåìåííûå --------------------------------------
datetime OldBar;

//+------------------------------------------------------------------+
//| Ïðîâåðêà óñëîâèé îòêðûòèÿ ïîçèöèè                                |
//+------------------------------------------------------------------+
void CheckForOpen() {
  bool   PosExist=False;     // Åñòü îòêðûòàÿ ïîçèöèÿ ïî òåêóùåìó èíñòðóìåíòó
  double cci1, cci2, ema;
  double take;

  // Ïîèñê ïîçèöèé ïî òåêóùåìó èíñòðóìåíòó, îòêðûòûõ èìåííî ýòèì ñîâåòíèêîì
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
        PosExist=True;
      }
    }
  }

  // Íåò îòêðûòûõ ïîçèöèé.
  if (!PosExist) {
    // Ôèêñèðóåì çíà÷åíèÿ ÑÑÈ.
    cci1 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, 1);
    cci2 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, BarsForCheck);
    ema  = iMA (NULL, 0, EMA_Period, 0, MODE_EMA, PRICE_TYPICAL, 1);
    // Ñèãíàë íà ïîêóïêó.
    if (cci1>100 && cci2<-100 && ema>Close[1]) {
      if (UseTakeProfit) take = Ask+TakeProfit*Point;
      else take = 0;
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,take,"e-PassLevCCI",MAGIC,0,Blue);
      OldBar = Time[1];
      return;
    }
    // Ñèãíàë íà ïðîäàæó.
    if (cci1<-100 && cci2>100 && ema<Close[1]) {
      if (UseTakeProfit) take = Bid-TakeProfit*Point;
      else take = 0;
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,take,"e-PassLevCCI",MAGIC,0,Red);
      OldBar = Time[1];
      return;
    }
  }
}

//+------------------------------------------------------------------+
//| Ïðîâåðêà óñëîâèé çàêðûòèÿ ïîçèöèè                                |
//+------------------------------------------------------------------+
void CheckForClose() {
  bool fs=False;        // Ôëàã íàëè÷èÿ ñèãíàëà çàêðûòèÿ
  int  cci1, cci2;

  // Ôèêñèðóåì çíà÷åíèÿ ÑÑÈ.
  cci1 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, 1);
  cci2 = iCCI(NULL, 0, CCI_Period, PRICE_TYPICAL, 2);
  // Ñèãíàë íà çàêðûòèå ïîçèöèè.
  if (cci1*cci2<0 && OldBar!=Time[1]) fs = True;

  // Ïîèñê ïîçèöèé ïî òåêóùåìó èíñòðóìåíòó, îòêðûòûõ èìåííî ýòèì ñîâåòíèêîì
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
        if (OrderType()==OP_BUY && fs) {
          OrderClose(OrderTicket(), Lots, Bid, 3, Aqua);
          return;
        }
        if (OrderType()==OP_SELL && fs) {
          OrderClose(OrderTicket(), Lots, Ask, 3, Violet);
          return;
        }
      }
    }
  }
}

//+------------------------------------------------------------------+
//| Ñîïðîâîæäåíèå ïîçèöèè                                            |
//+------------------------------------------------------------------+
void TrailingPosition() {
  for (int i=0; i<OrdersTotal(); i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
        if (OrderType()==OP_BUY) {
          if ((Bid-OrderOpenPrice())>TrailingStop*Point) {
            if (OrderStopLoss()<Bid-TrailingStop*Point) {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),Blue);
              return;
            }
          }
        }
        if (OrderType()==OP_SELL) {
          if ((OrderOpenPrice()-Ask)>TrailingStop*Point) {
            if (OrderStopLoss()>Ask+TrailingStop*Point) {
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),Red);
              return;
            }
          }
        }
      }
    }
  }
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
void start() {
  CheckForOpen();
  if (UseTrailing) TrailingPosition();
  else if (!UseTakeProfit) CheckForClose();
}
//+------------------------------------------------------------------+

Profitability Reports

USD/CAD Oct 2024 - Jan 2025
1.04
Total Trades 14
Won Trades 4
Lost trades 10
Win Rate 28.57 %
Expected payoff 0.05
Gross Profit 19.92
Gross Loss -19.20
Total Net Profit 0.72
-100%
-50%
0%
50%
100%

Comments