以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://weistock.com/bbs/index.asp)
--  策略编写求助区  (http://weistock.com/bbs/list.asp?boardid=11)
----  TB二级移动止损策略,能否改成金字塔?  (http://weistock.com/bbs/dispbbs.asp?boardid=11&id=7320)

--  作者:beijib
--  发布时间:2011/7/25 10:05:06
--  两种模式下单如何处理?
 

Numeric MinPoint; // 一个最小变动单位,也就是一跳
Numeric MyEntryPrice; // 开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格
Numeric TrailingStart1(50); // 跟踪止损启动设置1
Numeric TrailingStart2(80); // 跟踪止损启动设置2
Numeric TrailingStop1(30); // 跟踪止损设置1
Numeric TrailingStop2(20); // 跟踪止损设置2
Numeric StopLossSet(50); // 止损设置,默认50
Numeric MyExitPrice; // 平仓价格

NumericSeries HighestAfterEntry; // 开仓后出现的最高价
NumericSeries LowestAfterEntry; // 开仓后出现的最低价

//跟踪止盈止损
If(BarsSinceentry == 0)
{
HighestAfterEntry = Close;
LowestAfterEntry = Close;
If(MarketPosition <> 0)
{
HighestAfterEntry = Max(HighestAfterEntry,AvgEntryPrice); // 开仓的Bar,将开仓价和当时的收盘价的较大值保留到HighestAfterEntry
LowestAfterEntry = Min(LowestAfterEntry,AvgEntryPrice); // 开仓的Bar,将开仓价和当时的收盘价的较小值保留到LowestAfterEntry
}
}else
{
HighestAfterEntry = Max(HighestAfterEntry,High); // 记录下当前Bar的最高点,用于下一个Bar的跟踪止损判断
LowestAfterEntry = Min(LowestAfterEntry,Low); // 记录下当前Bar的最低点,用于下一个Bar的跟踪止损判断
}

Commentary("HighestAfterEntry="+Text(HighestAfterEntry));
Commentary("LowestAfterEntry="+Text(LowestAfterEntry));

MinPoint = MinMove*PriceScale;
MyEntryPrice = AvgEntryPrice;
If(MarketPosition==1) // 有多仓的情况
{
If(HighestAfterEntry[1] >= MyEntryPrice + TrailingStart2*MinPoint) // 第二级跟踪止损的条件表达式
{
If(Low <= HighestAfterEntry[1] - TrailingStop2*MinPoint)
{
MyExitPrice = HighestAfterEntry[1] - TrailingStop2*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
Sell(0,MyExitPrice);
}
}else if(HighestAfterEntry[1] >= MyEntryPrice + TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式
{
If(Low <= HighestAfterEntry[1] - TrailingStop1*MinPoint)
{
MyExitPrice = HighestAfterEntry[1] - TrailingStop1*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
Sell(0,MyExitPrice);
}
}else if(Low <= MyEntryPrice - StopLossSet*MinPoint)//可以在这里写上初始的止损处理
{
MyExitPrice = MyEntryPrice - StopLossSet*MinPoint;
If(Open < MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
Sell(0,MyExitPrice);
}
}else if(MarketPosition==-1) // 有空仓的情况
{
If(LowestAfterEntry[1] <= MyEntryPrice - TrailingStart2*MinPoint) // 第二级跟踪止损的条件表达式
{
If(High >= LowestAfterEntry[1] + TrailingStop2*MinPoint)
{
MyExitPrice = LowestAfterEntry[1] + TrailingStop2*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
BuyToCover(0,MyExitPrice);
}
}else if(LowestAfterEntry[1] <= MyEntryPrice + TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式
{
If(High >= LowestAfterEntry[1] + TrailingStop1*MinPoint)
{
MyExitPrice = LowestAfterEntry[1] - TrailingStop1*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
BuyToCover(0,MyExitPrice);
}
}else If(High >= MyEntryPrice + StopLossSet*MinPoint)//可以在这里写上初始的止损处理
{
MyExitPrice = MyEntryPrice + StopLossSet*MinPoint;
If(Open > MyExitPrice) MyExitPrice = Open; // 如果该Bar开盘价有跳空触发,则用开盘价代替
BuyToCover(0,MyExitPrice);
}
}


--  作者:阿火
--  发布时间:2011/7/25 10:33:25
--  

一大推代码看着真累。

怎么连个开仓条件都没有啊?

还不如直接说出你的思路,我帮你写

看别人的代码比自己写代码难受多了

 

举个例子,突破hi20买入,lo20卖出 止损采用你的设置,代码如下:(30行不到的代码就搞定)

 

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-50*mindiff;//初始止损50个跳动点
end
if holding=0 and l<lo20 then begin//开空
 buyshort(1,1,limitr,min(o,lo20)-mindiff);
 hl:=l;//记录开仓后的最低点
 zs:=enterprice+50*mindiff;//初始止损50个跳动点
end
if holding>0 and h>hl then begin//上移最高点
 hl:=h;
 if hl>enterprice+80*mindiff then zs:=hl-20*mindiff;//满80个点,回落20点为止损位
 else if hl>enterprice+50*mindiff then zs:=hl-30*mindiff;//满50个点,回落30点为止损位
end
if holding<0 and l<hl then begin
 hl:=l;
 if hl<enterprice-80*mindiff then zs:=hl+20*mindiff;//满80个点,反弹20点为止损位
 else if hl<enterprice-50*mindiff then zs:=hl+30*mindiff;//满50个点,反弹30点为止损位
end

[此贴子已经被作者于2011-7-25 10:47:28编辑过]

--  作者:beijib
--  发布时间:2011/7/25 19:25:24
--  
谢谢,已经测试通过
--  作者:zhongjin
--  发布时间:2011/7/29 12:47:25
--  
图片点击可在新窗口打开查看
leevolvo版主请教,如果手动开仓,用你这套做自动止损止盈,再加一组定额百分比的止损止盈,在后台使用,同时请在图表显示

--  作者:zhongjin
--  发布时间:2011/7/29 12:50:26
--  
手动开仓过程有加码,减仓
--  作者:zhongjin
--  发布时间:2011/7/29 15:23:46
--  

leevolvo版主在你原来基础上再加上定额百分比的止损止盈的意思就是点数换算成比率可以适合不同的品种合约

 

按照开仓点亏千分之五止损

 

盈利百分之二减仓1手,盈利百分之2.5再减仓一手


--  作者:阿火
--  发布时间:2011/7/29 16:11:47
--  

那就是要量身定制了?下班有事先回家,改天写

[此贴子已经被作者于2011-7-29 16:12:00编辑过]

--  作者:zhongjin
--  发布时间:2011/8/1 10:27:50
--  

期待中


--  作者:xian_0_9
--  发布时间:2011/8/1 20:35:52
--  

期待中


--  作者:xian_0_9
--  发布时间:2011/8/3 9:41:53
--  
以下是引用zhongjin在2011-7-29 15:23:46的发言:

leevolvo版主在你原来基础上再加上定额百分比的止损止盈的意思就是点数换算成比率可以适合不同的品种合约

 

按照开仓点亏千分之五止损

 

盈利百分之二减仓1手,盈利百分之2.5再减仓一手

一共开仓2手呗。亏千分之5,2手全平?

盈利2%减一手。盈利2.5%全平?