设为首页收藏本站

 找回密码
 注册
查看: 4037|回复: 1
打印 上一主题 下一主题

请教pivot函数代码 [复制链接]

Rank: 4

精华
0
UID
348
积分
347
帖子
83
主题
31
阅读权限
50
注册时间
2007-9-13
最后登录
2021-9-14
跳转到指定楼层
1#
发表于 2011-3-13 19:22:12 |只看该作者 |倒序浏览
最近在通过看用户函数学习TB,pivot函数的代码感觉很绕,看不明白是怎么算出来的。麻烦给加点注释好吗?完全没注释看得很晕啊。谢谢谢谢!!!
  1. Params
  2. NumericSeries Price(1);
  3. Numeric Length(10);
  4. Numeric LeftStrength(1);
  5. Numeric RightStrength(1);
  6. Numeric Instance(1);
  7. Numeric HiLo(1);
  8. NumericRef PivotPrice;
  9. NumericRef PivotBar;
  10. Vars
  11. Numeric CandidatePrice( 0 );
  12. Numeric LengthCntr( 0 );
  13. Numeric StrengthCntr( 0 );
  14. Numeric InstanceCntr( 0 );
  15. Bool PivotTest( False);
  16. Bool InstanceTest( False ) ;
  17. Begin
  18. InstanceCntr = 0 ;
  19. InstanceTest = False ;
  20. LengthCntr = RightStrength ;
  21. While (LengthCntr < Length && (!InstanceTest ))
  22. {
  23.   CandidatePrice = Price[LengthCntr] ;
  24.   PivotTest = True ;
  25.   StrengthCntr = LengthCntr + 1 ;
  26.   
  27.   While (PivotTest && StrengthCntr - LengthCntr <= LeftStrength )
  28.   {
  29.    If (( HiLo == 1 And CandidatePrice < Price[StrengthCntr] ) or ( HiLo == -1 And CandidatePrice > Price[StrengthCntr] ))
  30.     PivotTest = False;
  31.    Else
  32.     StrengthCntr = StrengthCntr + 1 ;
  33.   }
  34.   
  35.   StrengthCntr = LengthCntr - 1 ;
  36.   While (PivotTest && (LengthCntr - StrengthCntr) <= RightStrength )
  37.   {
  38.    If (( HiLo == 1 And CandidatePrice <= Price[StrengthCntr] ) or ( HiLo == -1 And CandidatePrice >= Price[StrengthCntr] ))
  39.     PivotTest = False;
  40.    Else
  41.     StrengthCntr = StrengthCntr - 1 ;
  42.   }
  43.   
  44.   If (PivotTest)  
  45.    InstanceCntr = InstanceCntr + 1 ;
  46.   If (InstanceCntr == Instance)
  47.    InstanceTest = True;
  48.   Else
  49.    LengthCntr = LengthCntr + 1 ;
  50. }

  51. If (InstanceTest )
  52. {
  53.   PivotPrice = CandidatePrice ;
  54.   PivotBar = LengthCntr ;
  55.   Return True;
  56. }Else
  57. {
  58.   PivotPrice = -1 ;
  59.   PivotBar = -1 ;
  60.   Return False;  
  61. }
  62. End
复制代码

Rank: 3Rank: 3

精华
0
UID
114435
积分
154
帖子
27
主题
2
阅读权限
40
注册时间
2012-12-26
最后登录
2018-4-16
2#
发表于 2013-6-30 16:38:30 |只看该作者
你看明白了吗?我也是刚开始研究,看了好几天也没有看明白怎么回事。继续加油。

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-21 20:11

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部