欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → [分享]多空版本的海龟交易法则

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有23243人关注过本帖树形打印复制链接

主题:[分享]多空版本的海龟交易法则

帅哥哟,离线,有人找我吗?
bhwhui
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
[分享]多空版本的海龟交易法则  发帖心情 Post By:2009/11/23 21:42:42    Post IP:221.7.173.165[只看该作者]

简介:

 

      著名的商品投机家理查德·丹尼斯想弄清楚伟大的交易员是天生造就的还是后天培养的。为此,在1983年他招募了13个人,教授给他们期货交易的基本概念,以及他自己的交易方法和原则。

  “学员们被称为‘海龟’(丹尼斯先生说这项计划开始时他刚刚从亚洲回来,他解释了自己向别人说过的话,‘我们正在成长为交易员,就象在新加坡他们正在成长为海龟一样’)。”----斯坦利.W.安格瑞斯特,《华尔街期刊》,1989年9月5日。

  海龟成为交易史上最著名的实验,因为在随后的四年中海龟们取得了年均复利80%的收益。

  丹尼斯证明用一套简单的系统和法则,可以使仅有很少或根本没有交易经验的人成为优秀的交易员。

  当时,海龟们认为应对理查德·丹尼斯负责,商定甚至在他们议定的10年保密协定于1993年终止后也不泄露这些法则。但是,有个别海龟在网站上出售海龟交易法则而谋取钱财。两个原版海龟科蒂斯·费思和阿瑟·马多克,为了阻止个别海龟对知识产权的偷窃和出售海龟交易法则而赚钱的行为,决定在网站上将海龟交易法则免费公之于众。【交易之路www.irich.info§ www.irich.com.cn 收集整理】

  我们现在能看到的海龟交易法则,既是由此所得。

  这就是海龟交易法则的由来——稍微有点曲折。

  海龟交易系统是一个完整的交易系统,它包括市场----买卖什么,头寸规模----买卖多少,市----何时买卖止损----何时退出亏损的头寸,离市----何时退出赢利的头寸,策略----如何买卖等。

  海龟交易系统有三个特点:其一,是一个完整的交易系统,其法则覆盖了交易的各个方面。对于交易中所涉及到的每项决策,系统都会给出答案。其二,是一个机械化的交易系统。正是由于其交易系统的完整性,所以,系统不给交易员留下一点主观想象决策的余地。其三,是一个被检测可以赚钱的交易系统。正是由于此,不管交易员在赚钱还是亏钱时都容易接受信号。

  以下,对海龟交易系统作一简要的阐述:

  对于市场,海龟们交易的是美国芝加哥和纽约交易所具有流动性的期货品种。

  海龟交易认为头寸规模是所有交易系统最重要的部分之一。丹尼斯引入一个N的概念来表示某个特定市场根本的波动性,并用一个基于波动性的常数百分比用作头寸规模风险的测算标准。这样提高了多样化的收益,并且增加了赢利交易弥补亏损交易的可能性。

  海龟用两个相关的系统入市,这两个系统都以唐奇安的通道突破系统(Donchian’schannelbreakoutsystem)为基础,比如:系统一----以20日突破为基础的偏短线系统和系统二----以50日突破为基础的较简单的长线系统。20日突破可定义为超过前20天的最高价或最低价。另外,在入市系统上,海龟引入了增加单位和连续性的定义。它认为,一年中大部分利润可能仅仅来自于两三次大的赢利交易,因此增加单位和连续性显得尤为重要。

  海龟认为退出亏损头寸绝对是至关重要的。有两点说明:第一,在你建立头寸之前,你应该预先确定退出的点位;其二,如果市场的波动触及你的价位,你就必须每一次都毫无例外地退出。另外,海龟使用以N为基础的止损以避免净值的大幅损失,它能够适应市场的波动性,并使更不稳定的市场有更宽的止损。

  海龟对于赢利头寸使用以突破为基础的离市策略。赢利头寸的正确退出是交易最重要的方面之一,也是海龟系统中唯一最难的部分。人具有一种想要早点离市的强烈倾向,但这恰恰使大幅赢利变成微弱赢利的交易。在大幅赢利的交易中,遵守纪律和坚持原则的能力是成功老道的交易员的特征。【交易之路www.irich.info§ www.irich.com.cn 收集整理】

  海龟交易策略包括入市指令、快速波动的市场、同步入市信号、买强卖弱和更换期满合约等。

  最后,海龟法则建议进一步学习的范围,包括交易心理学、资金管理和交易研究等。

  关于海龟交易法则所得出的结论,我们引用理查德·丹尼斯说过的话:“我总是说你们可以在报纸上发表我的交易法则,没有人会遵循它们。关键在于连续性和纪律。几乎任何人都能够罗列一张交易法则的清单,其中的80%与我们教授给我们的学员的一样。他们所不能做的是带给他们自信,甚至在情况恶化时仍坚持那些法则。”

  总之,海龟交易法则在于有信心有纪律连续地应用所学到的法则,这就是海龟们作为交易员成功的秘诀。

 

