TR:=MAX(HIGH,CLOSE[1])-MIN(LOW,CLOSE[1]);
IF BARPOS>=20 THEN BEGIN
IF BARPOS=20 THEN
N:=MA(TR,20);
IF DayCount=5 OR BARPOS=20 THEN BEGIN {www.qill.cn5天调整N值}
N:=(19*N+TR)/20; {www.qill.cn计算N值}
DayCount:=1;
END
DayCount:=DayCount+1;
EntPoint:=ENTERBARS+1;
IF EntPoint=EntAndExitSign THEN BEGIN {www.qill.cn说明STOP指令买进头寸成功}
PositionCount:=PositionCount+1; {www.qill.cn头寸计数}
SellSign:=True; {www.qill.cn开始以STOP卖出,如果达到指定的价格}
END
IF PositionCount=1 THEN BEGIN {www.qill.cn第一头寸}
HOW:=CASH*0.01/N; {www.qill.cn波动性百分比决定头寸规模}
BUY(HOW,STOP,HHV(H,20)); {www.qill.cn在20日新高STOP指令买进}
END
IF PositionCount=2 THEN BEGIN {www.qill.cn第二头寸}
HOW:=CASH*0.01/N; {www.qill.cn波动性百分比决定头寸规模}
BUY(HOW,STOP,ENTERPRICE+0.5*N); {www.qill.cn在上头寸(即第一头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=3 THEN BEGIN {www.qill.cn第三头寸}
HOW:=CASH*0.01/N;
BUY(HOW,STOP,ENTERPRICE+0.5*N); {www.qill.cn在上头寸(即第二头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=4 THEN BEGIN
HOW:=CASH*0.01/N;
BUY(HOW,STOP,ENTERPRICE+0.5*N);
END
IF SellSign=True THEN BEGIN
ExitPoint:=EXITBARS+1;
IF ExitPoint=EntAndExitSign THEN BEGIN {www.qill.cn说明卖出成功}
PositionCount:=1; {www.qill.cn头寸计算复原}
SellSign:=False;
END
IF ENTERPRICE-2*N<0 THEN BEGIN
SELL(100%,STOP,LLV(L,10)); {www.qill.cn退出离盈利头寸}
END
SELL(100%,STOP,ENTERPRICE-2*N); {www.qill.cn退出亏损头寸}
END
END;
自动交易资金管理范本 海龟头寸 大智慧 分析家通用
{www.qill.cn海龟头寸_大智慧_分析家通用公式}
VARIABLE:dayCount=1, PositionCount=1, SellSign=0;
VARIABLE:EntAndExitSign=1, EntPoint=0, ExitPoint=0;
VARIABLE:True=1, False=0, N=0;
TR:=MAX(HIGH,CLOSE[1])-MIN(LOW,CLOSE[1]);
IF BARPOS>=20 THEN BEGIN
IF BARPOS=20 THEN
N:=MA(TR,20);
IF DayCount=5 OR BARPOS=20 THEN BEGIN {www.qill.cn5天调整N值}
N:=(19*N+TR)/20; {www.qill.cn计算N值}
DayCount:=1;
END
DayCount:=DayCount+1;
EntPoint:=ENTERBARS+1;
IF EntPoint=EntAndExitSign THEN BEGIN {www.qill.cn说明STOP指令买进头寸成功}
PositionCount:=PositionCount+1; {www.qill.cn头寸计数}
SellSign:=True; {www.qill.cn开始以STOP卖出,如果达到指定的价格}
END
IF PositionCount=1 THEN BEGIN {www.qill.cn第一头寸}
HOW:=CASH*0.01/N; {www.qill.cn波动性百分比决定头寸规模}
BUY(HOW,STOP,HHV(H,20)); {www.qill.cn在20日新高STOP指令买进}
END
IF PositionCount=2 THEN BEGIN {www.qill.cn第二头寸}
HOW:=CASH*0.01/N; {www.qill.cn波动性百分比决定头寸规模}
BUY(HOW,STOP,ENTERPRICE+0.5*N); {www.qill.cn在上头寸(即第一头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=3 THEN BEGIN {www.qill.cn第三头寸}
HOW:=CASH*0.01/N;
BUY(HOW,STOP,ENTERPRICE+0.5*N); {www.qill.cn在上头寸(即第二头寸)+0.5个N以STOP指令买进}
END
IF PositionCount=4 THEN BEGIN
HOW:=CASH*0.01/N;
BUY(HOW,STOP,ENTERPRICE+0.5*N);
END
IF SellSign=True THEN BEGIN
ExitPoint:=EXITBARS+1;
IF ExitPoint=EntAndExitSign THEN BEGIN {www.qill.cn说明卖出成功}
PositionCount:=1; {www.qill.cn头寸计算复原}
SellSign:=False;
END
IF ENTERPRICE-2*N<0 THEN BEGIN
SELL(100%,STOP,LLV(L,10)); {www.qill.cn退出离盈利头寸}
END
SELL(100%,STOP,ENTERPRICE-2*N); {www.qill.cn退出亏损头寸}
END
END;