Hey people, the broker I'm using imposes that TPs and SLs should be set a certain points away from the entry price.
Around 2 months ago, I used this code that closes a position based on the profit it generated, I was able to bypass the broker's limitations.
Now that I'm trying to use it in another EA, it doesn't work and the trades are closed at TP. Could've the broker somehow foundd a way to prevent users from bypassing their limitations? If you have some lines of code that could be helpful, please share them with me. Thanks :D
EDIT: I suspect it's because of the Sleep() function lasting half an hour after a trade is opened, if it is indeed the problem, how can I place an interval of half an hour between each trade all while leaving the EA being executed and thus executing my PositionClose() function?
EDIT2: The problem was indeed because of the Sleep(), I fixed it all while having the features I want by modifying the code like so and removing the Sleep() after a trade's execution. Shouldn't have posted so fast hahah, will this post up for future googelers.
you are mixing up market execution with TP & SL.
TP & SL levels often have a minimum distance from current price requirement when placing (broker dependent), but they are just pending orders to be triggered at a given price.
The code you show executes a market order to close the position at current bid/ask so not the same thing at all as it has nothing to do with SL or TP.
you are mixing up market execution with TP & SL.
TP & SL levels often have a minimum distance from current price requirement when placing (broker dependent), but they are just pending orders to be triggered at a given price.
The code you show executes a market order to close the position at current bid/ask so not the same thing at all as it has nothing to do with SL or TP.
Thank you :D

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey people, the broker I'm using imposes that TPs and SLs should be set a certain points away from the entry price.
Around 2 months ago, I used this code that closes a position based on the profit it generated, I was able to bypass the broker's limitations.
Now that I'm trying to use it in another EA, it doesn't work and the trades are closed at TP. Could've the broker somehow foundd a way to prevent users from bypassing their limitations? If you have some lines of code that could be helpful, please share them with me. Thanks :D
EDIT: I suspect it's because of the Sleep() function lasting half an hour after a trade is opened, if it is indeed the problem, how can I place an interval of half an hour between each trade all while leaving the EA being executed and thus executing my PositionClose() function?
EDIT2: The problem was indeed because of the Sleep(), I fixed it all while having the features I want by modifying the code like so and removing the Sleep() after a trade's execution. Shouldn't have posted so fast hahah, will this post up for future googelers.