获取 MQL5 中的未平仓合约
我想在开仓后立即得到票号。
此代码的输出为零:
bool r = trade.Buy(0.1, Symbol(), 0, 0, 0);
if(r)
{
position_Info.SelectByIndex(0);
Alert(position_Info.Ticket());
}
但是如果我添加延迟命令,输出将正确显示:
bool r = trade.Buy(0.1, Symbol(), 0, 0, 0);
if(r)
{
Sleep(2000); // <=======================HERE
position_Info.SelectByIndex(0);
Alert(position_Info.Ticket());
}
如何在不添加延迟命令的情况下执行此操作?
I want to get the ticket number immediately after opening the position.
The output of this code is zero:
bool r = trade.Buy(0.1, Symbol(), 0, 0, 0);
if(r)
{
position_Info.SelectByIndex(0);
Alert(position_Info.Ticket());
}
But if I add a delay command, the output will be displayed correctly:
bool r = trade.Buy(0.1, Symbol(), 0, 0, 0);
if(r)
{
Sleep(2000); // <=======================HERE
position_Info.SelectByIndex(0);
Alert(position_Info.Ticket());
}
How can I do this without adding a delay command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查文档。
成功完成Buy方法并不总是意味着成功执行的贸易运作。需要使用 ResultRetcode() 和 ResultDeal()。
返回值 = 交易单(如果交易已执行)。
以下代码示例已经过测试并确认可以正常工作:
Check the documentation.
Successful completion of the Buy method does not always mean successful execution of the trade operation. It is necessary to check the result of trade request (trade server return code) using ResultRetcode() and value returned by ResultDeal().
Return Value = Deal ticket if the deal is executed.
The following code example has been tested and confirmed as working: