以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (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=4942)

--  作者:大灰狼
--  发布时间:2011/1/22 12:26:08
--  能否帮忙将只能做多的海龟改成可以多空的?

VARIABLE:dayCount=1,PositionCount=1,SellSign=0;
VARIABLE:EntAndExitSign=1,EntPoint=0,ExitPoint=0;
VARIABLE:N=0;

MA1:MA(C,5);
MA3:MA(C,10);

M:=MA(TR,20);
BUYHHV:=HHV(H,20);
SELLLLV:=LLV(L,10);

ss:n,linethick0;

IF BARPOS>=21 THEN BEGIN
IF BARPOS=21 THEN
N:=M;
IF DayCount=6 OR BARPOS=21 THEN BEGIN{5天调整N值}
N:=(19*N+TR)/20;{计算N值}
DayCount:=2;
END
DayCount:=DayCount+1;
EntPoint:=ENTERBARS+1;
IF EntPoint=EntAndExitSign THEN BEGIN{说明STOP指令买进头寸成功}
PositionCount:=PositionCount+1;{头寸计数}
SellSign:=True;{开始以STOP卖出,如果达到指定的价格}
END
IF PositionCount=1 THEN BEGIN{第一头寸}
HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
开1:BUY(H>=BUYHHV,HOW,MARKET);{在20日新高STOP指令买进}
END
IF PositionCount=2 THEN BEGIN{如到第二头寸}
HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
开2:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);{在上头寸(即第一头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=3 THEN BEGIN{如到第三头寸}
HOW:=CASH(0)*0.01/N;
开3:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);{在上头寸(即第二头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=4 THEN BEGIN
HOW:=CASH(0)*0.01/N;
开4:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);
END
IF SellSign=True THEN BEGIN
    ExitPoint:=EXITBARS+1;
    IF ExitPoint=EntAndExitSign THEN BEGIN {说明卖出成功}
       PositionCount:=1;{头寸计算复原}
       SellSign:=False;
    END
    IF ENTERPRICE-2*N then SELL(L<=SELLLLV,100%,MARKET);{退出离盈利头寸}
    ELSE
    SELL(L<=ENTERPRICE-2*N,100%,MARKET);{退出亏损头寸}
    END
END;

 


--  作者:clq1967
--  发布时间:2011/1/22 16:42:11
--  

VARIABLE:dayCount=1,PositionCount=1,SellSign=0;
VARIABLE:EntAndExitSign=1,EntPoint=0,ExitPoint=0;
VARIABLE:N=0;
ss:n,linethick0;

M:=MA(TR,20);
BUYHHV:=HHV(H,20);
SELLLLV:=LLV(L,10);

MA1:MA(C,5);
MA3:MA(C,10);


IF BARPOS>=21 THEN BEGIN
IF BARPOS=21 THEN
N:=M;
IF DayCount=6 OR BARPOS=21 THEN BEGIN{5天调整N值}
N:=(19*N+TR)/20;{计算N值}
DayCount:=2;
END
DayCount:=DayCount+1;
EntPoint:=ENTERBARS+1;
IF EntPoint=EntAndExitSign THEN BEGIN{说明STOP指令买进头寸成功}
PositionCount:=PositionCount+1;{头寸计数}
SellSign:=True;{开始以STOP卖出,如果达到指定的价格}
END
IF PositionCount=1 THEN BEGIN{第一头寸}
HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
开1:BUY(H>=BUYHHV,HOW,MARKET);{在20日新高STOP指令买进}
END
IF PositionCount=2 THEN BEGIN{如到第二头寸}
HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
开2:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);{在上头寸(即第一头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=3 THEN BEGIN{如到第三头寸}
HOW:=CASH(0)*0.01/N;
开3:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);{在上头寸(即第二头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=4 THEN BEGIN
HOW:=CASH(0)*0.01/N;
开4:BUY(H>=ENTERPRICE+0.5*N,HOW,MARKET);
END
IF SellSign=True THEN BEGIN
    ExitPoint:=EXITBARS+1;
    IF ExitPoint=EntAndExitSign THEN BEGIN {说明卖出成功}
       PositionCount:=1;{头寸计算复原}
       SellSign:=False;
    END
    IF ENTERPRICE-2*N then SELL(L<=SELLLLV,100%,MARKET);{退出离盈利头寸}
    ELSE
    SELL(L<=ENTERPRICE-2*N,100%,MARKET);{退出亏损头寸}
    END
END;


VARIABLE:dayCount=1,PositionCount=1,SELLSHORTSign=0;
VARIABLE:EntAndExitSign=1,EntPoint=0,ExitPoint=0;
VARIABLE:N=0;


M:=MA(TR,20);
BUYHHV:=HHV(H,20);
SELLLLV:=LLV(L,10);

 


IF BARPOS>=21 THEN BEGIN
IF BARPOS=21 THEN
N:=M;
IF DayCount=6 OR BARPOS=21 THEN BEGIN
N:=(19*N+TR)/20;
DayCount:=2;
END
DayCount:=DayCount+1;
EntPoint:=ENTERBARS+1;
IF EntPoint=EntAndExitSign THEN BEGINPositionCount:=PositionCount+1;
SELLSHORTSign:=True;

END
IF PositionCount=1 THEN BEGIN

HOW:=CASH(0)*0.01/N;
开空1:BUYSHORT(L<=SELLLLV,HOW,MARKET);
END
IF PositionCount=2 THEN BEGIN

HOW:=CASH(0)*0.01/N;

开空2:BUYSHORT(L<=ENTERPRICE-0.5*N,HOW,MARKET);
END
IF PositionCount=3 THEN BEGIN
HOW:=CASH(0)*0.01/N;
开空3:BUYSHORT(L<=ENTERPRICE-0.5*N,HOW,MARKET);
END
IF PositionCount=4 THEN BEGIN
HOW:=CASH(0)*0.01/N;
开空4:BUYSHORT(L<=ENTERPRICE-0.5*N,HOW,MARKET);
END
IF SELLSHORTSign=True THEN BEGIN
    ExitPoint:=EXITBARS+1;
    IF ExitPoint=EntAndExitSign THEN BEGIN 
       PositionCount:=1;
       SELLSHORTSign:=False;
    END
    IF ENTERPRICE+2*N then SELLSHORT(H>=BUYHHV,100%,MARKET);
    ELSE
    SELLSHORT(H>=ENTERPRICe+2*N,100%,MARKET);
    END
END;