[此贴子已经被作者于2009-11-23 21:45:21编辑过]

[本帖被加为精华]
 回到顶部
帅哥哟,离线,有人找我吗?
bhwhui
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
  发帖心情 Post By:2009/11/23 21:44:16    Post IP:221.7.173.165[只看该作者]

作为著名的系统交易规则,海龟法则一直是程序化爱好者的必修课,

以上是简介,读者感兴趣可以自己下载电子版阅读。

金字塔系统所带的法则仅是多头版本,试着改写了一下多空版本,不对之处请指教。

 

input:trn(20,5,30),hn(20,5,30),ln(10,5,20);

VARIABLE:dayCount=1,PositionCount=1,SellSign=0,dK=0;//加多空标志,1:多,-1:空 0:空仓
VARIABLE:EntAndExitSign=1,EntPoint=0,ExitPoint=0;
VARIABLE:N=0;

N:=MA(TR,trn);
BUYHHV:=HHV(H,hn);
SELLLLV:=LLV(L,ln);

sellshortllv:=llv(l,hn);
buyshorthhv:=hhv(h,ln);

IF BARPOS>=hn THEN
BEGIN
 IF BARPOS=hn THEN
 IF DayCount=hn/2 OR BARPOS=hn  THEN
  BEGIN{hn/2天调整N值}
      N:=((hn-1)*N+TR)/hn;{计算N值}
      DayCount:=2;
  END
 
 DayCount:=DayCount+1;
 EntPoint:=ENTERBARS+1;
 
 IF EntPoint=EntAndExitSign THEN
     BEGIN{说明STOP指令买进头寸成功}
  PositionCount:=PositionCount+1;{头寸计数}
  SellSign:=True;{可以平仓信号,如果达到指定的价格}
   END
  
 IF PositionCount=1 THEN BEGIN{第一头寸}
  HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
  if high=buyhhv then
   BEGIN
   dk:=1;
   多开1:BUY(1,HOW,STOP,BUYHHV);{在20日新高STOP指令买进}
   END;
  
  if low=sellshortllv then
   begin
   dk:=-1;
   空开1:buyshort(1,HOW,STOP,sellshortllv);{在20日新低STOP指令空开}
   end;
 END

 IF PositionCount=2 THEN BEGIN{如到第二头寸}
  HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
  if dk=1 then 多开2:BUY(1,HOW,STOP,ENTERPRICE+0.5*N);{在上头寸(即第一头寸)+0.5个N以STOP指令买进}
  if dk=-1 then 空开2:buyshort(1,HOW,STOP,ENTERPRICE-0.5*N);
 END

 IF PositionCount=3 THEN BEGIN{如到第三头寸}
  HOW:=CASH(0)*0.01/N;
  if dk=1 then 多开3:BUY(1,HOW,STOP,ENTERPRICE+0.5*N);{在上头寸(即第二头寸)+0.5个N以STOP指令买进}
  if dk=-1 then 空开3:buyshort(1,HOW,STOP,ENTERPRICE-0.5*N);
 END

 IF PositionCount=4 THEN BEGIN
  HOW:=CASH(0)*0.01/N;
  if dk=1 then 多开4:BUY(1,HOW,STOP,ENTERPRICE+0.5*N);
  if dk=-1 then 空开4:buyshort(1,HOW,STOP,ENTERPRICE-0.5*N); 
 END

 IF SellSign=True THEN
  BEGIN
      ExitPoint:=EXITBARS+1;
      if dk=1 then
       begin
        IF ExitPoint=EntAndExitSign THEN
        BEGIN {说明卖出成功}
           PositionCount:=1;{头寸计算复原}
           SellSign:=False;
           dk:=0;
        END
    
        IF ENTERPRICE-2*N then
         SELL(1,100%,STOP,SELLLLV);{退出离盈利头寸}
        ELSE
         SELL(1,100%,STOP,ENTERPRICE-2*N);{退出亏损头寸}
       end;
      
      if dk=-1 then
        begin
       IF ExitPoint=EntAndExitSign THEN
        BEGIN
           PositionCount:=1;
           SellSign:=False;
           dk:=0;
        END
    
       IF ENTERPRICE+2*N then
        sellSHORT(1,100%,STOP,BUYSHORTHHV);
       ELSE
        sellSHORT(1,100%,STOP,ENTERPRICE+2*N);
      
       END;
     END
    
END;

 

 


 回到顶部
帅哥哟,离线,有人找我吗?
tzttyxy
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:76 积分:681 威望:0 精华:0 注册:2009/8/17 21:46:07
  发帖心情 Post By:2009/11/23 22:24:25    Post IP:220.189.149.29[只看该作者]

编译错误:参数名LN不能与函数名重复

 回到顶部
帅哥哟,离线,有人找我吗?
bhwhui
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
  发帖心情 Post By:2009/11/23 23:18:56    Post IP:221.7.173.165[只看该作者]

奇怪,我的编译器能通过。。。。

 

那就替换一下ln吧:

 

input:trn(20,5,30),hn(20,5,30),lown(10,5,20);

VARIABLE:dayCount=1,PositionCount=1,SellSign=0,dK=0;//加多空标志,1:多,-1:空 0:空仓
VARIABLE:EntAndExitSign=1,EntPoint=0,ExitPoint=0;
VARIABLE:N=0;

N:=MA(TR,trn);
BUYHHV:=HHV(H,hn);
SELLLLV:=LLV(L,lown);

sellshortllv:=llv(l,hn);
buyshorthhv:=hhv(h,lown);

IF BARPOS>=hn THEN
BEGIN
 IF BARPOS=hn THEN
 IF DayCount=hn/2 OR BARPOS=hn  THEN
  BEGIN{hn/2天调整N值}
      N:=((hn-1)*N+TR)/hn;{计算N值}
      DayCount:=2;
  END
 
 DayCount:=DayCount+1;
 EntPoint:=ENTERBARS+1;
 
 IF EntPoint=EntAndExitSign THEN
     BEGIN{说明STOP指令买进头寸成功}
  PositionCount:=PositionCount+1;{头寸计数}
  SellSign:=True;{可以平仓信号,如果达到指定的价格}
   END
  
 IF PositionCount=1 THEN BEGIN{第一头寸}
  HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
  if high=buyhhv then
   BEGIN
   dk:=1;
   多开1:BUY(1,HOW,STOP,BUYHHV);{在20日新高STOP指令买进}
   END;
   
  if low=sellshortllv then
   begin
   dk:=-1;
   空开1:buyshort(1,HOW,STOP,sellshortllv);{在20日新低STOP指令空开}
   end;
 END

 IF PositionCount=2 THEN BEGIN{如到第二头寸}
  HOW:=CASH(0)*0.01/N;{波动性百分比决定头寸规模}
  if dk=1 then 多开2:BUY(1,HOW,STOP,ENTERPRICE+0.5*N);{在上头寸(即第一头寸)+0.5个N以STOP指令买进}
  if dk=-1 then 空开2:buyshort(1,HOW,STOP,ENTERPRICE-0.5*N);
 END

 IF PositionCount=3 THEN BEGIN{如到第三头寸}
  HOW:=CASH(0)*0.01/N;
  if dk=1 then 多开3:BUY(1,HOW,STOP,ENTERPRICE+0.5*N);{在上头寸(即第二头寸)+0.5个N以STOP指令买进}
  if dk=-1 then 空开3:buyshort(1,HOW,STOP,ENTERPRICE-0.5*N);
 END

 IF PositionCount=4 THEN BEGIN
  HOW:=CASH(0)*0.01/N;
  if dk=1 then 多开4:BUY(1,HOW,STOP,ENTERPRICE+0.5*N);
  if dk=-1 then 空开4:buyshort(1,HOW,STOP,ENTERPRICE-0.5*N); 
 END

 IF SellSign=True THEN
  BEGIN
      ExitPoint:=EXITBARS+1;
      if dk=1 then
       begin
        IF ExitPoint=EntAndExitSign THEN
        BEGIN {说明卖出成功}
           PositionCount:=1;{头寸计算复原}
           SellSign:=False;
           dk:=0;
        END
     
        IF ENTERPRICE-2*N then
         SELL(1,100%,STOP,SELLLLV);{退出离盈利头寸}
        ELSE
         SELL(1,100%,STOP,ENTERPRICE-2*N);{退出亏损头寸}
       end;
       
      if dk=-1 then
        begin 
       IF ExitPoint=EntAndExitSign THEN
        BEGIN
           PositionCount:=1;
           SellSign:=False;
           dk:=0;
        END
     
       IF ENTERPRICE+2*N then
        sellSHORT(1,100%,STOP,BUYSHORTHHV);
       ELSE
        sellSHORT(1,100%,STOP,ENTERPRICE+2*N);
       
       END;
     END
     
