CCI由美国股市分析家唐纳德·蓝伯特提出,是一种超买超卖指标,重点研判股价偏离度。策略在均线判定趋势以后,运用经典的CCI入场信号进场,利用固定比例止损,当CCI达到出场信号,并且达到预期盈利离场。
源码如下:
//适用软件:交易开拓者
//公式名称:CCI与移动平均线策略
//数据周期:15M等
//数据合约:指数合约
//交易合约:主力合约
//适合品种:商品期货
//官方网站:www.quant.la
Params
Numeric N(200);
Numeric M(5);
Numeric X(1);
Numeric Fund(20000);
Vars
NumericSeries CC(0);
Numeric Mean( 0 );
Numeric AvgDev( 0 );
Numeric Counter( 0 ) ;
NumericSeries CCI(0);
NumericSeries MACC(0);
NumericSeries Lots(0);
BoolSeries BuyK(false);
BoolSeries SellK(false);
BoolSeries BuyS(false);
BoolSeries SellS(false);
BoolSeries BuyY(false);
BoolSeries SellY(false);
Begin
CC = High + Low + Close;
Mean = AverageFC( CC, N ) ;
AvgDev = 0 ;
for Counter = 0 to N - 1
{
AvgDev = AvgDev + Abs( CC[Counter] - Mean ) ;
}
AvgDev = AvgDev / N ;
if( AvgDev == 0)
CCI = 0;
Else
CCI = ( CC - Mean ) / ( 0.015 * AvgDev ) ;
MACC=AverageFC(C,N*M);
Lots=max(1,intpart(Fund/(O*ContractUnit*BigPointValue*MarginRatio)));
BuyK=CrossOver(CCI,100) AND C>MACC;
SellK=CrossUnder(CCI,-100) AND C<MACC;
SellY=CCI<0 AND C>entryprice*(1+X*0.01);
BuyY=CCI>0 AND C<entryprice*(1-X*0.01);
SellS=C<=entryprice*(1-X*0.01);
BuyS=C>=entryprice*(1+X*0.01);
If (MarketPosition==0 and CurrentBar>N*M and BuyK[1])
{
Buy(Lots,O);
Commentary("C21BK");
}
If (MarketPosition==0 and CurrentBar>N*M and SellK[1])
{
SellShort(Lots,O);
Commentary("C21SK");
}
If (MarketPosition>0 and BarsSinceEntry>1 and SellS[1])
{
Sell(0,O);
Commentary("C21SS");
}
If (MarketPosition<0 and BarsSinceEntry>1 and BuyS[1])
{
BuyToCover(0,O);
Commentary("C21BS");
}
If (MarketPosition>0 and BarsSinceEntry>1 and SellY[1])
{
Sell(0,O);
Commentary("C21SY");
}
If (MarketPosition<0 and BarsSinceEntry>1 and BuyY[1])
{
BuyToCover(0,O);
Commentary("C21BY");
}
End
标签:false,模型,Numeric,AvgDev,CCI,BoolSeries,Commentary,开拓者 From: https://www.cnblogs.com/bluejj/p/17963642