Board logo

标题: TB指标(RSI)源码 [打印本页]

作者: 龙听    时间: 2017-11-2 13:58     标题: TB指标(RSI)源码

  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. //------------------------------------------------------------------------
复制代码





欢迎光临 龙听期货论坛 (http://www.qhlt.cn/) Powered by Discuz! 7.2