e-PassLevCCI-EMA

Author: Gentor, KimIV
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

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

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 ---