开仓函数正常,平仓执行无效

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,而且正确获得了要平的数量,但是仓位仍然在。

你这个输出不代表任何事你说的仓位仍在是什么仍在,截图说明然后你发的代码栏事空的

回复: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函数混用,这种一般除了编写者本人知道什么意思,外人是不容易理解的。建议一种方法,给出最小能够产生对应问题的代码,这种问题只能通过运行调试判断。