设为首页收藏本站

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

RSI的第一个值是怎么来的 [复制链接]

Rank: 2

精华
0
UID
114998
积分
73
帖子
40
主题
13
阅读权限
30
注册时间
2013-1-20
最后登录
2020-2-25
跳转到指定楼层
1#
发表于 2013-5-28 14:36:53 |只看该作者 |倒序浏览
刚开始学TB,请教一下RSI的计算。
If(CurrentBar <= Length - 1)的时候Close[Length] 的值都是空的,那么NetChgAvg = ( Close - Close[Length] ) / Length 应该也是空值,那么第一个NetChgAvg的值是怎么计算来的,谢谢。
  1. //------------------------------------------------------------------------
  2. // 简称: RSI
  3. // 名称: 相对强弱指数
  4. // 类别: 公式应用
  5. // 类型: 内建应用
  6. //------------------------------------------------------------------------

  7. Params
  8.         Numeric Length(14) ;
  9.         Numeric OverSold(30) ;
  10.         Numeric OverBought(70) ;
  11. Vars
  12.         NumericSeries NetChgAvg( 0 );
  13.         NumericSeries TotChgAvg( 0 );
  14.         Numeric SF( 0 );
  15.         Numeric Change( 0 );       
  16.         Numeric ChgRatio( 0 ) ;
  17.         Numeric RSIValue;
  18. Begin       
  19.         If(CurrentBar <= Length - 1)
  20.         {
  21.                 NetChgAvg = ( Close - Close[Length] ) / Length ;
  22.                 TotChgAvg = Average( Abs( Close - Close[1] ), Length ) ;
  23.         }Else
  24.         {
  25.                 SF = 1/Length;
  26.                 Change = Close - Close[1] ;
  27.                 NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
  28.                 TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;       
  29.         }
  30.        
  31.         If( TotChgAvg <> 0 )
  32.         {
  33.                 ChgRatio = NetChgAvg / TotChgAvg;
  34.         }else
  35.         {
  36.                 ChgRatio = 0 ;
  37.         }       
  38.         RSIValue = 50 * ( ChgRatio + 1 );       
  39.         PlotNumeric("RSI",RSIValue);
  40.         PlotNumeric("超买",OverBought);
  41.         PlotNumeric("超卖",OverSold);
  42. End

  43. //------------------------------------------------------------------------
  44. // 编译版本        GS2010.12.08
  45. // 版权所有        TradeBlazer Software 2003-2010
  46. // 更改声明        TradeBlazer Software保留对TradeBlazer平
  47. //                        台每一版本的TradeBlazer公式修改和重写的权利
  48. //------------------------------------------------------------------------
复制代码

Rank: 2

精华
0
UID
114998
积分
73
帖子
40
主题
13
阅读权限
30
注册时间
2013-1-20
最后登录
2020-2-25
2#
发表于 2013-5-28 15:50:53 |只看该作者
自己搞明白了,原来Bar数据、序列变量在回溯越界时用该数据源的第1个值代替,而不是返回空值。

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
117799
积分
2351
帖子
151
主题
6
阅读权限
70
注册时间
2013-4-9
最后登录
2015-1-23
3#
发表于 2013-6-8 15:43:02 |只看该作者

if(hitoday>=ssetup and marketposition>-1 and GetGlobalVar(1)<1)
        {
                If(Low<=(senter+(hitoday-ssetup)/div))
                {
                        SellShort(1,senter+(hitoday-ssetup)/div);
                        SetGlobalVar(1,Time);
                        Return;
                }
        }
        if(ltoday<=bsetup and marketposition<1  and GetGlobalVar(1)<1)
        {
                If(High>=(benter-(bsetup-ltoday)/div))
                {
                        Buy(1,benter-(bsetup-ltoday)/div);
                        SetGlobalVar(1,Time);
                       Return;
                }
        }
这一段可能会出现同一根BAR既满足high值高于ssetup,又满足Low<=(senter+(hitoday[1]-ssetup)/div)的情况,但实际无法判断先后。

改成
        if(hitoday[1]>=ssetup and marketposition>-1 and GetGlobalVar(1)<1 &&date==date[1])
        {
              If(Low<=(senter+(hitoday[1]-ssetup)/div))
                {
                        SellShort(1,senter+(hitoday[1]-ssetup)/div);
                        SetGlobalVar(1,Time);
                        Return;
                }
        }
        if(ltoday[1]<=bsetup and marketposition<1  and GetGlobalVar(1)<1 &&date==date[1])
        {
                If(High>=(benter-(bsetup-ltoday[1])/div))
                {
                        Buy(1,benter-(bsetup-ltoday[1])/div);
                        SetGlobalVar(1,Time);
                Return;
                }
        }
这样子会不会好一点?还有后面的if(marketposition==0)那一段貌似也得加上跳空判断~    本人在实盘观察过的确有实盘闪烁过。还要自己仔细看一看啦!
和大家一样也是一个期货爱好者,在前进的道路上也是伤疤累累!但并为自己的爱好奋斗着。

使用道具 举报

Rank: 6Rank: 6

精华
0
UID
117799
积分
2351
帖子
151
主题
6
阅读权限
70
注册时间
2013-4-9
最后登录
2015-1-23
4#
发表于 2013-6-8 17:19:45 |只看该作者


if(hitoday>=ssetup and marketposition>-1 and GetGlobalVar(1)<1)
        {
                If(Low<=(senter+(hitoday-ssetup)/div))
                {
                        SellShort(1,senter+(hitoday-ssetup)/div);
                        SetGlobalVar(1,Time);
                        Return;
                }
        }
        if(ltoday<=bsetup and marketposition<1  and GetGlobalVar(1)<1)
        {
                If(High>=(benter-(bsetup-ltoday)/div))
                {
                        Buy(1,benter-(bsetup-ltoday)/div);
                        SetGlobalVar(1,Time);
                       Return;
                }
        }
这一段可能会出现同一根BAR既满足high值高于ssetup,又满足Low<=(senter+(hitoday[1]-ssetup)/div)的情况,但实际无法判断先后。

改成
        if(hitoday[1]>=ssetup and marketposition>-1 and GetGlobalVar(1)<1 &&date==date[1])
        {
              If(Low<=(senter+(hitoday[1]-ssetup)/div))
                {
                        SellShort(1,senter+(hitoday[1]-ssetup)/div);
                        SetGlobalVar(1,Time);
                        Return;
                }
        }
        if(ltoday[1]<=bsetup and marketposition<1  and GetGlobalVar(1)<1 &&date==date[1])
        {
                If(High>=(benter-(bsetup-ltoday[1])/div))
                {
                        Buy(1,benter-(bsetup-ltoday[1])/div);
                        SetGlobalVar(1,Time);
                Return;
                }
        }
这样子会不会好一点?还有后面的if(marketposition==0)那一段貌似也得加上跳空判断~    本人在实盘观察过的确有实盘闪烁过。还要自己仔细看一看啦!
和大家一样也是一个期货爱好者,在前进的道路上也是伤疤累累!但并为自己的爱好奋斗着。

使用道具 举报

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

bottom

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

GMT+8, 2024-5-23 12:11

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部