【问题标题】:MQL4 - ERROR 4111 when calling OrderSend() methodMQL4 - 调用 OrderSend() 方法时出现错误 4111
【发布时间】:2016-07-31 22:57:03
【问题描述】:

我正在尝试下订单,但我对 OrderSend() 方法的调用 (https://docs.mql4.com/trading/ordersend)
失败:

2016.08.01 00:51:09.710 2016.07.01 01:00 s EURUSD,M1: OrderSend error 4111

void OnTick() {
    if (  OrdersTotal() == 0 ){
          int   result =  OrderSend( NULL, OP_SELL, 0.01, Bid, 5, 0, Bid - 0.002, NULL, 0, 0, clrGreen );
          if (  result <  0 ) Print( "Order failed #", GetLastError() );
          else                Print( "Order success" );
    }
} 

请问你知道我做错了什么吗?

【问题讨论】:

    标签: algorithmic-trading mql4 metatrader4 mql5


    【解决方案1】:

    让我们先反汇编OrderSend()调用:

    int result = OrderSend( NULL,             // string:      _Symbol,
                            OP_SELL,          // int:         OP_SELL,
                            0.01,             // double:      NormalizeLOTs( nLOTs ),
                            Bid,              // double:      NormalizeDouble( Bid, Digits ),
                            5,                // int:         slippagePOINTs,
                            0,                // double:      {       0 | NormalizeDouble( aSlPriceTARGET, Digits ) },
                            Bid-0.002,        // double:      {       0 | NormalizeDouble( aTpPriceTARGET, Digits ) },
                            NULL,             // string:      {    NULL | aBrokerUnguaranteedStringCOMMENT },
                            0,                // int:         {       0 | aMagicNUMBER },
                            0,                // datetime:    {       0 | aPendingOrderEXPIRATION },
                            clrGreen          // color:       { clrNONE | aMarkerCOLOR }
                            );
    

    为了更加安心,应该始终规范化所有值,在 MQL4 方面(价格 + 手数)有一些限制性处理 (量化的)值——因为这些不是 R 域中的连续值,而是量子步进的:

    价格:0.000010.00010.0010.010.11.0等步进,

    手数:受到经纪人特定设置的更多限制,每个工具,三个关键值,所有允许的交易量大小必须满足:
    [aMinLOTs&lt;=, +aMinLotSTEP, &lt;=aMaxLOTs] @ 987654331@ 正确的数字规范化
    ~ 因此,double NormalizeLOTs( aProposedVOLUME ) {...} 是一个方便的工具,可以无缝实现这两个部分的需求。 p>


    Error 4111:

    还有一些其他障碍会阻止您的 MetaTrader Terminal 4 顺利运行您的代码:

    4111
    ERR_SHORTS_NOT_ALLOWED
    Shorts are not allowed. Check the Expert Advisor properties

     if (  !TerminalInfoInteger( TERMINAL_TRADE_ALLOWED ) ) 
            Alert( "Check if automated trading is allowed in the terminal settings!" ); 
     else  if (  !MQLInfoInteger( MQL_TRADE_ALLOWED ) )
                 Alert( "Automated trading is forbidden in the program settings for ",
                        __FILE__
                        );
    

    这会指示用户修改 MetaTrader Terminal 4 设置,
    MT4 -&gt; Tools -&gt; Options -&gt; ExpertAdvisor 选项卡
    和经纪商交易工具条件下,其中做空一些一般情况下,工具可能会受到限制,或者仅针对某些帐户类型。

     if (  !AccountInfoInteger( ACCOUNT_TRADE_EXPERT ) )
            Alert( "Automated trading is forbidden for the account",
                    AccountInfoInteger( ACCOUNT_LOGIN ),
                   " at the trade server side. Contact Broker's Customer Care Dept."
                   );
    

    有关更多详细信息,printScreens 并演示了这组 Terminal-side / Broker-side 障碍的编程处理:ref.-> MQL4 Reference / MQL4程序/贸易许可

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2013-11-07
      • 1970-01-01
      相关资源
      最近更新 更多