Total closure or partial closure of a position by applying opposite order is only possible with non-hedge accounts.
In case you are using a hedge account you may use PositionClosePartial method from Trade.mqh.
Also note that you are not allowed to update comment of position.
Can I ask why you are doing it in OnTrade event handler? Are you aware about the specific usage of this handler?
Yashar Seyyedin #:
Total closure or partial closure of a position by applying opposite order is only possible with non-hedge accounts.
i am really not too familiar with the ontrade and ontick but i do think that ontrade is for modifying opened trades isnt it?
Total closure or partial closure of a position by applying opposite order is only possible with non-hedge accounts.
In case you are using a hedge account you may use PositionClosePartial method from Trade.mqh.
Also note that you are not allowed to update comment of position.
Can I ask why you are doing it in OnTrade event handler? Are you aware about the specific usage of this handler?
Yashar Seyyedin #:
Total closure or partial closure of a position by applying opposite order is only possible with non-hedge accounts.
Total closure or partial closure of a position by applying opposite order is only possible with non-hedge accounts.
In case you are using a hedge account you may use PositionClosePartial method from Trade.mqh.
Also note that you are not allowed to update comment of position.
Can I ask why you are doing it in OnTrade event handler? Are you aware about the specific usage of this handler?
Anonymous Prime #:
i am really not too familiar with the ontrade and ontick but i do think that ontrade is for modifying opened trades isnt it?
what would recommend usingi am really not too familiar with the ontrade and ontick but i do think that ontrade is for modifying opened trades isnt it?
i am really lost and i am trying to learn how to do that
i am not really good at coding
Anonymous Prime #:
i am really not too familiar with the ontrade and ontick but i do think that ontrade is for modifying opened trades isnt it?
i am really not too familiar with the ontrade and ontick but i do think that ontrade is for modifying opened trades isnt it?
OnTrade event handler is invoked every time a trade event occurs. OnTick is used when you want to monitor market per tick and take actions accordingly. OnTick suits your purpose.
Check documentation for partial closure.
Yashar Seyyedin #:
thank you so much
OnTrade event handler is invoked every time a trade event occurs. OnTick is used when you want to monitor market per tick and take actions accordingly. OnTick suits your purpose.
Check documentation for partial closure.
Anonymous Prime:
I am looking for guidance on the best practices to:
- Close half of an existing position.
- Update the position's comment to indicate that it has been partially closed.
Any help or suggestions on improving this part of the code would be greatly appreciated. Thank you!
#include <MT4Orders.mqh> // https://www.mql5.com/en/code/16006 #define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK) void OnStart() { const ulong Ticket = OrderSend(_Symbol, OP_BUY, 3.6, Ask, 0, 0, 0, "FullPosition"); if (OrderSelect(Ticket, SELECT_BY_TICKET)) OrderClose(OrderTicket(), 1.8, OrderClosePrice(), 0, clrNONE, "HalfPosition"); }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hello everyone,
I am developing a trading bot in MQL5 and I'm facing an issue with partially closing a position.
Partial Closure Logic:My goal is to close half of a position when a certain profit threshold is reached,
and to update the position's comment to reflect this partial closure.
Here are the key parts of my code:
I am looking for guidance on the best practices to:
Any help or suggestions on improving this part of the code would be greatly appreciated. Thank you!