设为首页收藏本站

 找回密码
 注册
楼主: 读书山林
打印 上一主题 下一主题

福利 跨周期的傻瓜式解决方案 [复制链接]

Rank: 5Rank: 5

精华
1
UID
30159
积分
1116
帖子
280
主题
23
阅读权限
60
注册时间
2011-3-23
最后登录
2019-3-21
11#
发表于 2015-5-9 00:18:49 |只看该作者
本帖最后由 读书山林 于 2015-5-9 00:23 编辑

大周期上回溯[N]怎么办 很重要的函数iRef  很多童鞋改写一些算法不正确就是因为忽视了算法内部的回溯值
  1. //------------------------------------------------------------------------
  2. // 简称: iRef
  3. // 名称: 跨周期求回溯值 读书山林
  4. // 类别: 用户函数
  5. // 类型: 用户函数
  6. // 输出: 数值型
  7. //------------------------------------------------------------------------

  8. Params

  9.         NumericSeries mtBarCnt(0);        // MtBar函数返回的mtBarCnt值
  10.         Numeric Length(10);         // 目标周期下的回溯周期
  11. Vars
  12.         Numeric Length0(2);   
  13.         Numeric i;
  14.         Numeric j(0); // 与目标周期下的回溯周期 等值的小周期回溯周期值
  15. Begin
  16.         If(Length==0)
  17.         {
  18.           Return 0;          
  19.         }Else   If(Length==1)
  20.         {
  21.           Return mtBarCnt;       
  22.         }Else
  23.         {
  24.           j=0;
  25.           Length0=Length;

  26.           For i = 1 to Length0
  27.           {
  28.                 If (mtBarCnt[j] <> InvalidNumeric)
  29.                 {
  30.                         j = j + mtBarCnt[j];
  31.                 }
  32.                 else Break;
  33.          }
  34.          Return j;
  35.         }
  36. End
复制代码

使用道具 举报

Rank: 5Rank: 5

精华
1
UID
30159
积分
1116
帖子
280
主题
23
阅读权限
60
注册时间
2011-3-23
最后登录
2019-3-21
12#
发表于 2015-5-9 00:37:55 |只看该作者
本帖最后由 读书山林 于 2015-5-13 09:03 编辑

iEMA
  1. //------------------------------------------------------------------------
  2. // 简称: iEMA
  3. // 名称: 读书山林
  4. // 类别: 用户函数
  5. // 类型: 用户函数
  6. // 输出: 数值型
  7. //------------------------------------------------------------------------
  8. Params
  9.         NumericSeries iPrice;
  10.         NumericSeries mtBarCnt;
  11.         Numeric Length(10);
  12. Vars
  13.         Numeric sFcactor;
  14.         NumericSeries XAvgValue;
  15.         
  16. Begin
  17.                 sFcactor = 2 / ( Length + 1 );
  18.                 if ( XAvgValue[mtBarCnt] == InvalidNumeric)
  19.                 {
  20.                         XAvgValue = iPrice;
  21.                 }else
  22.                 {
  23.                         XAvgValue = XAvgValue[mtBarCnt] + sFcactor * ( iPrice - XAvgValue[mtBarCnt] ) ;
  24.                 }        
  25.                 Return XAvgValue;
  26. End
复制代码

使用道具 举报

Rank: 1

精华
0
UID
131028
积分
25
帖子
12
主题
8
阅读权限
10
注册时间
2012-8-2
最后登录
2016-8-19
13#
发表于 2015-5-10 08:44:16 |只看该作者
好东西,谢谢分享!

使用道具 举报

Rank: 5Rank: 5

精华
1
UID
30159
积分
1116
帖子
280
主题
23
阅读权限
60
注册时间
2011-3-23
最后登录
2019-3-21
14#
发表于 2015-5-10 22:33:13 |只看该作者
iAMA   跨周期求考夫曼
  1. //------------------------------------------------------------------------
  2. // 简称: iAMA
  3. // 名称: 跨周期求考夫曼 读书山林
  4. // 类别: 用户函数
  5. // 类型: 用户函数
  6. // 输出: 数值型
  7. //------------------------------------------------------------------------


  8. Params
  9.         NumericSeries Price(1);
  10.         NumericSeries mtBarCnt(1);       
  11.         Numeric EffRatioLength(10);
  12.         Numeric FastAvgLength(2);
  13.         Numeric SlowAvgLength(30);
  14. Vars
  15.         Numeric oEffRatioLength(10);
  16.         Numeric NetChg(0);
  17.         Numeric TotChg(0);
  18.         Numeric EffRatio(0);
  19.         Numeric ScaledSFSqr(0);
  20.         NumericSeries AMAValue;       
  21.         Numeric SFDiff;
  22.         NumericSeries sumx;       
  23. Begin
  24.               if ( AMAValue[mtBarCnt] == InvalidNumeric)
  25.               {
  26.                   AMAValue = Price;
  27.                   Return AMAValue;
  28.                }
  29.                
  30.                oEffRatioLength=iRef(mtBarCnt,EffRatioLength);
  31.                
  32.                 NetChg = Abs( Price - Price[oEffRatioLength] );
  33.                 sumx = Abs( Price - Price[mtBarCnt] );
  34.                 TotChg = iSum(sumx ,mtBarCnt ,EffRatioLength );               
  35.                 EffRatio = IIF(TotChg > 0, NetChg / TotChg, 0);
  36.                 SFDiff = 2 / ( FastAvgLength + 1 ) - 2 / ( SlowAvgLength + 1 );               
  37.                 ScaledSFSqr = Sqr( 2 / ( SlowAvgLength + 1 ) + EffRatio * SFDiff );               
  38.                 AMAValue = AMAValue[mtBarCnt] + ScaledSFSqr * ( Price - AMAValue[mtBarCnt] );

  39.                Return AMAValue;
  40. End
