Problem with First Order at market without signals

 

hello,

 

I'm trying to use this EA https://www.mql5.com/en/forum/2910/page1 

Why when I use the EA it open immediately a position and not wait for the first crossover?

 

How can fix it?

 

I want wait first crossover to open a new position 

 

Can you help me with the code? 

Expert Advisors: MQL5 Wizard - Trade Signals Based on Price Crossover with Moving Average Indicator
Expert Advisors: MQL5 Wizard - Trade Signals Based on Price Crossover with Moving Average Indicator
  • www.mql5.com
Expert Advisors: MQL5 Wizard - Trade Signals Based on Price Crossover with Moving Average Indicator.
 
TradingOnline:

hello,

 

I'm trying to use this EA https://www.mql5.com/en/forum/2910/page1 

Why when I use the EA it open immediately a position and not wait for the first crossover?

 

How can fix it?

 

I want wait first crossover to open a new position 

 

Can you help me with the code? 

 

 

You need to modify code inside signalma.mqh

bool CSignalMA::CheckOpenLong(double& price,double& sl,double& tp,datetime& expiration)
  {
   price=0.0;
   sl   =0.0;
   tp   =0.0;
//---
   return(StateOpen(1)<0 && StateClose(1)>0 && StateMA(1)>0);
  }
//+------------------------------------------------------------------+
//| Check conditions for long position close.                        |
//| INPUT:  price - refernce for price.                              |
//| OUTPUT: true-if condition performed, false otherwise.            |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CSignalMA::CheckCloseLong(double& price)
  {
   price=0.0;
//---
   return(StateOpen(1)>0 && StateClose(1)<0 && StateMA(1)<0);
  }
//+------------------------------------------------------------------+
//| Check conditions for short position open.                        |
//| INPUT:  price      - refernce for price,                         |
//|         sl         - refernce for stop loss,                     |
//|         tp         - refernce for take profit,                   |
//|         expiration - refernce for expiration.                    |
//| OUTPUT: true-if condition performed, false otherwise.            |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CSignalMA::CheckOpenShort(double& price,double& sl,double& tp,datetime& expiration)
  {
   price=0.0;
   sl   =0.0;
   tp   =0.0;
//---
   return(StateOpen(1)>0 && StateClose(1)<0 && StateMA(1)<0);
  }
//+------------------------------------------------------------------+
//| Check conditions for short position close.                       |
//| INPUT:  price - refernce for price.                              |
//| OUTPUT: true-if condition performed, false otherwise.            |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CSignalMA::CheckCloseShort(double& price)
  {
   price=0.0;
//---
   return(StateOpen(1)<0 && StateClose(1)>0 && StateMA(1)>0);
  }
//+------------------------------------------------------------------+

become (you can try this as another example of crossover MA)

bool CSignalMA::CheckOpenLong(double& price,double& sl,double& tp,datetime& expiration)
  {
   price=0.0;
   sl   =0.0;
   tp   =0.0;
//---
   return(StateOpen(2)<0 && StateOpen(1)>0 && StateClose(1)>0);
  }
//+------------------------------------------------------------------+
//| Check conditions for long position close.                        |
//| INPUT:  price - refernce for price.                              |
//| OUTPUT: true-if condition performed, false otherwise.            |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CSignalMA::CheckCloseLong(double& price)
  {
   price=0.0;
//---
   return(StateOpen(2)>0 && StateOpen(1)<0 && StateClose(1)<0);
  }
//+------------------------------------------------------------------+
//| Check conditions for short position open.                        |
//| INPUT:  price      - refernce for price,                         |
//|         sl         - refernce for stop loss,                     |
//|         tp         - refernce for take profit,                   |
//|         expiration - refernce for expiration.                    |
//| OUTPUT: true-if condition performed, false otherwise.            |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CSignalMA::CheckOpenShort(double& price,double& sl,double& tp,datetime& expiration)
  {
   price=0.0;
   sl   =0.0;
   tp   =0.0;
//---
   return(StateOpen(2)>0 && StateOpen(1)<0 && StateClose(1)<0);
  }
//+------------------------------------------------------------------+
//| Check conditions for short position close.                       |
//| INPUT:  price - refernce for price.                              |
//| OUTPUT: true-if condition performed, false otherwise.            |
//| REMARK: no.                                                      |
//+------------------------------------------------------------------+
bool CSignalMA::CheckCloseShort(double& price)
  {
   price=0.0;
//---
   return(StateOpen(2)<0 && StateOpen(1)>0 && StateClose(1)>0);
  }
//+------------------------------------------------------------------+
Reason: