开仓函数正常,平仓执行无效
    positions=0.01*(Portfolio_CurrentCapital() + Portfolio_UsedMargin())*pos/(sl*lev);
    Position pos;
	A_GetPosition(pos, "", 0);
    if (sl!=0 and SpeLimit!=0 and dir!=0 and lev!=0){
    	if (dir==1 and pos.longCurrentVolume==0 and close>SpeLimit and close[1]<=SpeLimit and SumDC>stdev){
    		CurPos=pos.longCurrentVolume;
			TRes=Buy(positions,0);
			Alert("Buy - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.longCurrentVolume));
		}
		else if (pos.longCurrentVolume>0 and close<SpeLimit and close[1]>=SpeLimit and SumDC>stdev){
			CurPos=pos.longCurrentVolume;
			TRes=Sell(pos.longCurrentVolume,0);
			Alert("Sell - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.longCurrentVolume));
		}
    	else if (dir==-1 and pos.shortCurrentVolume==0 and close<SpeLimit and close[1]>=SpeLimit and SumDC>stdev){
 			CurPos=pos.shortCurrentVolume;
			TRes=SellShort(positions,0);
			Alert("SellShort - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.shortCurrentVolume));
		}
		else if(pos.shortCurrentVolume>0 and close>SpeLimit and close[1]<=SpeLimit and SumDC>stdev){
 			CurPos=pos.shortCurrentVolume;
			TRes=BuyToCover(pos.shortCurrentVolume,0);
			Alert("BuyToCover - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.shortCurrentVolume));
		}
	}

日志显示BuyToCover触发了并且返回了True,而且正确获得了要平的数量,但是仓位仍然在。

平仓函数无法正常平仓
实盘平仓函数不执行问题
收盘平仓不执行
getdictime函数无效?
ISMAINCONTRACT无效
关于开仓策略与平仓策略对接
A函数发单时,如何判断当根K线没有新开仓成交,不想当根K线开仓即平仓,至少要等到下一根K线再平仓
保存开仓和平仓时的时间
收盘平仓不执行
收盘平仓不执行

你这个输出不代表任何事

你说的仓位仍在是什么仍在,截图说明

然后你发的代码栏事空的

positions=0.01*(Portfolio_CurrentCapital() + Portfolio_UsedMargin())*pos/(sl*lev);

   Position pos;

A_GetPosition(pos, "", 0);

   if (sl!=0 and SpeLimit!=0 and dir!=0 and lev!=0){

    if (dir==1 and pos.longCurrentVolume==0 and close>SpeLimit and close[1]<=SpeLimit and SumDC>stdev){

    CurPos=pos.longCurrentVolume;

TRes=Buy(positions,0);

Alert("Buy - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.longCurrentVolume));

}

else if (pos.longCurrentVolume>0 and close<SpeLimit and close[1]>=SpeLimit and SumDC>stdev){

CurPos=pos.longCurrentVolume;

TRes=Sell(pos.longCurrentVolume,0);

Alert("Sell - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.longCurrentVolume));

}

    else if (dir==-1 and pos.shortCurrentVolume==0 and close<SpeLimit and close[1]>=SpeLimit and SumDC>stdev){

CurPos=pos.shortCurrentVolume;

TRes=SellShort(positions,0);

Alert("SellShort - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.shortCurrentVolume));

}

else if(pos.shortCurrentVolume>0 and close>SpeLimit and close[1]<=SpeLimit and SumDC>stdev){

CurPos=pos.shortCurrentVolume;

TRes=BuyToCover(pos.shortCurrentVolume,0);

Alert("BuyToCover - "+IIFString(TRes, "True", "False")+" - "+Text(CurPos)+" - "+Text(pos.shortCurrentVolume));

}

}

原本无仓位,执行开仓的两个函数,能正确产生仓位

原本有仓位,执行平仓的两个函数,仓位还在

你描述的"仓位还在",是图表上的没平 还是账户的没平

账户的

图表如何没信号,那么编写逻辑问题。

账户没平,那说明你可能机制理解哪里没对上,已经注意到你代码里有图表和A函数混用,这种一般除了编写者本人知道什么意思,外人是不容易理解的。

建议一种方法,给出最小能够产生对应问题的代码,这种问题只能通过运行调试判断。