为什么能在连续合于上开仓,但是平不了仓,把里面的RelativeSymbol()改成Symbol()就能在主力合约上既能开仓,也能平仓

Params
    Numeric length1(5);
    Numeric length2(10);
    Numeric length8(144);    
    Numeric money(100);             //固定市值开仓:单位万  
Vars
    Plot plt;
    String tableName("账户资金");
    String RelativeSymbol("主力合约");
    Numeric myprice;            //委托价格
    Numeric ma1;
    Numeric ma2;
    Numeric ma8;
    Plot PlotNumeric;
    Global Integer sendCount(0);
    Global Integer fillCount(0);
    Numeric lots;                //委托数量
    Numeric fet;
    
Events
OnInit()
   {
    //=========除权换月相关设置==============
    AddDataFlag(Enum_Data_RolloverBackWard());    //设置后复权
    AddDataFlag(Enum_Data_RolloverRealPrice());    //设置映射真实价格
    AddDataFlag(Enum_Data_AutoSwapPosition());    //设置自动换仓
    AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());    //设置忽略换仓信号计算
    //=========交易相关设置==============
    SetInitCapital(1000000);    //设置初始资金为100万  
    }   
OnReady()
    {
        
        Print("RelativeSymbol:" + RelativeSymbol());
    }
OnBar(ArrayRef<Integer> indexs)
  
          {
    ma1=AverageFC (Close, 5); 
    ma2=AverageFC (Close, 10); 
    ma8=AverageFC (Close, 144); 
    myprice=Open/rollover; //这里使用open/rollover,更为精确的是使用委托价格.Rollvoer是系统提供的复权系数,真实价格= 后复权的价格/rollover。
    lots=IntPart(money*10000/(myprice*contractunit*BigPointValue)); //计算开仓手数
          If(BarStatus != 2)
          {
              Return;
          }
    Array<Integer> orders;
    Print("ma1:"+Text(ma1));
    Print("ma2:"+Text(ma2));
    Print("ma8:"+Text(ma8));

    If(BarStatus == 2 &&  High == Low) 
        Return;
    If ( Q_Last == 0 || ( Date != Date[1] && High == Low ) ) 
        Return;
    
    if(ma1>ma8&&ma2>ma8&&A_TotalPosition==0&&BarStatus == 2 && sendCount == 0)//当5日线10日线上穿144日线开多
    {
            
            Bool ret = A_Buy(RelativeSymbol(), lots, Q_AskPrice, orders, "", "");
            Print("A_Buy:" + IIFString(ret, "True", "False") + "," + TextArray(orders));
            if(ret)
            {
                sendCount =sendCount+1;
            }
    }
    if( ma1<ma8&&ma2<ma8&&A_BuyPosition>0&&BarStatus == 2 && sendCount == 1)//当5日线10日线下穿144日线平多
    {
            Bool ret = A_Sell(RelativeSymbol(), lots, Q_BidPrice, orders, "", "");
            Print("A_Sell:" + IIFString(ret, "True", "False") + "," + TextArray(orders));
            if(ret)
            {
                sendCount =sendCount-1 ;
            }
    }
    if(ma1<ma8&&ma2<ma8&&A_TotalPosition ==0&&BarStatus == 2 && sendCount == 0)//当5日线10日线下穿144日线开空
    {
            Bool ret =   A_SellShort(RelativeSymbol(), lots, Q_BidPrice, orders, "", "");
            Print("A_SellShort:" + IIFString(ret, "True", "False") + "," + TextArray(orders));
            if(ret)
            {
                sendCount =sendCount-1 ;
            }
    }
    if(ma1>ma8&&ma2>ma8&&A_SellPosition>0&&BarStatus == 2 && sendCount == -1)//当5日线10日线上穿144日线平空
    {
            Bool ret =  A_BuyToCover(RelativeSymbol(),lots, Q_AskPrice, orders, "", "");
            Print("A_BuyToCover:" + IIFString(ret, "True", "False") + "," + TextArray(orders));
            if(ret)
            {
                sendCount =sendCount+1;
            }
    }
}

连续合约上获取主力合约实时持仓
A函数发单能在图表上显示吗?
如果获取连续合约(888合约)图表上的连续合约对应主力合约的账户实际持仓?
请问主力连续映射能否在持仓结束后再换合约?
期权合约订阅0518_2023腾讯课堂里的策略,只能在螺纹品种上能正常应用
关于开仓策略与平仓策略对接
A函数平仓不生效,平不了仓
建议临近交割月,提前十天把主力合约切换到新的合约上
用连续合约映射交易,能自动切换主力月吗?
开仓K实时开仓,并同K实时止损

没有复现出来你说的问题,relativesymbol挺正常的啊

crying可以把这个公式去跑一下,只能开仓,不能平仓。

出现信号不平仓

我大概知道你的问题了

你的问题是,开仓委托单发了,但是满足平仓条件的时候,平仓委托单发不出来是吧?

你看看的平仓语句

你的图表应该是000,所以当然是查不出来持仓的

试试用getposition 查relativesymbol的持仓,替换这个

 

好的,谢谢老师

 

你是指图表的显示,还是实际账户的问题

实际账户。

老师,能帮忙看一下嘛