Download MetaTrader 5

EA based on two crosses any advice??

To add comments, please log in or register
rooster44
157
rooster44  

Hello,

I was wondering if any of you had suggestions for how I should implement my cross strategy.

I've written the beginning stages of it, but need a push in the right direction or even better some examples.

My idea was to create an Expert Advisor that traded on a 1hr. chart with the cross of the MACD greater than .0003 or less than .0003 and checked it with a cross in the Alligator indicator (on a 15min interval??). It would go long when MACD crossed above .0003 and was confirmed by a cross in the Alligator. Vice Versa for a short.

Here is the basic framework, which has errors that seem odd and unfixable.

The signals used for the alligator can be found here:  https://www.mql5.com/en/code/267

//+---------------+
//|   Include     |
//+---------------+
#include <Expert\Expert.mqh>
#include <Indicators\BillWilliams.mqh>
#include <Indicators\Oscilators.mqh>
#include <Expert\Trailing\TrailingNone.mqh>
#include <Expert\Signal\SignalAlligator.mqh>
#include <Expert\Signal\SignalMACD.mqh>
#include <Expert\Money\MoneyFixedRisk.mqh>

//--- input for expert
input string      Expert_title            ="IMAG";
ulong             Expert_MagicNumber      =4432;
bool              Expert_EveryTick        =false;

//--- input for Alligator signal
input int                Inp_Signal_Alligator_JawPeriod   =13;
input int                Inp_Signal_Alligator_JawShift    =8;
input int                Inp_Signal_Alligator_TeethPeriod =8;
input int                Inp_Signal_Alligator_TeethShift  =5;
input int                Inp_Signal_Alligator_LipsPeriod  =5;
input int                Inp_Signal_Alligator_LipsShift   =3;
input ENUM_MA_METHOD     Inp_Signal_Alligator_MaMethod    =MODE_SMMA;
input ENUM_APPLIED_PRICE Inp_Signal_Alligator_Applied     =PRICE_MEDIAN;
input int                Inp_Signal_Alligator_CrossMeasure=5; 

//--- input for MACD signal
input int                Inp_Signal_MACD_PeriodFast       =12;
input int                Inp_Signal_MACD_PeriodSlow       =24;
input int                Inp_Signal_MACD_PeriodSignal     =9;
input int                Inp_Signal_MACD_TakeProfit       =110;
input ENUM_APPLIED_PRICE Inp_Signal_MACD_Applied          =PRICE_CLOSE

//--- input for money
input double Money_FixRisk_Percent=10.0;

//+--------------+
//|Global Expert |
//+--------------+
CExpert ExtExpert; 

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))  
      {
       //--- failed
       printf(__FUNCTION__+": error initializing expert");
       ExtExpert.Deinit();
       return(-1);
       }
//--- Creation of Alligator Signal stuff
   CSignalAlligator *signal=new CSignalAlligator;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(-2);
     }
//--- Add signal to expert (will be deleted automatically))
   if(!ExtExpert.InitSignal(signal))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing signal");
      ExtExpert.Deinit();
      return(-3);
     }
//--- Set Alligator signal parameters
   signal.JawPeriod(Inp_Signal_Alligator_JawPeriod);
   signal.JawShift(Inp_Signal_Alligator_JawShift);
   signal.TeethPeriod(Inp_Signal_Alligator_TeethPeriod);
   signal.TeethShift(Inp_Signal_Alligator_TeethShift);
   signal.LipsPeriod(Inp_Signal_Alligator_LipsPeriod);
   signal.LipsShift(Inp_Signal_Alligator_LipsShift);
   signal.MaMethod(Inp_Signal_Alligator_MaMethod);
   signal.Applied(Inp_Signal_Alligator_Applied);
   signal.CrossMeasure(Inp_Signal_Alligator_CrossMeasure);
   
//--- Creation of MACD signal stuff
   CSignalMACD *signal=new CSignalMACD;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(-4);

///--- Add signal to expert
      if(!ExtExpert.InitSignal(signal))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing signal");
      ExtExpert.Deinit();
      return(-5);    
      
///--- MACD signal parameters
    signal.PeriodFast(Inp_Signal_MACD_PeriodFast);
    signal.PeriodSlow(Inp_Signal_MACD_PeriodSlow);
    signal.PeriodSignal(Inp_Signal_MACD_PeriodSignal);
    signal.Applied(Inp_Signal_MACD_Applied);
    signal.TakeProfit(Inp_Signal_MACD_TakeProfit);
      
//--- Check signal parameters
   if(!signal.ValidationSettings())
     {
      //--- failed
      printf(__FUNCTION__+": error signal parameters");
      ExtExpert.Deinit();
      return(-6);
     }
//--- Creation of trailing object
   CTrailingNone *trailing=new CTrailingNone;
   if(trailing==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating trailing");
      ExtExpert.Deinit();
      return(-7);
     }
//--- Add trailing to expert (will be deleted automatically))
   if(!ExtExpert.InitTrailing(trailing))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing trailing");
      ExtExpert.Deinit();
      return(-8);
     }
//--- Set trailing parameters
//--- Check trailing parameters
   if(!trailing.ValidationSettings())
     {
      //--- failed
      printf(__FUNCTION__+": error trailing parameters");
      ExtExpert.Deinit();
      return(-9);
     }
//--- Creation of money object
   CMoneyFixedRisk *money=new CMoneyFixedRisk;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(-10);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(-11);
     }
//--- Set money parameters
   money.Percent(Inp_Money_FixRisk_Percent);

//--- Check money parameters
   if(!money.ValidationSettings())
     {
      //--- failed
      printf(__FUNCTION__+": error money parameters");
      ExtExpert.Deinit();
      return(-12);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(-13);
     }

//--- create timer
   EventSetTimer(60);
      

   return(0);
   
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Trade function                                                   |
//+------------------------------------------------------------------+
void OnTrade()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---

//---
   return(ret);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| BookEvent function                                               |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
  {
//---
   
  }
//+------------------------------------------------------------------+
MQL5 Wizard - Trade Signals Based on Crossover of Lines of the Alligator Indicator
  • votes: 6
  • 2011.01.14
  • MetaQuotes Software Corp. | English Russian Chinese Spanish Portuguese
  • www.mql5.com
Trade signals based on crossover of lines of the Alligator technical indicator (CSignalAlligator from MQL5 Standard Library) is considered. The code of the Expert Advisor based on this strategy can be generated automatically using the MQL5 Wizard.
To add comments, please log in or register