Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
Lost magic number and comment after partially closing
Does anyone here have a solution about this problem? Let's say you use OrderSend to open 0.5 lots. If you call orderClose to close 0.1 lot. The system would generate another new 0.4 lots order, but your original magic number and comment were lost. Without them, your EA couldn't work together with others on the same symbol. I have to open multiple orders for this problem, wondering if there is anyway to keep them.
Thanks!
No warranty to this code but it has worked for a very long time
int orderToClose = (ticket number of the smaller ticket);
int closingTicket = (ticket number of the larger ticket);
if (orderToClose != 0 && closingTicket != 0)
{
bFlag1 = OrderCloseBy(orderToClose, closingTicket);
if (bFlag1 == true)
{
newTicket = 0;
// Check for a new ticket
for (idx2 = OrdersTotal() - 1; idx2 >= 0; idx2--)
{
if (OrderSelect(idx2, SELECT_BY_POS, MODE_TRADES))
{
s = StringConcatenate("split from #", orderToClose);
splitIndex = StringFind(OrderComment(), s, 0);
if (splitIndex != -1)
{
// We found the new ticket number
newTicket = OrderTicket();
// Now update the old ticket to the new ticket
closingTicket = newTicket;
break;
}
}
}
}
In my opinion MQL4 has it completely backwards on this point. They change the ticket number making it very difficult to find.
Thanks, so it will use "Split from xxx" as the comment of the new orders. I will try it.
Quote:
Originally Posted by ScottB
No warranty to this code but it has worked for a very long time
int orderToClose = (ticket number of the smaller ticket);
int closingTicket = (ticket number of the larger ticket);
if (orderToClose != 0 && closingTicket != 0)
{
bFlag1 = OrderCloseBy(orderToClose, closingTicket);
if (bFlag1 == true)
{
newTicket = 0;
// Check for a new ticket
for (idx2 = OrdersTotal() - 1; idx2 >= 0; idx2--)
{
if (OrderSelect(idx2, SELECT_BY_POS, MODE_TRADES))
{
s = StringConcatenate("split from #", orderToClose);
splitIndex = StringFind(OrderComment(), s, 0);
if (splitIndex != -1)
{
// We found the new ticket number
newTicket = OrderTicket();
// Now update the old ticket to the new ticket
closingTicket = newTicket;
break;
}
}
}
}
In my opinion MQL4 has it completely backwards on this point. They change the ticket number making it very difficult to find.