Error ...
4108
ERR_INVALID_TICKET
Invalid ticket
When you do a partial close, the ticket number of the remaining position is different to the initial one.
For simplicity, I suggest you do the modification first, then do the partial close, otherwise you will have to write extra code to track and search for the ticket number of new order after the partial close.
As a followup to my previous post, in the following GIF animation, you can see how when I do a partial close of an open order, the ticket number changes from #490272795 to #490273079.
Click on the image below to see the animated video...
Hello,
I am trying to modify stoploss using the ordermodify function after partial profit taking in MQL4, but I keep receiving error 4108. All the variables have been declared without any errors.
Thanks in advance for your help.
Do not double post!
I have deleted your duplicated topic.
OrderClose(openOrderID, lots/2, Ask, slippage, clrRed);
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.)
Hello,
I am trying to modify stoploss using the ordermodify function after partial profit taking in MQL4, but I keep receiving error 4108. All the variables have been declared without any errors.
Thanks in advance for your help.
It does not need to be computed.
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum (2013)
PositionClose is not working - MQL5 programming forum (2020)
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (2011)
Limit one open buy/sell position at a time - General - MQL5 programming forum (2022)
You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am trying to modify stoploss using the ordermodify function after partial profit taking in MQL4, but I keep receiving error 4108. All the variables have been declared without any errors.
Thanks in advance for your help.