复制代码

使用道具 举报

Rank: 5Rank: 5

精华
1
UID
30159
积分
1116
帖子
280
主题
23
阅读权限
60
注册时间
2011-3-23
最后登录
2019-3-21
15#
发表于 2015-5-10 22:36:03 |只看该作者
再举个调用实例
  1. //------------------------------------------------------------------------
  2. // 简称: testAMA
  3. // 名称:
  4. // 类别: 公式应用
  5. // 类型: 用户应用
  6. // 输出:
  7. //------------------------------------------------------------------------
  8. Params  
  9.         Numeric TimeFrame(30);        // 目标时间周期参数,参数说明参见iBar
  10.         Numeric BarsBack(1);          // 目标时间周期BAR偏移参数,说明见MtBar函数
  11.         Numeric EffRatioLength(10);
  12.         Numeric FastAvgLength(2);
  13.         Numeric SlowAvgLength(30);
  14. Vars
  15.         Numeric closeX(1);  
  16.         Numeric AMAValue(1);
  17.         NumericSeries mtBarCnt(1);        
  18. Begin
  19.         closeX=iPrice0("Close",TimeFrame,BarsBack);//跨周期的数据源
  20.         mtBarCnt=inBar(TimeFrame,BarsBack);       // 跨周期的inBar
  21.        
  22.         AMAValue=iAMA(closeX,mtBarCnt,EffRatioLength,FastAvgLength,SlowAvgLength);
  23.         PlotNumeric("AdpMa",AMAValue);       
  24. End
复制代码

使用道具 举报

Rank: 5Rank: 5

精华
1
UID
30159
积分
1116
帖子
280
主题
23
阅读权限
60
注册时间
2011-3-23
最后登录
2019-3-21
16#
发表于 2015-5-10 22:55:35 |只看该作者
本帖最后由 读书山林 于 2015-5-10 22:57 编辑
  1. //------------------------------------------------------------------------
  2. // 简称: iHHV
  3. // 名称: 跨期求Highest
  4. // 类别: 用户函数
  5. // 类型: 用户函数
  6. // 输出: 数值型
  7. //------------------------------------------------------------------------

  8. Params
  9.         NumericSeries Price(0);
  10.         NumericSeries mtBarCnt(0);        
  11.         Numeric Length(5);
  12. Vars
  13.         Numeric HighestValue;
  14.         Numeric i;
  15.         Numeric j;       
  16. Begin                       
  17.         HighestValue = Price;               
  18.         for i=1 to Length - 1
  19.        {
  20.                 j=iRef(mtBarCnt,i);
  21.                 If(Price[j] > HighestValue)
  22.                         HighestValue = Price[j];
  23.         }
  24.         Return HighestValue;
  25. End
复制代码

使用道具 举报

Rank: 5Rank: 5

精华
1
UID
30159
积分
1116
帖子
280
主题
23
阅读权限
60
注册时间
2011-3-23
最后登录
2019-3-21
17#
发表于 2015-5-10 22:56:27 |只看该作者
  1. //------------------------------------------------------------------------
  2. // 简称: iLLV
  3. // 名称: 跨期求Lowest
  4. // 类别: 用户函数
  5. // 类型: 用户函数
  6. // 输出: 数值型
  7. //------------------------------------------------------------------------

  8. Params
  9.         NumericSeries Price(0);
  10.         NumericSeries mtBarCnt(0);                
  11.         Numeric Length(5);
  12. Vars
  13.         Numeric LowestValue;
  14.         Numeric i;
  15.         Numeric j;               
  16. Begin
  17.         LowestValue = Price;       
  18.         for i=1 to Length - 1
  19.        {
  20.                 j=iRef(mtBarCnt,i);       
  21.                 If(Price[j] < LowestValue)
  22.                         LowestValue = Price[j];
  23.         }
  24.         Return LowestValue;

  25. End
复制代码

使用道具 举报

Rank: 1

精华
0
UID
115259
积分
20
帖子
15
主题
4
阅读权限
10
注册时间
2013-1-30
最后登录
2018-11-27
18#
发表于 2015-5-10 22:58:01 |只看该作者
还没完全看懂 谢谢山林老师 留着细细看

使用道具 举报

Rank: 5Rank: 5

精华
1
UID
30159
积分
1116
帖子
280
主题
23
阅读权限
60
注册时间
2011-3-23
最后登录
2019-3-21
19#
发表于 2015-5-10 23:12:19 |只看该作者
glaceage 发表于 2015-5-10 22:58
还没完全看懂 谢谢山林老师 留着细细看

会用调用就行,调用已经很方便了

使用道具 举报

Rank: 1

精华
0
UID
180855
积分
26
帖子
16
主题
6
阅读权限
10
注册时间
2014-2-20
最后登录
2022-4-20
20#
发表于 2015-5-11 10:17:27 |只看该作者
非常感谢!

使用道具 举报

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

bottom

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

GMT+8, 2024-4-20 22:37

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部