ExpertClor_v01: Your Go-To Assistant EA for MetaTrader 5

Mike 2017.08.10 21:55 14 0 0
Attachments

Author of the ideaJohn Smith, author of the MQL5 codebarabashkakvn.

Meet your new trading buddy: ExpertClor_v01, an assistant Expert Advisor designed specifically for MetaTrader 5. This EA focuses solely on closing positions effectively.

ExpertClor_v01

With ExpertClor, you can rest easy knowing that your positions are automatically shifted to breakeven. The Stop Loss is calculated using the StopATR_auto indicator, and positions will be closed based on the crossover of two Moving Averages (MAs).

To get this EA up and running, make sure to place the compiled StopATR_auto indicator file in the following folder: MQL5\Indicators\Downloads:

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
...
//--- create handle of the indicator iCustom
   handle_iCustom=iCustom(m_symbol.Name(),TimeFrame,"Downloads\StopATR_auto",
                          CountBarsForAverage,
                          Target
                          );

While this Expert Advisor primarily focuses on closing positions, I've included a snippet of code to open new positions as well:

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(MQLInfoInteger(MQL_DEBUG) || MQLInfoInteger(MQL_PROFILER) || 
      MQLInfoInteger(MQL_TESTER) || MQLInfoInteger(MQL_OPTIMIZATION))
     {
      static long counter=-50;
      static bool trade_buy=true;

      if(counter==0)
         m_trade.Buy(m_symbol.LotsMin());
      else if(counter%1500==0)
        {
         if(RefreshRates())
           {
            if(trade_buy)
              {
               OpenBuy(m_symbol.LotsMin());
               trade_buy=false;
              }
            else
              {
               OpenSell(m_symbol.LotsMin());
               trade_buy=true;
              }
           }
         else
            counter=counter-9;
        }

      counter++;
     }
//---

This unit is only meant for testing or optimizing this Expert Advisor. A Buy or Sell is initiated after every 1,500 ticks.

List
Comments 0