EA not parsing through tester

 

Hi guys,

I'm trying to code a simple EA to pick up a type of divergence from a custom indicator and need some help (new to mql4 programming, engineer in real life, so most likely just need some code snippets, as I'm most likely doing something wrong).

I'm using the iCustom function on the indi. Posting the declaration page underneath:


double          MacdBuffer[];
double          SignalBuffer[];
double          MacdHistBuffer[];
double          HistGUBuffer[], HistGDBuffer[];
double          HistRDBuffer[], HistRUBuffer[];
double          BullDivBuffer[], BearDivBuffer[];
double          typeOfTrade[];

//-----------------Global variables-------------------------------------------+
//---
input int       FastEMA         = 12;       // Fast EMA Period
input int       SlowEMA         = 26;       // Slow EMA Period
input int       SignalEMA       = 9;        // Signal SMA Period
input bool      ON_MACD         = true;     // MACD line
input bool      ON_SIGNAL       = true;     // Signal line
input string    SECTION1        = "===== Divergence parameters =====";//==========================
input bool      ON_DIVER_HIST   = true;    // MACD Histogram divergence indicator
input bool      ON_DIVER_LINE   = true;    // MACD Line divergence indicator
input bool      ON_CLASSIC      = true;     // Search classical
input bool      ON_HIDDEN       = false;     // Search hidden
input bool      ON_EXPAND       = false;     // Search extended
input bool      ON_TREND_LINES  = true;     // Show trend lines
input bool      ON_DIVER_SYMBOL = true;     // Show divergence indicator
input bool      ON_ALERT        = true;     // Show alerts
//---
const int       SEARCH_LEN      = 120;      // Lenght of peacks search
const int       SEARCH_LEN_Z    = 90;       // Lenght of zero check
//---
string          prefix          = "MASi_MACDHist";
string          indicatorName;
int tradeType;

//+---------------------------------------------------------------------------+
int OnInit()
{
    SetIndexBuffer( 0, MacdBuffer );
    SetIndexBuffer( 1, SignalBuffer );
    SetIndexBuffer( 2, MacdHistBuffer );
    SetIndexBuffer( 3, HistGUBuffer );
    SetIndexBuffer( 4, HistGDBuffer );
    SetIndexBuffer( 5, HistRDBuffer );
    SetIndexBuffer( 6, HistRUBuffer );
    if( ON_DIVER_HIST || ON_DIVER_LINE ) {
        SetIndexBuffer( 7, BullDivBuffer );
        SetIndexBuffer( 8, BearDivBuffer );
        SetIndexBuffer( 9, typeOfTrade   );


Then inside the EA I go ahead and use this :


input int      Pas=10;
input int      SL=150;
input string   SECTION1        = "===== Valoarea pasului e procentuala din cont ex. 10 = 10% risc per trade * 3 trades =====";//==========================
      double      typeOfTrade = 0; 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
if (Pas<0 || Pas >17)

   {  Print("Valoarea pasului trebuie sa fie intre 1 si 16.6");
   return(INIT_FAILED); }
   
   EventSetTimer(5);
   
//---
   return(INIT_SUCCEEDED);
  
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  typeOfTrade = iCustom(NULL, 0, "MASi_MACDHist_TType",12,26,9,1,1,1,1,1,0,0,1,1,1,9,1);
  
  if (typeOfTrade != 0)
  {
  Print("Primit tipul de tranzactie ", typeOfTrade);
      if (typeOfTrade == 1 && OrdersTotal() == 0)
      {  Buy();
         return;           }
       
      if (typeOfTrade == 2 && OrdersTotal() == 0)
      {  Sell(); 
         return;           }
      
      if (typeOfTrade != 0 || typeOfTrade != 1 || typeOfTrade !=2)
      {  typeOfTrade=0;
         return;           }
   }
  
  TrailingSL(SL);


Problem is whenever I go ahead and try to use the strategy tester to see some logic functioning, it just locks. It doesnt create any bars, nothing. Do you guys see any obvious problems?

 
  1. iCustom
     Indicator parameters
    iCustom(NULL, 0, "MASi_MACDHist_TType",
    12,
    26,
    9,
    1,  Not bool
    1,  Not bool
        string completely missing
    1,  not bool
    1,  :
    1,  :
    0,  :
    0,  :
    1,  :
    1,  :
    1,  not bool
    9,
    1);
    input int    FastEMA         = 12;    // Fast EMA Period
    input int    SlowEMA         = 26;    // Slow EMA Period
    input int    SignalEMA       = 9;     // Signal SMA Period
    input bool   ON_MACD         = true;  // MACD line
    input bool   ON_SIGNAL       = true;  // Signal line
    input string SECTION1        = "===== Divergence parameters ====="
    input bool   ON_DIVER_HIST   = true;  // MACD Histogram divergence indicator
    input bool   ON_DIVER_LINE   = true;  // MACD Line divergence indicator
    input bool   ON_CLASSIC      = true;  // Search classical
    input bool   ON_HIDDEN       = false; // Search hidden
    input bool   ON_EXPAND       = false; // Search extended
    input bool   ON_TREND_LINES  = true;  // Show trend lines
    input bool   ON_DIVER_SYMBOL = true;  // Show divergence indicator
    input bool   ON_ALERT        = true;  // Show alerts

    You should encapsulate your iCustom calls to make your code self-documenting.
              Detailed explanation of iCustom - MQL4 programming forum 2017.05.23
              iAlligator signal gone wrong - MQL4 programming forum #4.2 2017.06.15
              take candle color hekin ashi - MQL4 and MetaTrader 4 #8-9 or #1 2018.02.21

  2. AEne: Problem is whenever I go ahead and try to use the strategy tester to see some logic functioning, it just locks. It doesnt create any bars, nothing. Do you guys see any obvious problems?

    We can't "see any obvious problems" because you haven't posted all your code.
         How To Ask Questions The Smart Way. 2004
              Be precise and informative about your problem

  3. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?