小白请教,多品种开平只有data0图层品种按照设定的资金量开仓,其他图层只1手

K线和调试输出的截图,附件是导出的代码,测试过不同图层品种开仓前的可用资金和计算出来的开仓手数输出是正常的,在buy时只有data0是正常执行买入手数的

Params

   Numeric risk(50);           //资金使用率

Vars

   Series<Numeric> i;

   Series<Numeric> p;

   Series<Numeric> q;

   Series<Numeric> pq;

   Series<Numeric> m;

   Series<Numeric> m_result;

   Series<Numeric> pq_hold;

   Series<Numeric> score;

   Series<Numeric> score0;

   Series<Numeric> score1;

   Series<Numeric> score2;

   Series<Numeric> score3;

   Series<Numeric> lots;

   Series<Numeric> lots1;

   Numeric ww;

   Global Integer timerId;

   Series<Numeric> pq_value;


Events

    OnInit()

   {

       //与数据源有关

       Range[0:DataCount - 1]

       {

           //=========数据源相关设置==============

           AddDataFlag(Enum_Data_RolloverBackWard());    //设置后复权

           AddDataFlag(Enum_Data_RolloverRealPrice());    //设置映射真实价格

           AddDataFlag(Enum_Data_AutoSwapPosition());    //设置自动换仓

           AddDataFlag(Enum_Data_IgnoreSwapSignalCalc());    //设置忽略换仓信号计算

           //=========交易相关设置==============

           SetSlippage(Enum_Rate_PointPerHand, 1);   //设置滑点为1跳/手

       }

   }

   OnBarOpen(ArrayRef<Integer> indexes)

   {

       //----------------------------------下面代码未能用FOR遍历解决计算过程---------------------------

       //与数据源有关

       Range[0:DataCount - 1]

       {

           //收益率参数计算

           score = Close[1] / Close[5] ;

           Commentary("得分" + Text(score));

       }

       //----------------------------------下面代码未能用FOR遍历解决计算过程---------------------------

       score0 = Data0.score;

       score1 = Data1.score;

       score2 = Data2.score;

       score3 = Data3.score;

       PlotNumeric("分值0", score0);

       PlotNumeric("分值1", score1);

       PlotNumeric("分值2", score2);

       PlotNumeric("分值3", score3);

//计算品种可开仓该品种的数量

       lots = IntPart(risk / 100 * (Portfolio_CurrentCapital()+Portfolio_UsedMargin()))/(ContractUnit()*BigPointValue());

//分值  筛选出最大值的图层pq

       ww = Max(Max(Max(Data0.score, Data1.score), Data2.score), Data3.score);

       pq = 0;

       For p = 0 To (DataCount - 1)

       {

           pq = pq + 1;

           If(ww == Data[p].score)

           {

               pq_value = pq - 1;

           }

       }

       Print("=================");

       Print("Date" + Text(Date));

       Print("Data数量:" + Text(DataCount));

       Print("最大图层等于:" + Text(pq_value));

       Print("最大值等于:" + Text(ww));

       Print("一、最大图层值等于:" + Text(Data[pq_value].score));

//判断是否持仓 进行买卖

       //有持仓 持仓图层:pq_hold 之前计算出来的最大图层:pq_value

       pq_hold = -1;

       For m = 0 To (DataCount - 1)

       {

           If(Data[m].MarketPosition == 1)

           {

               pq_hold = m;

           }

       }

       If(pq_hold == -1)

       {

           Print("无历史持仓!");

       }

       If(pq_hold != -1)

       {

           Print("持仓图层为:"+Text(pq_hold));

       }

       If(pq_hold == pq_value)

       {

           Print("二、正在持仓最大值图层:" + Text(pq_hold));

           If(Data[pq_value].score <= 0)

           {

               Data[pq_value].Sell(0, Open);

               Print("三、清掉最大值为负值的图层:" + Text(pq_hold));

           }

       }

       If(pq_hold != -1 And pq_hold != pq_value And Data[pq_value].score > 0)

       {

           Print("二、正在持仓图层:" + Text(pq_hold));

           Print("卖出前保证金占用:"+Text(Portfolio_UsedMargin()));

           Data[pq_hold].Sell(0, Open);

           Print("三、卖出持仓图层:" + Text(pq_hold));

           //仓位

           //二选一

           lots = (risk / 100 * (Portfolio_CurrentCapital()+Portfolio_UsedMargin()))/(Data[pq_value].Open * Data[pq_value].ContractUnit() * Data[pq_value].MarginRatio);

           lots = IntPart(lots);

           Print("公式买入数量:"+Text(lots1));

           Data[pq_value].Buy(lots, Open);

           Print("四、买入最大值图层:" + Text(pq_value));

       }

       //无持仓

       m_result = 0;

       For m = 0 To (DataCount - 1)

       {

           m_result = m_result + Data[m].MarketPosition;

       }

       If(m_result == 0 And Data[pq_value].score > 0)

       {

           Print("当前无持仓,且分值为正值!");

           lots1 = (risk / 100 * (Portfolio_CurrentCapital()+Portfolio_UsedMargin()))/(Data[pq_value].Open * Data[pq_value].ContractUnit() * Data[pq_value].MarginRatio);  

           lots1 = IntPart(lots1);

           Data[pq_value].Buy(lots1, Open);

           Print("二、开仓最大值图层:" + Text(pq_value));

       }

       //负分值离场模块

       For i = 0 to (DataCount -1)

       {

          If(Data[i].MarketPosition == 1 And Data[i].score < 0)

           {

               Data[pq_value].Sell(0, Open);

               Print("##负值清掉!##");

           }

       }

       Print("可用资金2:"+Text(Portfolio_CurrentCapital()));

       Print("保证金占用2:"+Text(Portfolio_UsedMargin()));

       Print("--占用保证金--");

       Print("D0:"+Text(Data0.Portfolio_UsedMargin()));

       Print("D1:"+Text(Data1.Portfolio_UsedMargin()));

       Print("D2:"+Text(Data2.Portfolio_UsedMargin()));

       Print("D3:"+Text(Data3.Portfolio_UsedMargin()));

   }


   

请教!关于多品种,跨周期,多图层
多周期,只设置图层时间,品种手选
请教!多品种,跨周期,多图层,RANGE下获取当前品种交易结束时间。
请教!MarketPosition,AvgEntryPrice,CurrentContracts等函数在多品种,多图层下是否可用?比如:
如何让多图层只加载0图层的K线图表?
多图层onBar(),各品种bar的时间对齐问题
多图层
关于相应图层的品种名称判断的问题
多图层的触发和运行顺序
白糖图层空单持仓量的疑虑

是不是对应图层的数据没赋值,只赋值了data0

lots每个图层的lots都要赋值


data0.lots和data1.lots不同

感谢感谢 搞定了 😁