想使用HANS123和横盘突破(两个金字塔自带的范例模型),但是我不会编写,现向版主求助:
如何在这两个模型里加入这两个条件:
(1)20个点止损;
(2)浮盈达到20个点后,如果再次回到开仓位置则自动平仓;
只要在原有模型中加入以上两个条件就好了,我不知道在原模型中的哪里加,请版主帮忙,不胜感激!下面是我金字塔里面横盘突破的范例模型:
//策略:横盘突破
//简介:
//类型:日内交易
//周期:1分钟
//使用市场:
//详情介绍网址:
//修订时间:2012.11.1
//DESIGNED BY ROGARZ
//准备需要的中间变量
INPUT:SS(1,1,10000,1),N1(0.005,0.001,1,0.001);
CYC:=BARSLAST(DATE<>REF(DATE,1))+1;
H30:REF(HHV(H,30),1);
L30:REF(LLV(L,30),1);
MID:(H30+L30)/2;//中轴
T1:=TIME>090000 AND TIME <145500;
T2:=TIME>=145500;
手数:=SS;
//进场的条件
开多条件:= H>H30 AND (H30-MID)/MID<N1 AND CYC>=30 AND T1;
开空条件:= L<L30 AND (MID-L30)/MID<N1 AND CYC>=30 AND T1;
//系统
收盘平多:SELL(T2 AND HOLDING>0,0,MARKET) ;
收盘平空:SELLSHORT(T2 AND HOLDING<0,0,MARKET) ;
开空:BUYSHORT(开空条件 AND HOLDING=0,手数,MARKET);
开多:BUY(开多条件 AND HOLDING=0, 手数,MARKET);
//其他
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;//输出当前资产,但不影响坐标最高最低值
(1)20个点止损;
(2)浮盈达到20个点后,如果再次回到开仓位置则自动平仓;
1.
if h-enterprice>20*mindiff then sellshort(1,0,market);
if enterprice-l>20*Mindiff then sell(1,0,market);
2.
if hhv(h,enterbars+1)>enterprice+20*mindiff and enterbars>0 and h<=enterprice then sell(1,0,market);
if llv(l,enterbars+1)<enterprice-20*MIndiff and enterbars>0 and l>=enterprice then sellshort(1,0,market);
多谢,但不知道在哪里加这两个条件?刚才家进入之后,发现开平仓信号多了起来,而这两个模型是日内只开一次仓的呀
[此贴子已经被作者于2014/2/26 11:28:51编辑过]
谢谢,加进去了。但是又出现一个问题,即20个点止损后接下来又会出现开仓的信号,而我的想法是无论是止损20个点还是盈利20个点回撤到开仓位这两种情况,之后均不再开仓了,即日内只做一次开仓,怎样处理?
求教版主:日内开第一次仓之后不再开仓了,这样的指令怎样编写?
input 后面加上这样一句
variable:n=0;
后面的代码要修改一下
1.
if h-enterprice>20*mindiff and n=0 and holding<0 then begin
sellshort(1,0,market);
n:=1;
end
if enterprice-l>20*Mindiff and n=0 and holding>0 then begin
sell(1,0,market);
n:=1;
end
2.
if hhv(h,enterbars+1)>enterprice+20*mindiff and enterbars>0 and h<=enterprice and holding>0 and n=0 then begin
sell(1,0,market);
n:=1;
end
if llv(l,enterbars+1)<enterprice-20*MIndiff and enterbars>0 and l>=enterprice and holding<0 and n=0 then begin
sellshort(1,0,market);
n:=1;
end
代码最后再添加一句
if time=closetime(0) then n:=0;
以下是我按照您给出的回复对金字塔里自带的“横盘突破”策略做的修改,可是在日内图形上还是会有二次甚至三次开仓,怎么回事?您看以下的编码哪里出问题了呢?(另注:我说的20点止损实际上是100跳,我把您给我的编码里的数值更改了一下)
下面的红色字体是您提供给我的编码,为了与原代码区别,做了颜色处理。
//准备需要的中间变量
INPUT:SS(1,1,10000,1),N1(0.005,0.001,1,0.001);
variable:n=0;
CYC:=BARSLAST(DATE<>REF(DATE,1))+1;
H30:REF(HHV(H,30),1);
L30:REF(LLV(L,30),1);
MID:(H30+L30)/2;//中轴
T1:=TIME>090000 AND TIME <145500;
T2:=TIME>=145500;
手数:=SS;
//进场的条件
开多条件:= H>H30 AND (H30-MID)/MID<N1 AND CYC>=30 AND T1;
开空条件:= L<L30 AND (MID-L30)/MID<N1 AND CYC>=30 AND T1;
//系统
收盘平多:SELL(T2 AND HOLDING>0,0,MARKET) ;
收盘平空:SELLSHORT(T2 AND HOLDING<0,0,MARKET) ;
开空:BUYSHORT(开空条件 AND HOLDING=0,手数,MARKET);
开多:BUY(开多条件 AND HOLDING=0, 手数,MARKET);
if h-enterprice>100*mindiff and n=0 and holding<0 then begin
sellshort(1,0,market);
n:=1;
end
if enterprice-l>100*Mindiff and n=0 and holding>0 then begin
sell(1,0,market);
n:=1;
end
if hhv(h,enterbars+1)>enterprice+100*mindiff and enterbars>0 and h<=enterprice and holding>0 and n=0 then begin
sell(1,0,market);
n:=1;
end
if llv(l,enterbars+1)<enterprice-100*MIndiff and enterbars>0 and l>=enterprice and holding<0 and n=0 then begin
sellshort(1,0,market);
n:=1;
end
if time=closetime(0) then n:=0;
//其他
当前持仓:HOLDING,COLORGRAY,LINETHICK0;
当前资产:ASSET,NOAXIS,COLORGRAY;//输出当前资产,但不影响坐标最高最低值
也就是不管怎么平仓的,就只开仓一次?
那么就不用这么复杂了
variable:n=0;
if 开空条件 AND HOLDING=0 and n=0 then begin
开空:BUYSHORT(开空条件 AND HOLDING=0,手数,MARKET);
n:=1;
end
if 开多条件 AND HOLDING=0 and n=0 then begin
开多:BUY(开多条件 AND HOLDING=0, 手数,MARKET);
n:=1;
end
if time=closetime(0) then n:=0;
上面的那些修改都删掉,还原为我最开始写的
然后对开仓语句做如上修改