Params
Numeric money(5);//固定资金开仓,单位万;
Numeric length(20,10,60,2);//四周周期参数
Numeric hcrate(2,1,5,1);//价格回撤幅度
Numeric malength(60,20,120,10);//均线周期参数
Vars
Numeric highline;//高点连线
Numeric lowline;//低点连线
Numeric myprice;//委托价格
numeric lots;//委托数量
Series<Numeric> buylasthigh(0,2);//买持仓价格峰值
series<Numeric> selllastlow(0,2);//卖持仓价格峰值
Numeric ma60;//均线
Events
oninit()
{
Range[0:datacount-1]
{
//除权换月相关设置====
AddDataFlag(Enum_Data_RolloverBackWard());//设置后复权
AddDataFlag(Enum_Data_RolloverRealPrice());//设置映射真实价格;
AddDataFlag(Enum_Data_AutoSwapPosition());//设置自动换仓;
adddataflag(Enum_Data_IgnoreSwapSignalCalc());//设置忽略自动换仓计算;
//====交易相关设置===
//SetMarginRate(0.1);
SetInitCapital(1000000);//设置初始本金1000000
SetCommissionRate(BitOr(Enum_Rate_FreeOfExitToday,Enum_Rate_ByFillAmount),5);//设置手续费率为成交金额的5%,不收平今;
setslippage(Enum_Rate_PointPerHand,2);//设置滑点为2跳/手
SetBeginBarMaxCount(1);//设置对打起始数为1
}
}
OnBar(ArrayRef<Integer> indexs)
{
Range[0:0]
{
myprice=Open;//这里使用open/rollover,更为精确的是使用委托价格;follover是系统提供的复权系数,真实价格=后复权的价格/rollover;
lots=intpart(money*10000/(myprice*contractunit*bigpointvalue*marginratio));//计算开仓手数
ma60=Average(close[1],malength);
}
range[1:1]
{
highline=Highest(high[1],length);
lowline=lowest(low[1],length);
PlotNumeric("highline",highline);
PlotNumeric("lowline",lowline);
if(MarketPosition<>1 and high>=highline)
buy(lots,max(open,highline));
if(MarketPosition<>-1 && LOW<lowline)
sellshort(lots,min(open,lowline));
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))); //多头止盈
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)));//空头止盈
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);
}
}
}
请说说为什么感觉没有运行