How to Close Half of a Position in MQL5
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.
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 lost and i am trying to learn how to do that
i am not really good at coding
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.
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.
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"); }
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!