It is at the close of the bar.
I have verified the code, in fact the rules had been optimized.
The expert advisor buys/sells also when the yellow MA crosses the orange MA at the condition that the orange MA and the yellow MA are over/under the red MA (see the picture above). And the exit is only made at the next opposite signal. The results are theorically better with these rules.
Concerning your errors, you have not modified the first settings, the periods should be 5, 15 and 36. Also you have certainly set the MM on true, that explains the lot of 4.04.