一个简单只做空的策略,每次修改下单手数都要从公式修改,能不能改成像修改参数一样,直接在策略里改。
代码如下:
Vars
//此处添加变量
Numeric highline;
Numeric lowline;
Numeric Lots(5);
Events
OnBar(ArrayRef<Integer> indexs)
{
highline=Highest(High[1],20);
lowline= Lowest(Low[1],20);
IF(MarketPosition<>-1 And Low<=lowline)
SellShort(Lots,Min(Open,lowline));
If(MarketPosition<>1 And High>=highline)
BuyToCover(Lots,Max(Open,highline));
}
Lots不是变量吗,怎么放到参数里去呢?
Params
Numeric Lots(5);
Vars
//此处添加变量
Numeric highline;
Numeric lowline;
Events
OnBar(ArrayRef<Integer> indexs)
{
highline=Highest(High[1],20);
lowline= Lowest(Low[1],20);
IF(MarketPosition<>-1 And Low<=lowline)
SellShort(Lots,Min(Open,lowline));
If(MarketPosition<>1 And High>=highline)
BuyToCover(Lots,Max(Open,highline));
}
虽然用户都不想成为程序员,但既然选择了量化这条路,基本知识还是要学习的。
把Lots的声明放到Params里不就可以了。