ea not recognizing entries signals

 

What am I doing wrong?

//+--- MQL data -----------------------------------------------------+
MqlRates eaRates[];
//+--- inputs -------------------------------------------------------+
extern double eaVolume = 0; // Expert trading volume value!
extern double eaTake = 0; // Expert take profit level value!
extern double eaLoss = 0; // Expert stop loss level value!
extern ENUM_MA_METHOD maOneMethod = MODE_SMA; // 1st MA's method!
extern ENUM_MA_METHOD maTwoMethod = MODE_SMA; // 2nd MA's method! 
extern ENUM_APPLIED_PRICE maOneApp= PRICE_CLOSE; // 1st MA's price! 
extern ENUM_APPLIED_PRICE maTwoApp= PRICE_CLOSE; // 2nd MA's pri!
extern int maOnePeriod = 5; // 1st MA's period!
extern int maOneShift = 0; // 1st MA's shift!
extern int maTwoPeriod = 20; // 2nd MA's period!
extern int maTwoShift = 0; // 2nd MA's shift!
//+--- handles ------------------------------------------------------+
double lastMAone;
double lastMAtwo;
double currentMAone;
double currentMAtwo;

//+------------------------------------------------------------------+
//| on init expert function                                          |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creating a timer!
EventSetTimer(Period());
//--- returning a value ! -------------------------------------------+
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| timer ea function                                                |
//+------------------------------------------------------------------+
void OnTimer()
  {
//--- getting ea Rates
CopyRates(Symbol(),Period(),0,3,eaRates);
//--- getting ea long prices
double buyPrice = NormalizeDouble(Ask,Digits);
double buyTake = eaTake*Point;
double buyLoss = eaLoss*Point;
//--- getting ea short prices
double sellPrice = NormalizeDouble(Bid,Digits); 
double sellTake = eaTake*Point;
double sellLoss = eaLoss*Point;
//--- getting take and loss conditionals 
if(eaTake == 0)
  {
buyTake = NULL;
sellTake = NULL; 
  }
if(eaLoss == 0)
  {
buyLoss = NULL;
sellLoss = NULL;
  }
//--- conditionals for entries --------------------------------------+
if((lastMAone <= lastMAtwo) && (currentMAone >= currentMAtwo))
  {
Alert("Buy!");
  }
  }

Detail: I didn't put real trading entries, but only Alert to see if it works, and nothing!

 
Marcos Gomes Artischeff: What am I doing wrong?

Detail: I didn't put real trading entries, but only Alert to see if it works, and nothing!

