Hello, I've written this partial close function but it's not working as it's supposed to. I need your help in correcting the bug so that it can work in my code and help in closing orders partially after certain % of pips has been achieved.
- Need help with my code
- Partial close not working
- Help with code: Partial Close orders
if(!OrderClose(ticket,lots /2 ,Bid,3,Green))
You can't just use OrderLots()/2 because that is not a multiple of LotStep, and you can't close or have remaining less than MinLot.
You also must check if you have already done it, to avoid repeated closing. Alternatives:
- Move SL to Break Even+1 before the partial close. That way, you know that you already did it.
- Set a flag in persistent storage (files, global variables w/flush)
- Open two orders initially, and close one (manually or by TP.)
William Roeder #:
You can't just use OrderLots()/2 because that is not a multiple of LotStep, and you can't close or have remaining less than MinLot.
You also must check if you have already done it, to avoid repeated closing. Alternatives:
- Move SL to Break Even+1 before the partial close. That way, you know that you already did it.
- Set a flag in persistent storage (files, global variables w/flush)
- Open two orders initially, and close one (manually or by TP.)
Thank you for your help
Ernest Akoyi:
Hello, I've written this partial close function but it's not working as it's supposed to. I need your help in correcting the bug so that it can work in my code and help in closing orders partially after certain % of pips has been achieved.
Hello, I've written this partial close function but it's not working as it's supposed to. I need your help in correcting the bug so that it can work in my code and help in closing orders partially after certain % of pips has been achieved.
For partial close purposes, there is already an OrderCloseBy function that you can use.
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