让我们先反汇编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.00001或0.0001或0.001或0.01或0.1或1.0等步进,
手数:受到经纪人特定设置的更多限制,每个工具,三个关键值,所有允许的交易量大小必须满足:
[aMinLOTs<=, +aMinLotSTEP, <=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 -> Tools -> Options -> 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程序/贸易许可