How to cose trades at current price not at close price

 
Hello am new to programming as a whole I have learned a few basic and have built my first EA but it is closing trades on close price not current price.......I don't know what I did wrong but I would love some help it uses moving average for enter and close below is the EA file
Files:
MA_1_02q.mq5  4 kb
MA_1_627.mq5  4 kb
 
Moriti Aston Mathibela: but it is closing trades on close price not current price

That is not possible — you can only close at the current price.

 
William Roeder:

That is not possible — you can only close at the current price.

For example 

If the current bar touches the moving average  after the trade is opened it must close the trade not after the current bar closes below the moving average line ......
Reason: