请教老师 我下面编写的代码 语言是否准确
TR=Max(H-L,H-PDC,PDC-L)
其中:
TR=真实波幅
H=当日最高价
L=当日最低价
PDC=前一日收盘价
N(即ATR)的计算公式如下(其实就):
前面20天的TR值平均
绝对波动幅度=N*合约每一点所代表的价值
头寸规模单位n=账户的1%/绝对波动幅度
开仓时机:当价格突破20天新高的时候开n手做多,当价格回调3ATR平仓。
当价格突破20日新低的时候做空,当价格回调3ATR平仓
止损为1N
PDC:=REF(C,1);
TR1:=MAX(H-L,MAX(H-PDC,PDC-L));
ATR:=MA(TR1,20);
绝对波幅:=ATR*DYNAINFO(209);
N:=tASSET*0.01/绝对波幅;
h20:=ref(hhv(h,20),1);
l20:=ref(llv(l,20),1);
t1:=c>h20;
t2:=c<l20;
n1:=ref(ATR,BARSLAST(t1 and ref(t1,1)=0));
n2:=ref(ATR,BARSLAST(t2 and ref(t2,1)=0));
c1:=ref(c,BARSLAST(t1 and ref(t1,1)=0));
c2:=ref(c,BARSLAST(t2 and ref(t2,1)=0));
kd:cross(c,h20);
pd:c<(c1-3*n1);
kk:=cross(l20,c);
pk:=c>(c2+3*n2);
if TBUYHOLDING(1)>0 and pd then tsell(pd,n,mkt);
if tsellholding(1)>0 and pk then tsellshort(pk,n,mkt);
if tbuyholding(1)=0 and kd then tbuy(kd,n,mkt);
if tsellholding(1)=0 and kk then tbuyshort(kk,n,mkt);
if tholding>0 and c<DYNAINFO(211)-n1 then tsell(pd,n,mkt);
if tholding<0 and c>DYNAINFO(211)+n2 then tsellshort(pk,n,mkt);{止损块在有持仓时运行}