OrderClosePrice返回不同​​于历史记录池的价格

问题描述

当使用api关闭一个(选定的)现有订单时,在那一刻我尝试获取收盘价,有时(也许十分之一)返回的价格与我在历史记录池中看到的价格不同

代码是这样的:

RefreshRates();

if(type == OP_BUY)
{
    currentPrice = NormalizeDouble(MarketInfo(symbol,MODE_ASK),vdigits);
}
else if(type == OP_SELL)
{
    currentPrice = NormalizeDouble(MarketInfo(symbol,MODE_BID),vdigits);
}

if (meetsRequirementsToClose(currentPrice))
{
    desiredPrice = currentPrice;


    // And then....

    bool retVal = OrderClose(OrderTicket(),numLots,desiredPrice,currSlippage);
    if (retVal)
    {
        this.reportClosePrice (myOrderId,OrderClosePrice(),"closing");
        return true;
    }
}

先前使用MODE_TRADES池中的SELECT_BY_POS选择了订单。

有人知道如何解决吗?

已编辑

我们有一个经纪人,有时会尊重所要求的价格...有时不会。

不管我们必须更换经纪人以获得更可靠的经纪人,我们都不能依靠所要求的价格。

我们看到的偏差大于一百点,无论价格是好是坏,都比真实价格高。

解决方法

@TheLastStark表示,问题已解决,即在关闭前通过票证选择订单。

最终代码如下:

RefreshRates();
if(type == OP_BUY)
{
    currentPrice = NormalizeDouble(MarketInfo(symbol,MODE_ASK),vdigits);
}
else if(type == OP_SELL)
{
    currentPrice = NormalizeDouble(MarketInfo(symbol,MODE_BID),vdigits);
}

if (meetsRequirementsToClose(currentPrice))
{
    desiredPrice = currentPrice;


    // And then....
    int tickNum = OrderTicket();
    bool retVal = OrderClose(OrderTicket(),numLots,desiredPrice,currSlippage);
    if (retVal)
    {
        if (OrderSelect(tickNum,SELECT_BY_TICKET,MODE_HISTORY)== false)
        {
            //this.logger.error ("Error selecting the order");
             this.reportClosePrice (myOrderId,-1,"closing");
        }
        else
        {
            this.reportClosePrice (myOrderId,OrderClosePrice(),"closing");
        }
        return true;
    }
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...