我正在尝试下订单,但是对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" );
}
}
你知道我在做什么错吗?
最佳答案
让我们首先反汇编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]
+
适当的数字归一化,因此double NormalizeLOTs( aProposedVOLUME ) {...}
是方便的工具无缝实现这两个需求。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
Taband经纪人端交易工具条件下修改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."
);
有关更多详细信息,请对这两个
Terminal
端/经纪人端的障碍进行printScreens演示并以编程方式进行处理:ref .-> MQL4参考/ MQL4程序/贸易许可