First Time Signals

 

Hi Guys,

I have this code that gives a signal the first time a bar crosses a 20 period MA, unfortunately it does it before it crosses, ie, gives a sell signal the bar before it closes below the MA, which is obviously a bar too early. Does anyone know how to fix this problem, the code is attached.

Files:
whohcares.mq4  2 kb
Reason: