Need help to fix simple EA...

 

I have an EA I did quickly using a template I have found on the net. It seems to work fine executing the BUY/SELL entries. However, it is not executing the exit code. Would someone please check it out and make the necessary corrections?

It is a simple MA cross using a fast EMA3 and couple EMAs serving as upper and lower bands. BUY is when EMA3 cross up and above the upper EMA band and exit when it cross down and below the upper EMA band. SELL is when EMA3 cross down and below the lower EMA band and exit when it cross up and above the lower band.

I would appreciate any help.

solaris

Files:
 

i believe it's because you have PRICE_CLOSE of the 3EMA has to be EQUAL to Price HIGH of the 20 EMA in order for a buy to close.

and how often is the close of the 3 EMA going to the exact same value as the HIGH of the 20 EMA?

you might want less than or equal for the buy close and greater than or equal for the sell close...If I understand what you're trying to do with the EA

 
skorcht:
i believe it's because you have PRICE_CLOSE of the 3EMA has to be EQUAL to Price HIGH of the 20 EMA in order for a buy to close.

and how often is the close of the 3 EMA going to the exact same value as the HIGH of the 20 EMA?

you might want less than or equal for the buy close and greater than or equal for the sell close...If I understand what you're trying to do with the EA

thanks, skorcht. i will make that change and keep you posted.

 
skorcht:
i believe it's because you have PRICE_CLOSE of the 3EMA has to be EQUAL to Price HIGH of the 20 EMA in order for a buy to close.

and how often is the close of the 3 EMA going to the exact same value as the HIGH of the 20 EMA?

you might want less than or equal for the buy close and greater than or equal for the sell close...If I understand what you're trying to do with the EA

Thanks, it works. Now, when EMA3 cross the upper or lower band, at times the price bar has not closed yet, thus EMA3 crosses in and out of the band which causes the trade to exit early with the loss of the spread in pips or more.

Any idea how this can be fixed and how should I code it within the EA?

I appreciate your kind help.

solaris

Reason: