variable:hh=0,cishu=0;
kcond:= c>o and ref(c,1)>ref(o,1) ;
mid_boll:=stkindi('','boll.mid',0,3);
mid_boll2:= stkindi('','boll,min',0,3,-1);
bollcond:= o>mid_boll and ref(o,1)>mid_boll2;
opencond:= c>o+15*mindiff and ref(c,1)>ref(o,1)+15*mindiff;
if kcond and bollcond and opencond and cishu=0 then begin
buy(holding=0,1,market);
hh:=h;
cishu:=1;
end
if h>hh then hh:=h;
if hh<enterprice+60*mindiff and c<=enterprice*1.03 then begin
sell(holding>0,0,limitr,hh-60*mindiff);//当最大值<(开仓值+60个单位),则止损位=最大值-60个单位;
hh:=0;
cishu:=0;
end
if enterprice*1.02>=hh and hh>=o+60*mindiff and c<=enterprice*1.03 then begin//当(开仓值*1.02)>=最大值>=(开仓值+60个单位),则止损位=开仓值+1个单位;
sell(holding>0,0,limitr,ENTERPRICE+mindiff);
hh:=0;
cishu:=0;
end
if hh>ENTERPRICE*1.02 and c<=enterprice*1.03 then begin//当最大值>(开仓值*1.02),则止损位=最大值*0.98;
sell(holding>0,0,limitr,hh*0.98);
hh:=0;
cishu:=0;
end
if time>144500 and c<enterprice*1.03 then begin //当日内14:45分时,若现值<(开仓值*1.03),则现价平仓;
sell(holding>0,0,limitr,c);
hh:=0;
cishu:=0;
end
免责声明:本人也是初学者,因为对楼主的止损策略感了兴趣,所以试着写了这个策略,有不对的地方请大家指正。
经测试,楼主的第四行止损策略好像有问题?红框处。但总体还可以
源码,我用的K线走完模式:
INPUT:M(26,5,500,30);
INPUT:M(2,0.1,10,1);
INPUT:M(0.2,0.2,10,0.2);
MID : MA(CLOSE,M);
UPPER: MID + N*STD(CLOSE,M);
LOWER: MID - N*STD(CLOSE,M);
多:=ALL(C>O+15*X,2) AND ALL(O>MID,2);
空:=ALL(C<O-15*X,2) AND ALL(O<MID,2);
if 多 then begin
sellshort(holding<0, 0, thisclose);
buy(holding=0 , 1, thisclose);
end
HH:=HHV(H,BARSLAST(HOLDING<=0));
多止损1:HH<Enterprice+60*X AND C<=HH-60*X ,LINETHICK0;
多止损2:Enterprice*1.02>=HH AND HH>=Enterprice+60*X AND C<Enterprice+2*X ,LINETHICK0;
多止损3:HH>Enterprice*1.02 AND C<HH*0.98 ,LINETHICK0;
多止损4:TIME>144000 AND C<Enterprice*1.03 ,LINETHICK0;
if 多止损1 OR 多止损2 OR 多止损3 OR 多止损4 then sell(holding>0, 0, thisclose);
if 空 then begin
sell(holding>0, 0, thisclose);
buyshort(holding=0 , 1, thisclose);
end
LL:=LLV(L,BARSLAST(HOLDING>=0));
空止损1:LL>Enterprice-60*X AND C>=LL+60*X ,LINETHICK0;
空止损2:Enterprice<=LL*1.02 AND LL<=Enterprice-60*X AND C>Enterprice-2*X ,LINETHICK0;
空止损3:LL*1.02<Enterprice AND C*0.98>LL ,LINETHICK0;
空止损4:TIME>144000 AND C*1.03>Enterprice ,LINETHICK0;
if 空止损1 OR 空止损2 OR 空止损3 OR 空止损4 then sellshort(holding<0, 0, thisclose);
上面参数错了,更正
INPUT:M(26,5,500,30);
INPUT:N(2,0.1,10,1);
INPUT:X(0.2,0.2,10,0.2);
MID : MA(CLOSE,M);
UPPER: MID + N*STD(CLOSE,M);
LOWER: MID - N*STD(CLOSE,M);
多:=ALL(C>O+15*X,2) AND ALL(O>MID,2);
空:=ALL(C<O-15*X,2) AND ALL(O<MID,2);
if 多 then begin
sellshort(holding<0, 0, thisclose);
buy(holding=0 {AND TIME<144000}, 1, thisclose);
end
HH:=HHV(H,BARSLAST(HOLDING<=0));
多止损1:HH<Enterprice+60*X AND C<=HH-60*X ,LINETHICK0;
多止损2:Enterprice*1.02>=HH AND HH>=Enterprice+60*X AND C<Enterprice+2*X ,LINETHICK0;
多止损3:HH>Enterprice*1.02 AND C<HH*0.98 ,LINETHICK0;
多止损4:TIME>144000 AND C<Enterprice*1.03 ,LINETHICK0;
if 多止损1 OR 多止损2 OR 多止损3 OR 多止损4 then sell(holding>0, 0, thisclose);
if 空 then begin
sell(holding>0, 0, thisclose);
buyshort(holding=0 {AND TIME<144000}, 1, thisclose);
end
LL:=LLV(L,BARSLAST(HOLDING>=0));
空止损1:LL>Enterprice-60*X AND C>=LL+60*X ,LINETHICK0;
空止损2:Enterprice<=LL*1.02 AND LL<=Enterprice-60*X AND C>Enterprice-2*X ,LINETHICK0;
空止损3:LL*1.02<Enterprice AND C*0.98>LL ,LINETHICK0;
空止损4:TIME>144000 AND C*1.03>Enterprice ,LINETHICK0;
if 空止损1 OR 空止损2 OR 空止损3 OR 空止损4 then sellshort(holding<0, 0, thisclose);