399330深证100指数的一个策略
通达信代码:
BARS:COUNT(C>0,0) NODRAW;
START_C_CONS :=REF(C,BARSCOUNT(C)); ROC1 :=100* (C/REF(C,1)-1) ;
PRICE:=(H+L+C)/3;
IC:="399330$C";
DMA8: DMA(C, AMOUNT/SUM(AMOUNT,N) ) COLORWHITE;
{DMA8: MA(PRICE, N);}
DMA13: DMA(C, AMOUNT/SUM(AMOUNT,20) ) COLORMAGENTA;
B1:= C>DMA8;
BUY(B1, L/1.05);
SELL(C<DMA8, H*1.05);
AUTOFILTER;
BBARS:=BUYBARS NODRAW COLORWHITE;
SBARS:=SELLBARS NODRAW COLORWHITE;
POS:= IF(BBARS<SBARS,1,0);
EQ:MULAR(1+ROC1*POS/100, 0) * START_C_CONS COLORCYAN LINETHICK2;
BP:=BUYPRICE;
SP:=SELLPRICE;
PNL:=IF(SELLBARS=1, (SP/BP -1)*100, DRAWNULL) NODRAW COLORWHITE;
TOTAL_D:= IF(BARS=1, DAYSTOTODAY, DRAWNULL);
TOT_YEARS:= REF(TOTAL_D/365, BARSCOUNT(C));
N_WIN:=COUNT(PNL>0,0); N_LOSS:=COUNT(PNL<0,0); WIN_RATE:=N_WIN/(N_WIN+N_LOSS) * 100;
NUM_TRADES:=COUNT(SELLBARS=1,0);
NTLINE:= VALUEWHEN(SELLBARS=1, NUM_TRADES);
{
DRAWTEXT(SELLBARS=1, H1.1, VARCAT(VAR2STR(PNL,2), '%'));
DRAWTEXT(SELLBARS=1, H1.15, VARCAT(VAR2STR(NUM_TRADES,0), '次'));
}
HOLD_BARS_PER_T:= IF(SELLBARS=1, BUYBARS, DRAWNULL) ;
TOTAL_HOLD_BARS:= SUM(HOLD_BARS_PER_T,0) NODRAW;
FINAL_GR:=IF(CURRBARSCOUNT=1, EQ/START_C_CONS, DRAWNULL);
CAGR:= (POW(FINAL_GR, 1/TOT_YEARS)-1)*100;
NDATE:=DATE+19000000 NODRAW; STEP:=0.03;
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP0,0, VARCAT( '权益指数 = ', VAR2STR(EQ/START_C_CONS,2)) );
DRAWTEXT_FIX(BARS=1 , 0.1,STEP1,0, VARCAT('开始日期 = ', VAR2STR(NDATE,0)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP2,0, VARCAT('结束日期 = ', VAR2STR(NDATE,0)) );
DRAWTEXT_FIX(BARS=1 ,0.1,STEP3,0, VARCAT('期间年数 = ', VAR2STR(DAYSTOTODAY/365,2)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP4,0, VARCAT('CAGR(%)= ', VAR2STR(CAGR,2)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP5,0, VARCAT('交易次数 = ', VAR2STR(NTLINE,0)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP6,0, VARCAT('盈利次数 = ', VAR2STR(N_WIN,0)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP7,0, VARCAT('亏损次数 = ', VAR2STR(N_LOSS,0)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP8,0, VARCAT('年均次数 = ', VAR2STR(NTLINE/TOT_YEARS,2)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP9,0, VARCAT('胜率(%) = ', VAR2STR(WIN_RATE,2)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP10,0, VARCAT('持仓率% = ', VAR2STR(TOTAL_HOLD_BARS/BARS100,2)) );
DRAWTEXT_FIX(CURRBARSCOUNT=1 ,0.1,STEP*11,0, VARCAT('平均持期 = ', VAR2STR(TOTAL_HOLD_BARS/NTLINE, 2)) );