//aberration策略================================================
//---------------------------------------------------------------------
Params
Numeric length (80);
Numeric lots (0);
Vars
Series<Numeric> avgout(0);
Series<Numeric> avgout2(0);
Series<Numeric> avgout3(0);
Series<Numeric> avgout4(0);
Series<Numeric> avgout5(0);
Series<Numeric> myvolav(0);
Series<Numeric> lps(0);
Series<Numeric> sps(0);
Series<Numeric> ps(0);
Series<Numeric> cnt(0);
Series<Numeric> lepnce(0);
Series<Numeric> sepnce(0);
Series<Numeric> sigma(0);
Events
OnBar(ArrayRef<Integer> indexs)
{
AvgOut =Average (close,length);
AvgOut2 =Average (close,length-intpart (length/8));
AvgOut3 =Average (close,length-intpart (length/8)*2);
AvgOut4 =Average (close,length-intpart (length/8)*3);
AvgOut5 =Average (close,length-intpart (length/8)*4);
sigma=(StandardDev(close,length)*2);
myvolav =(sigma+sigma[1] +sigma[2])/3;
lepnce=AvgOut+sigma;
sepnce=AvgOut-sigma;
//突破一倍标准差,进行建仓,限制条件中,有一条是必须跌回了最长期的均线后才能开仓,即是lps==0;
if(MarketPosition<1 and Close[1]>lepnce[1]and sigma[1] > myvolav [1] and lps==0)
{
ps=Close[1] +sigma [1];
cnt =1;
Buy(lots,open);
if(MarketPosition>-1 and Close[1]<sepnce[1]and sigma[1] > myvolav[1] and sps==0)
{
SellShort(lots,open);
ps=Close[1] -sigma [1];
cnt=1;
//跌破均线,进行平仓,盈利越多,跌破的均线周期越短
if(Marketposition==1 and close[1] < avgout [1] and cnt==1)
{
sell(0,open);
lps=0;
}
if(Marketposition==1 and close[1] < avgout2 [1] and cnt==2)
{
sell(0,open);
lps=1;
}
if(Marketposition==1 and close[1] < avgout3 [1] and cnt==3)
{
sell(0,open);
lps=1;
if(Marketposition==1 and close[1] < avgout4 [1] and cnt==4)
{
sell(0,open);
lps=1;
}
if(Marketposition==1 and close[1] < avgout5 [1] and cnt==5)
{
sell(0,open);
lps=1;
}
if(Marketposition==1 and cnt==6)
{
sell(0,open);
lps=1;
}
//开空
if(Marketposition==-1 and close[1] > avgout [1] and cnt==1)
{
BuyToCover(0,open);
SPS=0;
}
if(Marketposition==-1 and close[1] >avgout2 [1] and cnt==2)
{
BuyToCover(0,open);
SPS=1;
}
if(Marketposition==-1 and close[1] > avgout3 [1] and cnt==3)
{
BuyToCover (0,open);
SPS =1;
if(Marketposition==-1 and close[1] > avgout4 [1] and cnt==4)
{
BuyToCover(0,open);
SPS =1;
}
if(Marketposition==-1 and close[1] > avgout5 [1] and cnt==5)
{
BuyTocover(0,open);
SPS=1;
}
if(Marketposition==-1 and cnt==6)
{
BuyToCover(0,open);
SPS=1;
}
//更新盈利级别,按照sigma递增
if(MarketPosition==1 and close [1]>ps)
{
cnt=cnt+1;
ps=close[1]+sigma[1];
}
if(MarketPosition==-1 and close [1]<ps)
{
cnt=cnt+1;
ps=close[1]-sigma[1];
}
//只有当跌破最长期的均线后,才能准备下一次的开仓
if(sps ==1 and Close[1]>avgout[1])sps =0;
if(lps ==1 and Close[1]<avgout[1])lps =0;
}
}
}
我刚测试了这个策略,根本没法用啊
这不是已经是tbquant语法了吗
tbquant上,编译过不去,不知道为什么
编译不了,是因为代码内有多个大括号不对称,改下就好了。
//aberration策略================================================
//---------------------------------------------------------------------
Params
Numeric length (80);
Numeric lots (0);
Vars
Series<Numeric> avgout(0);
Series<Numeric> avgout2(0);
Series<Numeric> avgout3(0);
Series<Numeric> avgout4(0);
Series<Numeric> avgout5(0);
Series<Numeric> myvolav(0);
Series<Numeric> lps(0);
Series<Numeric> sps(0);
Series<Numeric> ps(0);
Series<Numeric> cnt(0);
Series<Numeric> lepnce(0);
Series<Numeric> sepnce(0);
Series<Numeric> sigma(0);
Events
OnBar(ArrayRef<Integer> indexs)
{
AvgOut =Average (close,length);
AvgOut2 =Average (close,length-intpart (length/8));
AvgOut3 =Average (close,length-intpart (length/8)*2);
AvgOut4 =Average (close,length-intpart (length/8)*3);
AvgOut5 =Average (close,length-intpart (length/8)*4);
sigma=(StandardDev(close,length)*2);
myvolav =(sigma+sigma[1] +sigma[2])/3;
lepnce=AvgOut+sigma;
sepnce=AvgOut-sigma;
//突破一倍标准差,进行建仓,限制条件中,有一条是必须跌回了最长期的均线后才能开仓,即是lps==0;
if(MarketPosition<1 and Close[1]>lepnce[1]and sigma[1] > myvolav [1] and lps==0)
{
ps=Close[1] +sigma [1];
cnt =1;
Buy(lots,open);
}
if(MarketPosition>-1 and Close[1]<sepnce[1]and sigma[1] > myvolav[1] and sps==0)
{
SellShort(lots,open);
ps=Close[1] -sigma [1];
cnt=1;
}
//跌破均线,进行平仓,盈利越多,跌破的均线周期越短
if(Marketposition==1 and close[1] < avgout [1] and cnt==1)
{
sell(0,open);
lps=0;
}
if(Marketposition==1 and close[1] < avgout2 [1] and cnt==2)
{
sell(0,open);
lps=1;
}
if(Marketposition==1 and close[1] < avgout3 [1] and cnt==3)
{
sell(0,open);
lps=1;
}
if(Marketposition==1 and close[1] < avgout4 [1] and cnt==4)
{
sell(0,open);
lps=1;
}
if(Marketposition==1 and close[1] < avgout5 [1] and cnt==5)
{
sell(0,open);
lps=1;
}
if(Marketposition==1 and cnt==6)
{
sell(0,open);
lps=1;
}
//开空
if(Marketposition==-1 and close[1] > avgout [1] and cnt==1)
{
BuyToCover(0,open);
SPS=0;
}
if(Marketposition==-1 and close[1] >avgout2 [1] and cnt==2)
{
BuyToCover(0,open);
SPS=1;
}
if(Marketposition==-1 and close[1] > avgout3 [1] and cnt==3)
{
BuyToCover (0,open);
SPS =1;
}
if(Marketposition==-1 and close[1] > avgout4 [1] and cnt==4)
{
BuyToCover(0,open);
SPS =1;
}
if(Marketposition==-1 and close[1] > avgout5 [1] and cnt==5)
{
BuyTocover(0,open);
SPS=1;
}
if(Marketposition==-1 and cnt==6)
{
BuyToCover(0,open);
SPS=1;
}
//更新盈利级别,按照sigma递增
if(MarketPosition==1 and close [1]>ps)
{
cnt=cnt+1;
ps=close[1]+sigma[1];
}
if(MarketPosition==-1 and close [1]<ps)
{
cnt=cnt+1;
ps=close[1]-sigma[1];
}
//只有当跌破最长期的均线后,才能准备下一次的开仓
if(sps ==1 and Close[1]>avgout[1])sps =0;
if(lps ==1 and Close[1]<avgout[1])lps =0;
}
谢谢