- 精华
- 0
- 在线时间
- 138 小时
- UID
- 348
- 积分
- 347
- 帖子
- 83
- 阅读权限
- 50
- 注册时间
- 2007-9-13
- 最后登录
- 2021-9-14
- 精华
- 0
- UID
- 348
- 积分
- 347
- 帖子
- 83
- 主题
- 31
- 阅读权限
- 50
- 注册时间
- 2007-9-13
- 最后登录
- 2021-9-14
|
最近在通过看用户函数学习TB,pivot函数的代码感觉很绕,看不明白是怎么算出来的。麻烦给加点注释好吗?完全没注释看得很晕啊。谢谢谢谢!!!- Params
- NumericSeries Price(1);
- Numeric Length(10);
- Numeric LeftStrength(1);
- Numeric RightStrength(1);
- Numeric Instance(1);
- Numeric HiLo(1);
- NumericRef PivotPrice;
- NumericRef PivotBar;
- Vars
- Numeric CandidatePrice( 0 );
- Numeric LengthCntr( 0 );
- Numeric StrengthCntr( 0 );
- Numeric InstanceCntr( 0 );
- Bool PivotTest( False);
- Bool InstanceTest( False ) ;
- Begin
- InstanceCntr = 0 ;
- InstanceTest = False ;
- LengthCntr = RightStrength ;
- While (LengthCntr < Length && (!InstanceTest ))
- {
- CandidatePrice = Price[LengthCntr] ;
- PivotTest = True ;
- StrengthCntr = LengthCntr + 1 ;
-
- While (PivotTest && StrengthCntr - LengthCntr <= LeftStrength )
- {
- If (( HiLo == 1 And CandidatePrice < Price[StrengthCntr] ) or ( HiLo == -1 And CandidatePrice > Price[StrengthCntr] ))
- PivotTest = False;
- Else
- StrengthCntr = StrengthCntr + 1 ;
- }
-
- StrengthCntr = LengthCntr - 1 ;
- While (PivotTest && (LengthCntr - StrengthCntr) <= RightStrength )
- {
- If (( HiLo == 1 And CandidatePrice <= Price[StrengthCntr] ) or ( HiLo == -1 And CandidatePrice >= Price[StrengthCntr] ))
- PivotTest = False;
- Else
- StrengthCntr = StrengthCntr - 1 ;
- }
-
- If (PivotTest)
- InstanceCntr = InstanceCntr + 1 ;
- If (InstanceCntr == Instance)
- InstanceTest = True;
- Else
- LengthCntr = LengthCntr + 1 ;
- }
-
- If (InstanceTest )
- {
- PivotPrice = CandidatePrice ;
- PivotBar = LengthCntr ;
- Return True;
- }Else
- {
- PivotPrice = -1 ;
- PivotBar = -1 ;
- Return False;
- }
- End
复制代码 |
|