double lastMAone;
double lastMAtwo;
double currentMAone;
double currentMAtwo;
⋮
void OnTimer()
  {
⋮
if((lastMAone <= lastMAtwo) && (currentMAone >= currentMAtwo))

Your variables have random values. Why do you think your condition will ever be true?

 
William Roeder:

Your variables have random values. Why do you think your condition will ever be true?

Thank you for you answer, but I gave values to then using iMA in another time and no working.
 
Marcos Gomes Artischeff:
Thank you for you answer, but I gave values to then using iMA, not?

No, you didn't. Not in the code that you have shown.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

 
Keith Watford:

No, you didn't. Not in the code that you have shown.


Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I will move your topic to the MQL4 and Metatrader 4 section.

Sorry for the mistake, I mean I rewrote the code, but forget right now to reorder, it looked different, but even with iMA and 2 for last and 1 for current candles, not working.
 
Marcos Gomes Artischeff:
Sorry for the mistake, I mean I rewrote the code, but forget right now to reorder, it looked different, but even with iMA and 2 for last and 1 for current candles, not working.

Show the code.

 
Keith Watford:

Show the code.

//+--- MQL data -----------------------------------------------------+
MqlRates eaRates[];
//+--- inputs -------------------------------------------------------+
extern double eaVolume = 0; // Expert trading volume value!
extern double eaTake = 0; // Expert take profit level value!
extern double eaLoss = 0; // Expert stop loss level value!
extern ENUM_MA_METHOD maOneMethod = MODE_SMA; // 1st MA's method!
extern ENUM_MA_METHOD maTwoMethod = MODE_SMA; // 2nd MA's method! 
extern ENUM_APPLIED_PRICE maOneApp= PRICE_CLOSE; // 1st MA's price! 
extern ENUM_APPLIED_PRICE maTwoApp= PRICE_CLOSE; // 2nd MA's pri!
extern int maOnePeriod = 5; // 1st MA's period!
extern int maOneShift = 0; // 1st MA's shift!
extern int maTwoPeriod = 20; // 2nd MA's period!
extern int maTwoShift = 0; // 2nd MA's shift!
//+--- handles ------------------------------------------------------+
double lastMAone = iMA(Symbol(),Period(),maOnePeriod,maOneShift,
maOneMethod,maOneApp,2);
double lastMAtwo = iMA(Symbol(),Period(),maTwoPeriod,maTwoShift,
maTwoMethod,maTwoApp,2);
double currentMAone = iMA(Symbol(),Period(),maOnePeriod,maOneShift,
maOneMethod,maOneApp,1);
double currentMAtwo = iMA(Symbol(),Period(),maTwoPeriod,maTwoShift,
maTwoMethod,maTwoApp,1);

//+------------------------------------------------------------------+
//| on init expert function                                          |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- creating a timer!
EventSetTimer(Period());
//--- returning a value ! -------------------------------------------+
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| timer ea function                                                |
//+------------------------------------------------------------------+
void OnTimer()
  {
//--- getting ea Rates
CopyRates(Symbol(),Period(),0,3,eaRates);
//--- getting ea long prices
double buyPrice = NormalizeDouble(Ask,Digits);
double buyTake = eaTake*Point;
double buyLoss = eaLoss*Point;
//--- getting ea short prices
double sellPrice = NormalizeDouble(Bid,Digits); 
double sellTake = eaTake*Point;
double sellLoss = eaLoss*Point;
//--- getting take and loss conditionals 
if(eaTake == 0)
  {
buyTake = NULL;
sellTake = NULL; 
  }
if(eaLoss == 0)
  {
buyLoss = NULL;
sellLoss = NULL;
  }
//--- conditionals for entries --------------------------------------+
if((lastMAone < lastMAtwo) && (currentMAone >= currentMAtwo))
  {
Alert("Buy!");
  }
  }
 
double lastMAone = iMA(Symbol(),Period(),maOnePeriod,maOneShift,
maOneMethod,maOneApp,2);
double lastMAtwo = iMA(Symbol(),Period(),maTwoPeriod,maTwoShift,
maTwoMethod,maTwoApp,2);
double currentMAone = iMA(Symbol(),Period(),maOnePeriod,maOneShift,
maOneMethod,maOneApp,1);
double currentMAtwo = iMA(Symbol(),Period(),maTwoPeriod,maTwoShift,
maTwoMethod,maTwoApp,1);

These should be in OnTimer(), not globalscope.

 
//--- creating a timer!
EventSetTimer(Period());

Why are you using Period() ??

 
Period() for use the current timeframe and... even on OnTimer not working.
 

Looks like this now, but not working yet.

//+--- MQL data -----------------------------------------------------+
MqlRates eaRates[];
//+--- inputs -------------------------------------------------------+
extern double eaVolume = 0; // Expert trading volume value!
extern double eaTake = 0; // Expert take profit level value!
extern double eaLoss = 0; // Expert stop loss level value!
extern ENUM_MA_METHOD maOneMethod = MODE_SMA; // 1st MA's method!
extern ENUM_MA_METHOD maTwoMethod = MODE_SMA; // 2nd MA's method! 
extern ENUM_APPLIED_PRICE maOneApp= PRICE_CLOSE; // 1st MA's price! 
extern ENUM_APPLIED_PRICE maTwoApp= PRICE_CLOSE; // 2nd MA's pri!
extern int maOnePeriod = 5; // 1st MA's period!
extern int maOneShift = 0; // 1st MA's shift!
extern int maTwoPeriod = 20; // 2nd MA's period!
extern int maTwoShift = 0; // 2nd MA's shift!
double firstMAone = INVALID_HANDLE;
double firstMAtwo = INVALID_HANDLE;
double secondMAone = INVALID_HANDLE;
double secondMAtwo = INVALID_HANDLE;
double currentMAone = INVALID_HANDLE;
double currentMAtwo = INVALID_HANDLE;
//+------------------------------------------------------------------+
//| on init expert function                                          |
//+------------------------------------------------------------------+
int OnInit()
  {
//+--- handles ------------------------------------------------------+
firstMAone = iMA(Symbol(),Period(),maOnePeriod,maOneShift,
maOneMethod,maOneApp,1);
firstMAtwo = iMA(Symbol(),Period(),maTwoPeriod,maTwoShift,
maTwoMethod,maTwoApp,1);
secondMAone = iMA(Symbol(),Period(),maOnePeriod,maOneShift,
maOneMethod,maOneApp,2);
secondMAtwo = iMA(Symbol(),Period(),maTwoPeriod,maTwoShift,
maTwoMethod,maTwoApp,2);
currentMAone = iMA(Symbol(),Period(),maOnePeriod,maOneShift,
maOneMethod,maOneApp,0);
currentMAtwo = iMA(Symbol(),Period(),maTwoPeriod,maTwoShift,
maTwoMethod,maTwoApp,0);

//--- creating a timer!
EventSetTimer(Period());
//--- returning a value ! -------------------------------------------+
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| timer ea function                                                |
//+------------------------------------------------------------------+
void OnTimer()
  {
//--- getting ea Rates
CopyRates(Symbol(),Period(),0,3,eaRates);
//--- getting ea long prices
double buyPrice = NormalizeDouble(Ask,Digits);
double buyTake = eaTake*Point;
double buyLoss = eaLoss*Point;
//--- getting ea short prices
double sellPrice = NormalizeDouble(Bid,Digits); 
double sellTake = eaTake*Point;
double sellLoss = eaLoss*Point;
//--- getting take and loss conditionals 
if(eaTake == 0)
  {
buyTake = NULL;
sellTake = NULL; 
  }
if(eaLoss == 0)
  {
buyLoss = NULL;
sellLoss = NULL;
  }
//--- conditionals for entries --------------------------------------+
if((secondMAone < secondMAtwo) && (firstMAone > firstMAtwo) && (currentMAone > currentMAtwo))
  {
Alert("Buy!");
  }
  }
Reason: