老师请问个问题,指数做信号 主连做交易回测。

data0.  做信号   data1. 做交易回测,我出来的怎么是这样,

data-href=

Params

//此处添加参数

Numeric N(20);

Numeric M(5);

Numeric Fund(20000);

Numeric SS(10);


Vars

//此处添加变量

Numeric Lots( 0 );

Series<Numeric> C_O( 0 );

Series<Numeric> Band( 0 );

Series<Numeric> Price_BPK( 0 );

Series<Numeric> Price_SPK( 0 );

Series<Numeric> Price_BP( 0 );

Series<Numeric> Price_SP( 0 );

Series<Bool> B( False );

Series<Bool> S( False );

Series<Bool> BuyPK(false);

Series<Bool> SellPK(false);

Series<Bool> BuyS(false);

Series<Bool> SellS(false);  

Series<Bool> BuyP(false);

Series<Bool> SellP(false);

   Numeric TotalEquity;                    // 按最新收盘价计算出的总资产

       Numeric TurtleUnits1;                    // 交易单位2012.12.25

       Numeric TurtleUnits;        // 交易单位2012.12.25

       Numeric AA;          

       Numeric CC;

Events

   OnInit()

{

   {

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

       SetBeginBarMaxCount(1);

   

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


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


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


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

 

       SetOrderMap2MainSymbol(); //设置委托映射到主力

   }

   

}

OnBar(ArrayRef<Integer> indexs)

{

//Lots=max(1,intpart(Fund/(O*ContractUnit*BigPointValue*0.1)));

TotalEquity = IntPart(Portfolio_CurrentCapital + Portfolio_UsedMargin())*0.01*SS;//按当前价计算可用资金+当前持仓保证金

    TurtleUnits1 = TotalEquity/(ContractUnit()* CloseD(1)*MarginRatio());   // 交易单位=((按当前价计算可用资金+当前持仓保证金)*0.3)/(合约价格*该合约一个整数点价值)

    Lots = IntPart(TurtleUnits1); // 对小数取整

    //TurtleUnits = Lots;

C_O=XAverage(C,N)-XAverage(O,N);

B=CrossOver(C_O,0);

S=CrossUnder(C_O,0);

Band=AvgTrueRange(N)*0.1*M;


If (B)

{

Price_BPK=H+Band;

Price_SP=L-Band;

}

If (S)

{

Price_SPK=L-Band;

Price_BP=H+Band;

}


BuyPK=C_O>0  AND C>=Price_BPK;

SellPK=C_O<0  AND C<=Price_SPK;


SellP=S;

BuyP=B;


SellS=C<=Price_SP;

BuyS=C>=Price_BP;

If (MarketPosition<=0 and CurrentBar>N and BuyPK[1])

{

data1.Buy(Lots,O);

Commentary(BPK);

}

If (MarketPosition>=0 and CurrentBar>N and SellPK[1])

{

data1.SellShort(Lots,O);

Commentary(SPK);

}

If (MarketPosition>0 and BarsSinceEntry>1 and SellS[1])

{

data1.Sell(0,O);

Commentary(SS);

}

If  (MarketPosition<0 and BarsSinceEntry>1 and BuyS[1])

{

data1.BuyToCover(0,O);

Commentary(BS);

}


If (MarketPosition>0 and BarsSinceEntry>1 and SellP[1])

{

data1.Sell(0,O);

Commentary(SP);

}

If  (MarketPosition<0 and BarsSinceEntry>1 and BuyP[1])

{

data1.BuyToCover(0,O);

Commentary(BP);

}

}




实盘时公式采用指数000还是主连888?
问个问题,历史回测数据主连会有换月失真的情况,怎么处理
老师,请问您觉得做回测用指数好还是用主连好啊?
TBQ指数映射次主连,是否能实盘下单到具体次主合约?
关于000指数和888主连的问题
指数合约如何映射到主连并回测
请问怎么实现指数信号,主连开仓?
如何用tbpy做多品种交易?
回测能否实现指数判断信号,主力下单
做交易需要天赋吗?

老师我自己解决了,谢谢

 OnInit()

   {

       //设置最大连续建仓次数

       data1.SetConsecEntries(1);

   }

OnBar(ArrayRef<Integer> indexs)

{

range[0:1]

{

Lots = ss;

}