Expert Advisor Messup - Beginners Problems

 

Hey Forum!

I was a passive reader up to now, but when starting to code on your own, you get your very own questions

I did a few testings with custom indicators and they worked pretty fine - i at least have the basics now.

But when trying to get the knack on the expert advisor i seemed to have some failures i cant figure out.

The EA simply looks for EMAs crossing and then gives a trade signal - as stated above that is for testing purpose only

But when backtesting this with MT, i get trades placed on the most weird places as you can see in the attached image.

I played around with the stuff but i simply cant find the reason why he places the trade in the middle of nowhere and i have no idea whatsoever how to effective debug that code

I hope some of you can help me there

thanks,

georg

Files:
EMA.mq4  4 kb
 

Not too sure why you get that 1st random entry, but the multiple entries later on are because you are looking at the iMA of the current bar, which will be changing all the time. So I'd replace

fastEma = iMA(NULL,0,FastEmaPeriod, 0, MODE_EMA, PRICE_CLOSE, 0);

slowEma = iMA(NULL,0,SlowEmaPeriod, 0, MODE_EMA, PRICE_CLOSE, 0);

with

fastEma = iMA(NULL,0,FastEmaPeriod, 0, MODE_EMA, PRICE_CLOSE, 1);

slowEma = iMA(NULL,0,SlowEmaPeriod, 0, MODE_EMA, PRICE_CLOSE, 1);

BB

 

uuh of course! Thats so simple, it's actually quite beautiful

Thanks,

georg