EA交易未开放交易

时间:2020-01-04 16:23:37

标签: mql4 algorithmic-trading metatrader4 forex

我试图在mql4中创建一个EA,它根据给定的条件打开和关闭交易头寸,但是在条件匹配后它并没有打开交易,EA一直工作到信号显示买入和卖出,之后什么也没有发生。我该如何调试?

Fixed
void CloseBuyPosition()
{
    for (int i = OrdersTotal() - 1; i >= 0; i--)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        string Cp = OrderSymbol();

        if (_Symbol == Cp)

            if (OrderType() == OP_BUY)
            {

                OrderClose(OrderTicket(), OrderLots(), Bid, 3, NULL);

            }
    }
}
void CloseSellPosition()
{
    for (int i = OrdersTotal() - 1; i >= 0; i--)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        string Cp = OrderSymbol();

        if (_Symbol == Cp)

            if (OrderType() == OP_SELL)
            {

                OrderClose(OrderTicket(), OrderLots(), Ask, 3, NULL);

            }
    }

}

1 个答案:

答案 0 :(得分:0)

步骤0:
,检查您的EA是否已在MetaTrader4终端内启动并获得了进行交易的有效许可。

步骤1:
检查代码,至少具有一些基本的自我调试工具( GetLastError() {{ 1}} 比间歇性和自我毁灭性要好,即内部具有零深度的GUI文本,但最后一个可见的Print()

步骤2:
分析日志,其中所有打印的详细信息将帮助您跟踪根本原因(经纪人拒绝,市场封闭,价格水平有缺陷以及许多可能的原因)进行Comment()通话以被拒绝)

OrderSend()

int  OrderSend( string   symbol,              // symbol
                int      cmd,                 // operation
                double   volume,              // volume
                double   price,               // price
                int      slippage,            // slippage
                double   stoploss,            // stop loss <------------ PRICE-DOMAIN levels, not INT-s
                double   takeprofit,          // take profit <---------- PRICE-DOMAIN levels, not INT-s
                string   comment = NULL,      // comment
                int      magic = 0,           // magic number
                datetime expiration = 0,      // pending order expiration
                color    arrow_color = clrNONE// color
                );