I have noticed when using MA crossovers as signals that sometimes a trade turns into a loss because a long is generated at the crossover when the top of the bar is closed and the position is closed out at the next crossover when the bar is closed out at the bottom of the bar. The same logic is applied to short trades. I have noticed from looking at a chart if trades could be entered 1 two 3 bars before a crossover, and if exited 1 to 3 bars before the next crossover, a trade would usually be more profitable than at the actual crossovers. Does anyone have any suggestions on how to generate signals just before a crossover for purposes of creating an EA?