buy和sellshort的问题,以buy为例,在空头时,有的品种执行buy后,只有买入开仓的操作,没有买入平仓的操作
Params
Numeric Length1(50); //长周期区间参数
Numeric Length2(30); //短周期区间参数
Numeric IPS(4); //保护止损波动率参数
Numeric AtrVal(10); //波动率参数
Numeric initcapital(50); //单位:万 国债期货可以改成50
Numeric Acceleration(0.05); //抛物线的加速系数
Numeric FirstBarMultp(5); //用于计算在进场Bar设置止损价的系数
Vars
natural Series<Numeric> myprice; //临界价格
natural Series<Numeric> myprice_temp; //临时的临界价格
natural Series<Numeric> myprice_new; //记录因为止损而产生的新的临界价格
natural Series<Numeric> nn; //向前计算的日期
Numeric temp10; //控制onbarclose的开仓次数
Array<Numeric> timepoint([0.145850]);
natural Series<Numeric> cros;
natural Numeric clo_temp; //收盘平仓价
natural Series<Numeric> i; //循环参数
//Numeric lots(1); //下单手数
natural Numeric lots;
OnBarClose(ArrayRef<Integer> indexs)
{
//Lots=IntPart(Portfolio_CurrentCapital*1/(open*contractunit*BigPointValue));
range[1:1]
{
If(time==0.1458)
{
clo_temp=close;
temp10=0;
}
If(data0.Marketposition ==1 and clo_temp<data0.cros and time==0.1458 and temp10==0)
{
//Sell(data0.lots, Open);
SellShort(data0.lots, Open);
temp10=1;
}
If(data0.Marketposition ==-1 and clo_temp>data0.cros and time==0.1458 and temp10==0)
{
//BuyToCover(data0.lots, Open);
buy(data0.lots, Open);
temp10=1;
}