以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  公式模型编写问题提交  (http://weistock.com/bbs/list.asp?boardid=4)
----  [求助]  (http://weistock.com/bbs/dispbbs.asp?boardid=4&id=11013)

--  作者:wzywzy292
--  发布时间:2012/4/10 20:20:59
--  [求助]
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为注释

--  作者:just
--  发布时间:2012/4/11 8:59:47
--  
工作人员在处理,稍后回复
--  作者:just
--  发布时间:2012/4/11 10:31:03
--  
http://www.weistock.com/bbs/dispbbs.asp?BoardID=11&ID=7320&skin=0 参考TB改金字塔的三级止损写法。
--  作者:wzywzy292
--  发布时间:2012/4/11 16:26:28
--  
看过了,还是搞不出来,能否帮忙,谢谢!!!

--  作者:just
--  发布时间:2012/4/11 16:32:33
--  
把你的思路写出来看看。
--  作者:wzywzy292
--  发布时间:2012/4/11 17:09:51
--  
 开多后首先设置初始止损:

// 初始止损
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编辑过]

--  作者:wzywzy292
--  发布时间:2012/4/12 9:08:51
--  [求助]1分钟周期模型下:要求5分钟开仓次数不超过三次,怎么表达?
有时间请帮忙,谢谢 !!!

--  作者:just
--  发布时间:2012/4/12 10:06:59
--  

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编辑过]

--  作者:wzywzy292
--  发布时间:2012/4/12 10:54:03
--  
没有达到思路的要求,谢谢!!!
--  作者:wzywzy292
--  发布时间:2012/4/12 16:12:48
--  
 求高手!!!