TB改金字塔
////////
我们使用三种类型的止损设置:
进场后设置初始止损;
有一定盈利后设置保本止损;
盈利增大后使用追踪止盈;
为此,设置三个止损参数:
Numeric InitialStop(20); // 初始止损(千分之N)
Numeric BreakEvenStop(30); // 保本止损(千分之N)
Numeric TrailingStop(50); // 追踪止损(千分之N)
三种止损的代码可以放在一起处理,取最有利的价格作为止损(赢)价。
////////
多头止损部分的代码
// 初始止损
StopLine = EntryPrice * (1-InitialStop/1000);
// 达到保本止损条件,将止损位上移到保本的价位
If (HigherAfterEntry >= EntryPrice * (1+BreakEvenStop/1000))
StopLine = EntryPrice;
// 追踪止损的价位超过保本止损价,止损价随盈利峰值价的上升同步提高
If (StopLine < HigherAfterEntry*(1-TrailingStop/1000))
StopLine = HigherAfterEntry*(1-TrailingStop/1000);
Commentary("止损价:"+Text(StopLine));
// 止损触发
If(Low <= StopLine)
{
MyPrice = StopLine;
If(Open < MyPrice) MyPrice = Open;
Sell(Lots,MyPrice);
bLongStoped = True; // 止损后设置标志
Commentary("Long Position Stoped at "+text(MyPrice));
}
//EntryPrice为开仓价
//Commentary为注释
开多后首先设置初始止损:
// 初始止损
StopLine = EnterPrice * (1-20/1000);
然后有一定盈利后设置保本止损:
// 达到保本止损条件,将止损位上移到保本的价位
If (开仓后最高价>= EnterPrice * (1+30/1000))
StopLine = EnterPrice;
最后,盈利增大后使用追踪止盈:
// 追踪止损的价位超过保本止损价,止损价随盈利峰值价的上升同步提高
If (StopLine < 开仓后最高价*(1-50/1000))
StopLine = 开仓后最高价*(1-50/1000);
// 止损触发
If(Low <= StopLine)
///////////
思路就是
开多后首先设置初始止损,如果价格上涨,则将止损线上移至开仓价,如果价格继续上涨,则设置移动止损
[此贴子已经被作者于2012-4-11 17:10:39编辑过]
variable:zs=c,hl=c;
hi20:=ref(hhv(h,20),1);
lo20:=ref(llv(l,20),1);
if holding>0 and l<zs then sell(1,1,limitr,min(o,zs)-mindiff);//止损
if holding<0 and h>zs then sellshort(1,1,limitr,max(o,zs)+mindiff);//止损
if holding>0 and l<lo20 then sell(1,1,limitr,min(o,lo20)-mindiff);//离场
if holding<0 and h>hi20 then sellshort(1,1,limitr,max(o,hi20)+mindiff);//离场
if holding=0 and h>hi20 then begin//开多
buy(1,1,limitr,max(o,hi20)+mindiff);
hl:=h;//记录开仓后的最高点
zs:=enterprice*(1-20/1000);//多头初始止损
end
if holding=0 and l<lo20 then begin//开空
buyshort(1,1,limitr,min(o,lo20)-mindiff);
hl:=l;//记录开仓后的最低点
zs:=enterprice*(1+20/1000);//空头初始止损
end
if holding>0 and h>hl then begin//上移最高点
hl:=h;
if hl>enterprice*(1+30/1000) then zs:=enterprice;//保本止损位
else if hl>enterprice*(1+50/1000)then zs:=enterprice*(1+50/1000);//移动止损
end
if holding<0 and l<hl then begin
hl:=l;
if hl<enterprice*(1-30/1000) then zs:=enterprice;//保本止损位
else if hl<enterprice*(1-50/1000) then zs:=enterprice*(1-50/1000);//移动止损
end
[此贴子已经被作者于2012-4-12 10:07:42编辑过]