在做策略回测时,买入头寸,某个公式的默认定义是buy(0,XXX),发现每次回测只买1手。我想根据当前账户资金量来确定买入头寸,于是选择了Portfolio_CurrentCapital 这个参数
——————————————————————
myprice=Open;//这里使用open,更为精确的是使用委托价格
lots=IntPart(Portfolio_CurrentCapital/(myprice*contractunit*BigPointValue*MarginRatio)); //计算开仓手数
Buy(lots, max(Open,LEPrice[1] + (ATRPcnt * AATR[1])));
——————————————————————————————————
使用以上参数后,发现部分买入信号丢失了,而且资金量的不同,买入信号也有差别。。。。。关键是资金量是2000万时,交易记录少了几笔,资金量10万时,和买入buy(0)的交易记录一样
请问老师哪里出问题了?
以下是完整公式
————————————————————————————————
Params
Numeric MomLen(5); //UWM参数
Numeric AvgLen(20); //UWM参数
Numeric ATRLen(5); //ATR参数
Numeric ATRPcnt(0.5); //入场价格波动率参数
Numeric SetupLen(5); //条件持续有效K线数
Vars
Series<Numeric> VWM(0);
Series<Numeric> AATR(0);
Series<Numeric> LEPrice(0);
Series<Numeric> SEPrice(0);
Series<Bool> BullSetup(False);
Series<Bool> BearSetup(False);
Series<Numeric> LSetup(0);
Series<Numeric> SSetup(0);
Numeric myprice; //委托价格
Numeric lots; //委托数量
Events
OnBar(ArrayRef<Integer> indexs)
{
VWM = XAverage(Vol * Momentum(Close, MomLen), AvgLen); //定义UWM
AATR = AvgTrueRange(ATRLen); //ATR
BullSetup = CrossOver(VWM,0); //UWM上穿零轴定义多头势
BearSetup = CrossUnder(VWM,0); //UWM下穿零轴定义空头势
If (BullSetup) //多头势开始计数并记录当前价格
{
LSetup = 0;
LEPrice = Close;
}
Else LSetup = LSetup[1] + 1; //每过一根BAR计数
//系统入场
IF ( CurrentBar > AvgLen And MarketPosition == 0 ) //当多头势满足并且在SetupLen的BAR数目内,当价格达到入场价格后,做多
{
If(High >= LEPrice[1] + (ATRPcnt * AATR[1]) And LSetup[1] <= SetupLen And LSetup >= 1 And Vol > 0)
{
myprice=Open;//这里使用open,更为精确的是使用委托价格
lots=IntPart(Portfolio_CurrentCapital/(myprice*contractunit*BigPointValue*MarginRatio)); //计算开仓手数
Buy(lots, max(Open,LEPrice[1] + (ATRPcnt * AATR[1])));
}
}
//系统出场
IF (MarketPosition == 1 And BarsSinceEntry>0 And Vol > 0 && lastEntryDate() <> date()) //空头势平掉多单
{
If(BearSetup[1] == True)
{
Sell(0,Open);
}
}
}