Download MetaTrader 5

Problem with First Order at market without signals

To add comments, please log in or register
Do you know that MQL5 has classes?
Lorenzo Sentino
261
Lorenzo Sentino 2012.11.09 21:20 

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.
Achmad Hidayat
14766
Achmad Hidayat 2012.11.16 11:52  
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);
  }
//+------------------------------------------------------------------+
To add comments, please log in or register