如附件,
void CheckForClose(void)
{
MqlRates rt[2];
//--- go trading only for first ticks of new bar
if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
{
Print("CopyRates of ",_Symbol," failed, no history");
return;
}
if(rt[1].tick_volume>1)
return;
//--- get current Moving Average
double ma[2];
if(CopyBuffer(ExtHandle,0,0,2,ma)!=2)
{
Print("CopyBuffer from iMA failed, no data");
return;
}
//--- positions already selected before
bool signal=false;
long type=PositionGetInteger(POSITION_TYPE);
if(type==(long)POSITION_TYPE_BUY && rt[0].close<ma[0] && rt[1].low<rt[0].low)
signal=true;
if(type==(long)POSITION_TYPE_SELL && rt[0].close>ma[0] && rt[1].high>rt[0].high)
signal=true;
//--- additional checking
if(signal)
if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
if(Bars(_Symbol,_Period)>100)
{
CTrade trade;
trade.PositionClose(_Symbol,3);
}
//---
}
添加调试语句,打印相关信息,看哪一步没有执行。
怎么做?加入Print,下面代码报错
如附件,
void CheckForClose(void)
{
MqlRates rt[2];
//--- go trading only for first ticks of new bar
if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
{
Print("CopyRates of ",_Symbol," failed, no history");
return;
}
if(rt[1].tick_volume>1)
return;
//--- get current Moving Average
double ma[2];
if(CopyBuffer(ExtHandle,0,0,2,ma)!=2)
{
Print("CopyBuffer from iMA failed, no data");
return;
}
//--- positions already selected before
bool signal=false;
long type=PositionGetInteger(POSITION_TYPE);
if(type==(long)POSITION_TYPE_BUY && rt[0].close<ma[0] && rt[1].low<rt[0].low)
signal=true;
if(type==(long)POSITION_TYPE_SELL && rt[0].close>ma[0] && rt[1].high>rt[0].high)
signal=true;
//--- additional checking
if(signal)
if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
if(Bars(_Symbol,_Period)>100)
{
CTrade trade;
trade.PositionClose(_Symbol,3);
}
//---
}
为什么图中,该平仓时没有平仓?![](https://c.mql5.com/3/247/40.PNG)