第一的:
在深入之前,让我们先更好地诊断一下情况:
#include<Trade\Trade.mqh>
...
CTrade m_trade;
...
if ( PositionsTotal() == 0 )
{
if ( !trade.Buy( 0.1, _Symbol ) )
{
//--- failure message
Print( "The .Buy() method failed. The return-code = ",
trade.ResultRetcode(),
". Code description: ",
trade.ResultRetcodeDescription()
);
}
else
{
Print( "The .Buy() method executed successfully. The return-code = ",
trade.ResultRetcode(),
" (",
trade.ResultRetcodeDescription(),
")"
);
}
}
下一个:
如果Print()
上面的 -ed 输出确认操作成功,您可以在.Buy()
方法中添加更多详细信息并重新测试:
#include<Trade\Trade.mqh>
...
CTrade m_trade;
...
double aVolume = 0.1;
double aPoint = SymbolInfoDouble( _Symbol, SYMBOL_POINT );
double anAsk = SymbolInfoDouble( _Symbol, SYMBOL_ASK );
double aBid = SymbolInfoDouble( _Symbol, SYMBOL_BID );
int aNumDigits = (int) SymbolInfoInteger( _Symbol, SYMBOL_DIGITS );
double aLongOpen = SymbolInfoDouble( _Symbol, SYMBOL_ASK ),
aLongSL = aBid - 1000 * aPoint,
SL = NormalizeDouble( aLongSL, aNumDigits ),
aLongTP = aBid + 1000 * aPoint,
TP = NormalizeDouble( aLongTP, aNumDigits );
if ( !trade.Buy( aVolume, _Symbol, aLongOpen, SL, TP, "Does this work?" ) )
{ ... }
对于做空aShortOpen
,anAsk
基于 , 的 { TP
, SL
}-prices 和对称编辑更改适用。