Can an EA close and open a trade on same bar?

 

I have an EA that sometimes needs to close a trade and open another one on current bar. But what I see happening is a multiple of trades happening on the bar with I guess each tick and drawing down the account. Is it possible to have an EA close and open a trade only once on the same bar in MT4?

Thank you. 

 
Eric1704: Is it possible to have an EA close and open a trade only once on the same bar in MT4?
Of course it's possible. You have to code it. Search once per bar.
Reason: