Download MetaTrader 5
To add comments, please log in or register
Find out how to use widgets at MQL5.community
Steve_o
34
Steve_o 2015.12.13 22:35 

Hi all,

Trying to catch a price to execute a trade when I'm not far from the EMA using GoodPrice function below

but with no success. what am I'm doing wrong here?

Thank you!!! 

//+------------------------------------------------------------------+ 

extern double FarFromAverage = 1;

//+------------------------------------------------------------------+

int OnInit()

  {

//---

  double ticksize = MarketInfo(Symbol(),MODE_TICKSIZE);

         if (ticksize == 0.00001 || ticksize == 0.001)

         pips = ticksize*10;

         else pips = ticksize;

  

//---

  } 

//+------------------------------------------------------------------+ 

bool GoodPrice (){

double Average = iMA (Symbol(), 0, FastMA, 0, MODE_EMA, 3, 0);

if (Ask - Average<FarFromAverage*pips)

   return (true);

      else return (false);

      }       
Keith Watford
Moderator
7904
Keith Watford 2015.12.13 22:55  

Please use the SRC button when posing code, I've done it for you this time.

if (Ask - Average<FarFromAverage*pips)

 if Ask is below the EMA then Ask-Average will be a negative number, so it will be true whatever the distance

if (MathAbs(Ask - Average)<FarFromAverage*pips)

 Using MathAbs should do as you want

Steve_o
34
Steve_o 2015.12.14 20:03  
GumRai:

Please use the SRC button when posing code, I've done it for you this time.

 if Ask is below the EMA then Ask-Average will be a negative number, so it will be true whatever the distance

 Using MathAbs should do as you want

Thank you very much GumRai.

The Issue I'm expiriencing is that I'm opening a trades with prices that are far from the EMA (more then:  FarFromAverage*pips).

I tried to use MathAbs and backtest it but still some trades opened witn 10p from the EMA instead of 1p that I set.

thanks. 

whroeder1
13610
whroeder1 2015.12.15 01:14  
There are no mind readers here. We can not see your code.
Steve_o
34
Steve_o 2015.12.15 22:00  
WHRoeder:
There are no mind readers here. We can not see your code.

I managed to figure this- the code is fine.

 thanks! 

/
To add comments, please log in or register