I'm trying to add to my code that once price has reached exactly halfway between my entry point and TP, then SL will move to where the entry position was, to add some downside protection on my code.
I looked around to find a basic trending SL for a starting point for me to work from but I am getting ModifyOrder Error 4051 & 4108 the whole time. Does anyone know where I might be missing something?
Thanks in advance!
First of all you should make your code more efficient
should be checked first as the whole block of code is irrelevant if it <=0
Where is total assigned a value?
Why are you looping through the orders when you are trying to modify a specific order. OrderOpenPrice() etc are the values for the selected ticket, not necessarily LongTicket's
Thanks for the help whroeder, I'm still not getting my code to work though. I've made some more changes and tried to print every variable.
It seems that the Bid/Ask and OpenPrice difference is always 10.. which is the spread that I use to backtest. So this means that it is not looping and I have tried shifting this all over my code and it still won't loop.
I have changed my code again. All I want it to do is once the price moves past my TrailingStop level, then the StopLoss should move to where I opened the order originally. Could anyone please help me figure out why this is not working?
I'm still not getting my code to work though.
I've made some more changes and tried to print every variable.
I have tried shifting this all over my code and it still won't loop.
I have changed my code again.
All I want it to do is once the price moves past my TrailingStop level, then the StopLoss should move to where I opened the order originally.
I removed the prints to make the code shorter to attach on here for you guys, otherwise I feel it would've been too cluttered.
Sorry if my previous comment wasn't clear, I couldn't get the code to engage the Trailing stop loss with a loop so I removed the loop and that is the code (or portion of) that I copied for you.
I figured out what the original issue was though, for some reason it did not pick up OrderOpenPrice() as anything other than 0.0001, even if I assigned an Int variable to it. I changed Int to Double and then it finally worked.
The whole goal of the code that I am trying to add is for the stoploss to move to breakeven(OrderOpenPrice), as soon as the price has moved 50% of the distance between the entry point and my TP.
I have managed to get the code to engage the ModifyOrder, although now once TP is reached it just doubles the distance of the TP for my next trade but the distance of my next trade's SL stays the same.
I am attaching my entire code for you. If you could give me any advice on this last issue, I would be extremely grateful.
I have deleted your new topic.
If you can't resolve your problems here, starting a new topic will not bring any different results.