Mq4 and mq5 aren't compatible!
Here you can find info what to do:
https://www.mql5.com/en/articles/81
https://www.mql5.com/en/docs/migration
more of it with Google search for: site:mql5.com migration mq4 to mq5
- www.mql5.com
Hi, I'm trying to migrate an expert from mql4 to mql5, but I can't get the ticket of the new position that just opened.
In mql4, OrderSend() will return the ticket automiticly, but in mql5, trade.mqh m_trade.Buy only return true or false.
Please help me about how to get the ticket of position that opened by trade.mqh function?
Thanks!
You can use PositionSelectByTicket(ticket)
Hi, I'm trying to migrate an expert from mql4 to mql5, but I can't get the ticket of the new position that just opened.
In mql4, OrderSend() will return the ticket automiticly, but in mql5, trade.mqh m_trade.Buy only return true or false.
Please help me about how to get the ticket of position that opened by trade.mqh function?
Thanks!
#include <Trade\Trade.mqh> #include <Trade\PositionInfo.mqh> CTrade trade; CPositionInfo m_position; //open position trade.Sell(0.1,NULL,0,0,0,NULL); //Get position Ticket ulong ticket = trade.ResultOrder();
Please help me about how to get the ticket of position that opened by trade.mqh function?
If you use the search, you can quickly find the answer yourself.
Forum on trading, automated trading systems and testing trading strategies
Vladimir Karputov, 2022.03.26 07:15
Use ResultOrder
trade.ResultOrder()
Forum on trading, automated trading systems and testing trading strategies
Fernando Carreiro, 2023.02.10 16:48
// The code below is uncheck and will not compile. It is only an sample code. ulong posTicket = 0; int OnInit( void ) { posTicket = 0; }; void OnTick( void ) { if( posTicket == 0 ) { if( trade.Sell( lot_size, _Symbol ) ) { posTicket = trade.ResultOrder(); Print( "Sell order placed with ticket number = ", posTicket ); } else Print( "Sell order failed!" ); }; };
...
Hi, I am having an issue with this ResultOrder() approach.
It works on most terminals (Brokers?) but now I have a case, where
ResultOrder() returns NOT the position ticket.
Maybe it is the ID of ther order submitted and executed. But this new behaviour breaks the logic.
Is there a way to make sure, that
ResultOrder() REALLY returns the position ticket number?
Shall we use now OrderGetInteger(ORDER_POSITION_ID) ?
😟
Hi, I am having an issue with this ResultOrder() approach.
It works on most terminals (Brokers?) but now I have a case, where
ResultOrder() returns NOT the position ticket.
Maybe it is the ID of ther order submitted and executed. But this new behaviour breaks the logic.
Is there a way to make sure, that
ResultOrder() REALLY returns the position ticket number?
Shall we use now OrderGetInteger(ORDER_POSITION_ID) ?
😟
After a trade request is sent, it results on an Order on broker, not a position...
The execution of that order generate the position.
In MT4 the OrderSend is asynchronous and wait the confirmation from the server (which happens when trade is placed on market)
In MT5 it can be set as sync or async, but even in the async mode, it wait the confirmation which happens at the generation of Order, not position.
The real big difference between MT4 and MT5 is in how they treat trades: in MT4 you have Orders only, In MT5 you have Orders, Deals and Positions.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I'm trying to migrate an expert from mql4 to mql5, but I can't get the ticket of the new position that just opened.
In mql4, OrderSend() will return the ticket automiticly, but in mql5, trade.mqh m_trade.Buy only return true or false.
Please help me about how to get the ticket of position that opened by trade.mqh function?
Thanks!