以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://222.73.7.161/bbs/index.asp)
--  公式模型编写问题提交  (http://222.73.7.161/bbs/list.asp?boardid=4)
----  新加条件,求指导  (http://222.73.7.161/bbs/dispbbs.asp?boardid=4&id=166943)

--  作者:f三年
--  发布时间:2018/12/9 17:10:18
--  新加条件,求指导
老师 ,我想在这个程序的基础上  加一个条件   增加条件:    如果品种的布林带宽大于4atr,开仓仓位减半。请教老师我这个条件怎么编写增加进去程序。

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);{止损块在有持仓时运行}


--  作者:FireScript
--  发布时间:2018/12/10 9:47:54
--  
 布林带宽 这个怎么定义的?


图片点击可在新窗口打开查看此主题相关图片如下:temp.png
图片点击可在新窗口打开查看



MID :  MA(CLOSE,M);
UPPER: MID + N*STD(CLOSE,M);
LOWER: MID - N*STD(CLOSE,M);
布林带代码是这样定义的,但是你这个布林带宽是指上下轨差值?
[此贴子已经被作者于2018/12/10 9:48:20编辑过]

--  作者:f三年
--  发布时间:2018/12/10 14:20:35
--  
是的   老师  M是定义 26
--  作者:FireScript
--  发布时间:2018/12/10 14:23:25
--  
 不是,我问的不是M啊。是这个布林带宽 。
[此贴子已经被作者于2018/12/10 14:28:25编辑过]

--  作者:f三年
--  发布时间:2018/12/10 14:25:51
--  
这个布林带宽是指上下轨差值,然后我要新增那个条件进去  
--  作者:FireScript
--  发布时间:2018/12/10 14:35:30
--  
 加一点代码,这个m,n的定义你自行处理下。

MID :  MA(CLOSE,M);
UPPER: MID + N*STD(CLOSE,M);
LOWER: MID - N*STD(CLOSE,M);
cd:UPPER-LOWER)>4*atr;


然后开仓语句这里也修改下
if tbuyholding(1)=0 and kd then tbuy(kd,if(cd,CEILING(n/2),n),mkt);
if tsellholding(1)=0 and kk then tbuyshort(kk,if(cd,CEILING(n/2),n),mkt);


--  作者:f三年
--  发布时间:2018/12/10 15:16:27
--  
PDC:=REF(C,1);
TR1:=MAX(H-L,MAX(H-PDC,PDC-L));
ATR:=MA(TR1,20);
绝对波幅:=ATR*DYNAINFO(209);
MID1 :=  MA(CLOSE,26);
UPPER1: =MID + 2*STD(CLOSE,26);
LOWER1: =MID - 2*STD(CLOSE,26);
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 upper1 - lower1>4*atr and tbuyholding(1)=0 then tbuy(1,n/2,mkt);
if  upper1 - lower1<4*atr and tsellshort(1)=0 then tbuyshort(1,n/2,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);{止损块在有持仓时运行}



运行时  if  upper1 - lower1<4*atr and tsellshort(1)=0 then tbuyshort(1,n/2,mkt);这句提示tsellshort不得在其他函数中作为参数被调用,怎么修改 。








--  作者:FireScript
--  发布时间:2018/12/10 15:27:45
--  
 if  upper1 - lower1<4*atr and tsellshort(1)=0 then tbuyshort(1,n/2,mkt);
你加的这个是啥意思。
tsellshort是平空的语句,没有这样的用法的,你想表达的是什么呢?

--  作者:f三年
--  发布时间:2018/12/10 15:42:03
--  
我已经完整写好了  老师帮我看下 是不是

TR=Max(H-L,H-PDC,PDC-L)
其中:
      TR=真实波幅
      H=当日最高价
      L=当日最低价
      PDC=前一日收盘价

如果品种的布林带宽大于4atr,开仓仓位减半
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);
MID :=  MA(CLOSE,26);
UPPER1: =MID + 2*STD(CLOSE,26);
LOWER1: =MID - 2*STD(CLOSE,26);
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 upper1 - lower1>4*atr and tbuyholding(1)=0 then tbuy(1,n/2,mkt);
if  upper1 - lower1<4*atr and tsellholding(1)=0 then tbuyshort(1,n/2,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);{止损块在有持仓时运行}

--  作者:FireScript
--  发布时间:2018/12/10 16:25:56
--  
 n/2你要取整吧。除的结果不一定是整数哦。其他基本没啥问题。