Why is my StopLoss moving in the wrong direction?

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I'm trying to build my first EA and honestly i'm mostly using copy and paste but i cannot see why this is not working the way i want it to. The idea is to move my stop loss up to the Low or High of the candle with a shift of 2 but once its placed it should not move back. In this example i have a Buy trade in and when it was placed the initial stop loss and first move were fine but then when the next candle posted the new low was lower than the previous without hitting my stop loss it moved my stop loss down and it should not have.
Here is the code i'm using:
If i understand correctly (which i don't since its not working), it should only myve the stop loss if Ask is greater than SL which is stop loss as is highlighted above. Also i have not done anything to make this work in JPY pairs but it is only working on 5 digit pairs at the moment so if you have a suggesting that would fix that i'd appreciate that too.
Thanks in advance for any assistance/advice you can give!