data0. 做信号 data1. 做交易回测,我出来的怎么是这样,
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);
}
}
老师我自己解决了,谢谢
OnInit()
{
//设置最大连续建仓次数
data1.SetConsecEntries(1);
}
OnBar(ArrayRef<Integer> indexs)
{
range[0:1]
{
Lots = ss;
}