-- 作者:guotx2010
-- 发布时间:2011/1/7 11:00:46
-- 帮我看看移动停损怎么不行?
//根据笔方向,向上笔做多,向下笔做空,周期以3周期为限,以确保笔已基本形成。
//参数说明:DuoKong 决定做多还是做空 DuoKong:=1; {多空,1-都做,2-只做多,3-只做空} OrdVol:=1; {开仓手数}
var1:="chzhshch@kxian"; {处理K线} var2:="chzhshch@bi"; {处理笔关系} var3:="chzhshch@duan"; {处理段关系}
B1:=barslast(var3<>0); //段最后一次信号后的周期 B2:=ref(var3,b1); //段信号 -1为下跌段结束点 +1为上涨段结束点
A1:=barslast(var2<>0); //笔最后一次信号后的周期 A2:=ref(var2,a1); //笔信号 -1为下跌笔结束点 +1为上涨笔结束点 AA1:=ref(a1+1,1); //最后信号到现在的周期 AA2:=-ref(a2,1); //最近信号取反,如果是-1,就变为+1 AA3:=AA1+REF(AA1+1,AA1); //倒数第二个端点的周期 AA4:=AA3+REF(AA1+1,AA3); //倒数第三个端点的周期 H1:=barslast(var2=1); //高点到现在的周期 H2:=ref(var2,H1); //高点笔方向 +1 HH1:=ref(H1+1,1); //最后高点信号到现在的周期 HH2:=-ref(H2,1); //高点方向取反 -1 L1:=barslast(var2=-1); L2:=ref(var2,L1); LL1:=ref(L1+1,1); LL2:=-ref(L2,1); //G1-G5为倒数的第一至第五个高点的价位 G:=REF(H,h1); //所有高点连线 G1:=REF(H,HH1); G2:=REF(G1,HH1); G3:=REF(G2,HH1); G4:=REF(G3,HH1); G5:=REF(G4,HH1); //D1-D5为倒数的第一至第五个低点的价位 D:=REF(L,l1); //所有低点连线 D1:=REF(L,LL1); D2:=REF(D1,LL1); D3:=REF(D2,LL1); D4:=REF(D3,LL1); D5:=REF(D4,LL1);
//下跌笔结束做多 Long:=A2=-1 AND A1=4; {多单进场条件} Short:=A2=1 AND A1=4; {空单进场条件}
开仓以来最低价:=LLV(L,ENTERBARS); 开仓以来最高价:=HHV(H,ENTERBARS); //多单 If DuoKong=1 Or DuoKong=2 then begin //多单进场 IF Long and holding<0 then begin {平空}sellshort(1,0,market); {开多}Buy(Long,OrdVol,market); end End //画出多单止损线 partline(holding>0,D1,Colorred);
If Holding>0 Then Begin //多单如果盈利超过5点了,回撤3点就止盈 if 开仓以来最高价-Enterprice>5 then begin 多保:sell(开仓以来最高价-H<3,0,limitr,H); end //就是下面这段用于移动止损的,如果有利润,并且大于3,就应该自动设置高一点的止损位,可是,没有起作用 Dts:=D1; //否则就使用D1作为止损点 If Enterprice-D1>10 then //如果开仓价与低点相差大于10点,就设置止损8点 Dts:=Enterprice-8; else if H-Enterprice>3 then Dts:=Enterprice+0.6; else if H-Enterprice>6 then Dts:=Enterprice+3; else if H-Enterprice>10 then Dts:=Enterprice+6; else if H-Enterprice>15 then Dts:=Enterprice+10; else if H-Enterprice>20 then Dts:=Enterprice+15; else if H-Enterprice>25 then Dts:=Enterprice+20; 多停损:sell(1,0,stopr,Dts); //多单平仓 LongY:=C<G1 And A2=1 AND A1=4; {价格低于前一个高点,多单止赢} If LongY then begin {多单平仓}Sell(1,0,market); end End //空单 If DuoKong=1 Or DuoKong=3 then begin //空单进场 If Short then Begin {平多}Sell(holding>0,0,market); {开空}BuyShort(Short,OrdVol,market); end End //画出空单止损线 partline(holding<0,G1,ColorGreen);
If Holding<0 Then Begin //空单如果盈利超过5点了,回撤3点就止盈 if Enterprice-开仓以来最低价>5 then begin 空保:sell(L-开仓以来最低价<3,Holding,limitr,l); end Kts:=G1; //否则就使用G1作为止损点 If G1-Enterprice>10 then //如果开仓价与低点相差大于10点,就设置止损8点 Kts:=Enterprice+8; else if Enterprice-l>3 then Kts:=Enterprice-0.6; else if Enterprice-l>3 then Kts:=Enterprice-0.6; else if Enterprice-l>6 then Kts:=Enterprice-3; else if Enterprice-l>10 then Kts:=Enterprice-6; else if Enterprice-l>15 then Kts:=Enterprice-10; else if Enterprice-l>20 then Kts:=Enterprice-15; else if Enterprice-l>25 then Kts:=Enterprice-20; 空停损:sellshort(1,0,stopr,Kts);
//空单止盈 //If Enterprice-L>KDZyDs then Begin // {空单止赢}SellShort(Holding<0,Holding,market); //End //空单平仓 ShortY:=C>D1 And A2=-1 AND A1=4; {价格高于前一个低点,空单止赢} If ShortY then begin {空单平仓}SellShort(1,0,market); end End
可用现金:CASH(0),LINETHICK0; 持仓:HOLDING,LINETHICK0; 资产:ASSET,LINETHICK0;
[此贴子已经被作者于2011-1-7 11:09:32编辑过]
|