比如我用四周跑,螺纹我设置市值30万,每次开仓10手为例,系统默认的代码是多头开仓10手,空头却只开仓1手,所有品种都是这样 多头市值对的,空头不管市值多少都只开仓一手,我想把他改为空头也能按市值开仓,需要在哪里做修改,以下是代码:
Params
Numeric money(100); //开仓市值:单位万元
Numeric length(20); //四周的周期
Numeric hcrate(15); //价格回撤%
Vars
Series<bool> pickCond; //是否满足选股表达式
Series<Numeric> highline;
Series<Numeric> lowline;
Series<Numeric> buylasthigh(0,2); //买持仓价格峰值
Series<Numeric> selllastlow(0,2); //卖持仓价格低谷
Events
OnBar(ArrayRef<Integer> indexs)
{
Integer i = 0;
range[i = 0:datacount-1]
{
//使用IsAllPickCondition()判断当前Bar是否满足选股表达式,
pickCond = IsAllPickCondition();
Numeric TempUnitMoney=Open/rollover*ContractUnit*BigPointValue;
numeric lots=Round(10000*money/TempUnitMoney/baseshares,0)*baseshares;
highline=Highest(High[1],length);
lowline=Lowest(Low[1],length);
if(MarketPosition==1 and Low<=buylasthigh*(1-0.01*hcrate) and buylasthigh>EntryPrice*(1+0.01*6))
{Sell(0,Min(Open,buylasthigh*(1-0.01*hcrate)));Return;}
if(MarketPosition==-1 and High>=selllastlow*(1+0.01*hcrate) and selllastlow<EntryPrice*(1-0.01*6))
{BuyToCover(0,Max(Open,selllastlow*(1+0.01*hcrate)));Return;}
If(MarketPosition<>1 And High>=highline and pickCond[1]) //在开仓的时候确认下是否被选中
Buy(lots,Max(Open,highline));
If(MarketPosition<>-1 And Low<=lowline)
SellShort(0,Min(Open,lowline));
If(MarketPosition==1)
{
If(BarsSinceEntry==0)
buylasthigh=EntryPrice;
Else
buylasthigh=Max(High,buylasthigh);
}
If(MarketPosition==-1)
{
If(BarsSinceEntry==0)
selllastlow=EntryPrice;
Else
selllastlow=Min(Low,selllastlow);
}
}
}
lots 是你计算的手数,你里面开空手数填的是0