【问题标题】:OrderClosePrice returns a price different from the history poolOrderClosePrice 返回与历史池不同的价格
【发布时间】:2021-02-24 07:01:04
【问题描述】:

当使用 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(), desiredPrice, numLots, "closing");
        return true;
    }
}

该订单之前是使用池 MODE_TRADES 中的 SELECT_BY_POS 选择的。

有人知道怎么解决吗?

已编辑

我们的经纪人有时会尊重要求的价格……有时不会。

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

我们看到的偏差大于一百个点,无论是比真实价格更好还是更差的价格。

【问题讨论】:

  • 可能是小滑点的原因吗?对于desiredPrice,您是否使用OrderClosePrice() 返回可以平仓的当前价格?
  • @TheLastStark 不,我们没有使用 OrderClosePrice() 来获取所需价格,但无论如何,这不是问题:NormalizeDouble(MarketInfo(symbol, MODE_ASK), vdigits); 用于检查我们是否有所需的价格(使用 OP_SELL,以及当其他满足要求)。问题是即使价格准确,它也会返回不同的价格(有时)。
  • 只是让您知道OrderClosePrice() 将返回正确的价格,此时可以关闭所选仓位,因此对于OP_SELL 订单(仓位),它将返回正确的Ask价钱。但是要解决您的原始问题,我假设这是一个滑点问题。如果不是meetsRequirementsToClose(currentPrice) 函数中的其他可能问题或使用了错误的数字(我假设vdigitsDigit or _Digit 不同)
  • 另外,您可以尝试在收盘前按票号选择订单吗?我还没有确认,但是一旦交易关闭,订单的索引必须更改(因为池已从MODE_TRADE 更改为MODE_HISTORY
  • @TheLastStark 看起来比重新选择订单有效:我会确认订单数量何时具有统计相关性

标签: mql4 metatrader4 mt4


【解决方案1】:

正如@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, desiredPrice, numLots, "closing");
        }
        else
        {
            this.reportClosePrice (myOrderId, OrderClosePrice(), desiredPrice, numLots, "closing");
        }
        return true;
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-07
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 2017-08-19
    相关资源
    最近更新 更多