END;


 回到顶部
帅哥哟,离线,有人找我吗?
bhwhui
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
  发帖心情 Post By:2009/11/23 23:21:55    Post IP:221.7.173.165[只看该作者]

大家有空可以研究一下第一代的Turtle和现在的不同:

 

作者的说明:

This is the original Turtle Trader System as described on the German website

http://keplerweb.oeh.uni-linz.ac.at/trading/turtletradingrules.htm

The only difference is: The position is not calculated with N.

Best regards
Odelys

哦,不是用金字塔写的,语法类似。

 

var N, L1, S1, L2, S2, L3, S3, L4, S4, SE, LE, SL: float;
var BAR, P : integer;

for Bar := 20 to BarCount - 1 do
begin
  //ApplyAutoStops(bar);
  if PriceClose(bar) > 5000 then
  setpositionsize(priceclose(bar)*1.1);
  N := ATR( Bar, 20 );
  L1 := Highest( Bar, #High, 20);
  S1 := Lowest( Bar, #Low, 20);
  L2 := L1 +0.5*N;
  S2 := S1 -0.5*N;
  L3 := L2 +0.5*N;
  S3 := S2 -0.5*N;
  L4 := L3 +0.5*N;
  S4 := S3 -0.5*N;
  SE := Highest( Bar, #High, 10);
  LE := Lowest( Bar, #Low, 10);

  if ActivePositionCount=3 then begin
    BuyAtStop( Bar + 1, L4, 'L4');
    ShortAtStop (Bar + 1, S4, 'S4');
  end;
  if ActivePositionCount=2 then begin
    BuyAtStop( Bar + 1, L3, 'L3');
    ShortAtStop (Bar + 1, S3, 'S3');
  end;
  if ActivePositionCount=1 then begin
    BuyAtStop( Bar + 1, L2, 'L2');
    ShortAtStop (Bar + 1, S2, 'S2');
  end;
  if ActivePositionCount = 0 then begin
    BuyAtStop( Bar + 1, L1, 'L1');
    ShortAtStop (Bar + 1, S1, 'S1');
  end;
  for p := 0 to PositionCount -1 do begin
    if PositionActive(p) then
    if Positionlong(p) then SL := PositionEntryPrice(p)-2*N
    else SL := PositionEntryPrice(p)+2*N;
  end;
  for p := 0 to PositionCount -1 do begin
    if PositionActive(p) then
    if Positionlong(p) then SellAtStop( Bar + 1, SL, p, 'LongStop')
    else CoverAtStop( Bar + 1, SL, p, 'ShortStop');
    if PositionActive(p) then
    if Positionlong(p) then SellAtStop( Bar + 1, LE, p, 'LongExit')
    else CoverAtStop( Bar + 1, SE, p, 'ShortExit');
  end;
end;


 回到顶部
帅哥哟,离线,有人找我吗?
bhwhui
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
  发帖心情 Post By:2009/11/23 23:24:15    Post IP:221.7.173.165[只看该作者]

Ver2.0

 

Same as V1, but N is kept constant after a position has been opened.

 

var N, L1, S1, L2, S2, L3, S3, L4, S4, SE, LE, SL: float;
var BAR, P : integer;

for Bar := 20 to BarCount - 1 do
begin
  //ApplyAutoStops(bar);
  if PriceClose(bar) > 5000 then
  setpositionsize(priceclose(bar)*1.1);
  SE := Highest( Bar, #High, 10);
  LE := Lowest( Bar, #Low, 10);

  if ActivePositionCount=3 then begin
    BuyAtStop( Bar + 1, L4, 'L4');
    ShortAtStop (Bar + 1, S4, 'S4');
  end;
  if ActivePositionCount=2 then begin
    BuyAtStop( Bar + 1, L3, 'L3');
    ShortAtStop (Bar + 1, S3, 'S3');
  end;
  if ActivePositionCount=1 then begin
    BuyAtStop( Bar + 1, L2, 'L2');
    ShortAtStop (Bar + 1, S2, 'S2');
  end;
  if ActivePositionCount = 0 then begin
    N := ATR( Bar, 20 );
    L1 := Highest( Bar, #High, 20);
    S1 := Lowest( Bar, #Low, 20);
    L2 := L1 +0.5*N;
    S2 := S1 -0.5*N;
    L3 := L2 +0.5*N;
    S3 := S2 -0.5*N;
    L4 := L3 +0.5*N;
    S4 := S3 -0.5*N;
    BuyAtStop( Bar + 1, L1, 'L1');
    ShortAtStop (Bar + 1, S1, 'S1');
  end;
  for p := 0 to PositionCount -1 do begin
    if PositionActive(p) then
    if Positionlong(p) then SL := PositionEntryPrice(p)-2*N
    else SL := PositionEntryPrice(p)+2*N;
  end;
  for p := 0 to PositionCount -1 do begin
    if PositionActive(p) then
    if Positionlong(p) then SellAtStop( Bar + 1, SL, p, 'LongStop')
    else CoverAtStop( Bar + 1, SL, p, 'ShortStop');
    if PositionActive(p) then
    if Positionlong(p) then SellAtStop( Bar + 1, LE, p, 'LongExit')
    else CoverAtStop( Bar + 1, SE, p, 'ShortExit');
  end;
end;


 回到顶部
帅哥哟,离线,有人找我吗?
bhwhui
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
  发帖心情 Post By:2009/11/23 23:27:06    Post IP:221.7.173.165[只看该作者]

Ver3.0

 

说明:

 

This Script follows the rules indicated by Curtis Faith in the booklet "Original Turtles ?Fighting the Scams, Frauds and Charlatans", downloadable from www.OriginalTurtles.org

I used odelys?Turtle_Original_V2 as the frame for my coding. Therefore I am considering this a third version of his work. Thank you odelys!

However, as I am considering this Script just an 揳cademic?tool, I have indulged in only a few shortcuts to Faith抯 rules:
1. Faith, page 19: 揘OTE: For the purposes of this test, the last breakout was considered the last breakout in the particular commodity irrespective of whether or not that particular breakout was actually take, or was skipped because of this rule.?In the ChartScript, only the taken breakouts (WL: LastPosition) are considered as the last breakout, not the skipped ones.
2. There is no automatic decreasing of the Account in the case of a string of losses nor yearly upward adjustments (Faith, page 17)
3. Stop loss positioning follows always the same rule in the ChartScript, and does not adjust for gaps (Faith example on top of page 23)
4. No coding for the Alternate Stop Strategy ?The Whipsaw (Faith page 23) was done
5. There is no position sizing limitations in coincidence with markets?correlation (Faith, page 16). A decent compromise could be to set the $imulator抯 Max Open Positions to 24, i.e. the maximum12 open positions in each direction, although we could have no guarantee that in such a way open positions would be effectively split 50% between long and short as rules would require.

NOTE:
As Turtles?stop loss is generally placed fairly tight, sometimes the entry bar is long enough to encompass both: the entry and the stop loss price. In such case, the Script will enter the position at Entry price, and exit THE SAME DAY at the stop loss price, with a loss. Although in several cases this would be incorrect.


 回到顶部
帅哥哟,离线,有人找我吗?
bhwhui
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
  发帖心情 Post By:2009/11/23 23:27:37    Post IP:221.7.173.165[只看该作者]

var ChannelUp, ChannelDn, LongExit, ShrtExit, FailsafeUp, FailsafeDn : integer;
var N, L1, S1, L2, S2, L3, S3, L4, S4, SE, LE, SL, FU, FD, Account, Tick: float;
var topSL, lowSL : float;
var Bar, p, SinceLast : integer;
var LeadBars : integer;
var cond20 : boolean;

{ Parameters input }
ChannelUp := 20 ;
ChannelDn := 20 ;
LongExit := 10 ;
ShrtExit := 10 ;
FailsafeUp := 55 ;
FailsafeDn := 55 ;
Account := 1000000 ; //This is the notional account

{ Cosmetics and general info }
HideVolume ;
EnableNotes(false);
tick := GetTick ;

{ Indicators plotting }
PlotSeries( HighestSeries( #High, ChannelUp ), 0, #blue, #Thin );
PlotSeries( LowestSeries( #Low, ChannelDn ), 0, #fuchsia, #Thin );
PlotSeries( HighestSeries( #High, ShrtExit ), 0, #green, #Dotted );
PlotSeries( LowestSeries( #Low, LongExit ), 0, #red, #Dotted );
PlotSeries( HighestSeries( #High, FailsafeUp ), 0, #purple, #Dotted );
PlotSeries( LowestSeries( #Low, FailsafeDn ), 0, #purple, #Dotted );

{ MAIN CYCLE }
LeadBars := Trunc(max(FailsafeUp, FailsafeDn)); // Failsafe > Channel and Failsafe > Exit
for Bar := LeadBars to BarCount - 1 do
begin
  SE := Highest( Bar, #High, ShrtExit) + tick ;
  LE := Lowest( Bar, #Low, LongExit) - tick ;

  { Entering the first position }
  if PositionCount = 0 then begin
    N := ATR( Bar, 20 ); // N calculation
    SetShareSize(Int( (Account * 0.01) / (N * GetPointValue))); // Unit
    L1 := Highest( Bar, #High, ChannelUp);
    S1 := Lowest( Bar, #Low, ChannelDn);
    L2 := L1 + 0.5 * N ;
    S2 := S1 - 0.5 * N ;
    L3 := L2 + 0.5 * N ;
    S3 := S2 - 0.5 * N ;
    L4 := L3 + 0.5 * N ;
    S4 := S3 - 0.5 * N ;
    BuyAtStop( Bar + 1, L1, 'L1 ' + FormatFloat( '#0.00', L1));
    ShortAtStop (Bar + 1, S1, 'S1 ' + FormatFloat( '#0.00', S1));
  end; // of 'if PositionCount = 0 then'
     
  { Entering next positions }
  if PositionCount > 0 then begin
    if ActivePositionCount=3 then begin
      BuyAtStop( Bar + 1, L4, 'L4 '+ FormatFloat( '#0.00', L4));
      ShortAtStop (Bar + 1, S4, 'S4 '+ FormatFloat( '#0.00', S4));
    end;
    if ActivePositionCount=2 then begin
      BuyAtStop( Bar + 1, L3, 'L3 '+ FormatFloat( '#0.00', L3));
      ShortAtStop (Bar + 1, S3, 'S3 '+ FormatFloat( '#0.00', S3));
    end;
    if ActivePositionCount=1 then begin
      BuyAtStop( Bar + 1, L2, 'L2 '+ FormatFloat( '#0.00', L2));
      ShortAtStop (Bar + 1, S2, 'S2 '+ FormatFloat( '#0.00', S2));
    end;
    if ActivePositionCount = 0 then begin
    { cond20 will be set true if any of the conditions listed on page 19
      has been met }
      cond20 := false ;
      N := ATR( Bar, 20 );  // N calculation

      { Condition 1: last position was unprofitable }
      if PositionProfit( LastPosition ) < 0 then cond20 := true;

      { Condition 2 and 3: last position = long and price has moved against it > 2N
        or last position = short and price has moved against it > 2N}
      SinceLast := (Bar - PositionExitBar(LastPosition) + 1) ;
      topSL := Highest( Bar, #High, SinceLast) ;
      lowSL := Lowest( Bar, #Low, SinceLast) ;
      if ( PositionLong(LastPosition) and
      lowSL < PositionExitPrice(LastPosition) + 2*N ) then cond20 := true;
      if ( PositionShort(LastPosition) and
      topSL > PositionExitPrice(LastPosition) + 2*N ) then cond20 := true;
    end; // of cond20 setting

    if ActivePositionCount = 0 then begin
      if cond20 = true then begin
        SetShareSize(Int( (Account * 0.01) / (N * GetPointValue)));  // Unit
        L1 := Highest( Bar, #High, ChannelUp);
        S1 := Lowest( Bar, #Low, ChannelDn);
        L2 := L1 + 0.5 * N ;
        S2 := S1 - 0.5 * N ;
        L3 := L2 + 0.5 * N ;
        S3 := S2 - 0.5 * N ;
        L4 := L3 + 0.5 * N ;
        S4 := S3 - 0.5 * N ;
        BuyAtStop( Bar + 1, L1, 'L1 '+ FormatFloat( '#0.00', L1));
        ShortAtStop (Bar + 1, S1, 'S1 '+ FormatFloat( '#0.00', S1));
        end // of cases where cond20 = true
      else
        begin
        SetShareSize(Int( (Account * 0.01) / (N * GetPointValue)));  // Unit
        FU := Highest( Bar, #High, FailsafeUp);
        FD := Lowest( Bar, #Low, FailsafeDn);
        L2 := FU + 0.5 * N ;
        S2 := FD - 0.5 * N ;
        L3 := L2 + 0.5 * N ;
        S3 := S2 - 0.5 * N ;
        L4 := L3 + 0.5 * N ;
        S4 := L3 - 0.5 * N ;
        BuyAtStop( Bar + 1, FU, 'FU');
        ShortAtStop (Bar + 1, FD, 'FD');
      end; // of cases where cond20 = false
    end; // of entering positions ActivePositionCount = 0
  end; // of buying rules when PositionCount > 0 and ActivePositions = 0

  { Define the stop loss level }
  if PositionCount > 0 then
    if PositionActive(LastPosition) then
      if PositionLong(LastPosition) then SL := PositionEntryPrice(LastPosition) - 2 * N
      else SL := PositionEntryPrice(LastPosition) + 2 * N ;

  { Check for position exit conditions }
  for p := 0 to PositionCount -1 do begin
    if PositionActive(p) then
      if Positionlong(p) then SellAtStop( Bar + 1, SL, p, 'LongStop')
      else CoverAtStop( Bar + 1, SL, p, 'ShortStop');
    if PositionActive(p) then
      if Positionlong(p) then SellAtStop( Bar + 1, LE, p, 'LongExit')
      else CoverAtStop( Bar + 1, SE, p, 'ShortExit');
  end; // of position exits
end; // OF THE MAIN CYCLE


 回到顶部
帅哥哟,离线,有人找我吗?
bhwhui
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:208 积分:1565 威望:0 精华:2 注册:2009/8/23 19:18:53
  发帖心情 Post By:2009/11/23 23:33:16    Post IP:221.7.173.165[只看该作者]

估计这个帖子不会很多人看的,呵呵呵,答应过管理员将一些国外优秀的交易系统改写成金字塔语法。

 

Dynamic Breakout II from "Building Winning Trading Systems That Work with Tradestation"


Any one like this ? Much nonsense that those who understand the natural love.

[此贴子已经被作者于2009-11-23 23:38:58编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
wtx128153
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:38 积分:351 威望:0 精华:1 注册:2009/11/21 7:52:15
  发帖心情 Post By:2009/11/23 23:38:44    Post IP:60.222.50.58[只看该作者]

为什么只能显示3年前的信号,而不能显示现在的信号,比如豆粕日线 15分 3分等?

 回到顶部
总数 25 1 2 3 下一页