Support with building simple EA that buys/sells when EMA is touched - page 2

 

I just had a quick look a the code again. Here's the thing, in order to make EMA1[0] and EMA2[0] correspond to the most updated MA value (at current bar), then you need to use ArraysSetAsSeries  in OnInit:


ArraysSetAsSeries(EMA1, true);
ArraysSetASSeries(EMA2, true);

ArraysSetASSeries(ATR1, true);

^ the same goes for the ATR



Otherwise if you don't do this, then you should be coding it like:

 if ( open < previousEMAfastVal && EMA1[ Bars(Symbol(), Period()) - 1] <  EMA2[Bars(Symbol(), Period()) - 1]  &&  ( high >= previousEMAfastVal || tempriceBID >=currentEMAfastVal)  )

but I don't think that's a common approach to index it that way


I didn't test anything yet, I don't have time, but maybe I can have a closer look later.

It will help you a lot if you print the buffer prices, and then look in the journal.

Print("ATR 1  CURRENT: ", ATR1[0]);
 
Thanks Conor!  It works better now! I do some backtest and try different numbers. Still there is a problem with opening position one candle after the price intersects the EMA, but it works better! Thanks again!