Need assistance: entering trades near EMA

Back to topics list To post a new topic, please log in or register
avatar
11
steve_o 2015.12.13 23: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);

      }       

 

avatar
Moderator
3419
GumRai 2015.12.13 23: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

avatar
11
steve_o 2015.12.14 21: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. 

avatar
13006
WHRoeder 2015.12.15 02:14 #
 
There are no mind readers here. We can not see your code.
avatar
11
steve_o 2015.12.15 23:00 #
 
WHRoeder:
There are no mind readers here. We can not see your code.

I managed to figure this- the code is fine.

 thanks! 

Back to topics list  

To add comments, please log in or register