- 精华
- 20
- 在线时间
- 2981 小时
- UID
- 4
- 积分
- 22709
- 帖子
- 4802
- 阅读权限
- 255
- 注册时间
- 2007-7-20
- 最后登录
- 2024-1-15
- 精华
- 20
- UID
- 4
- 积分
- 22709
- 帖子
- 4802
- 主题
- 64
- 阅读权限
- 255
- 注册时间
- 2007-7-20
- 最后登录
- 2024-1-15
|
最近无意发现TS可以实现渐近色的指标,看了一下,发现TB不用系统函数也可以实现该功能,因此写一个例程供大家参考,没啥大用处,仅供玩赏.
1、首先,我们先要新建一个用户函数,取名为: GradientColor
返回值为数值型,代码如下:
- Params
- Numeric Price(10);
- Numeric minSet(20);
- Numeric MaxSet(80);
- Numeric StartColor(255);
- Numeric EndColor(65535);
- Vars
- Numeric offset;
- Numeric startRed;
- Numeric startGreen;
- Numeric startBlue;
- Numeric endRed;
- Numeric endGreen;
- Numeric endBlue;
- Numeric reRed;
- Numeric reGreen;
- Numeric reBlue;
- Numeric step;
- Numeric reColor;
- Begin
- step = 10;
- offset = (maxSet-minSet)/step;
- startRed = StartColor%256;
- startGreen = (StartColor/256)%256;
- startBlue = (StartColor/256/256);
- endRed = EndColor%256;
- endGreen = (EndColor/256)%256;
- endBlue = (EndColor/256/256);
-
- reRed = startRed + IntPart((Price - minSet)/offSet)*(endRed-startRed)/step;
- reGreen = startGreen + IntPart((Price - minSet)/offSet)*(endGreen-startGreen)/step;
- reBlue = startBlue+ IntPart((Price - minSet)/offSet)*(endBlue-startBlue)/step;
- FileAppend("C:\\formula.log","Red="+Text(reRed)+",Green="+Text(reGreen)+",Blue="+Text(reBlue));
- reColor = RGB(reRed,reGreen,reBlue);
- return reColor;
- End
复制代码
2、我们在RSI的基础上来进行修改,支持RSI渐近色!新建一个RSIEx技术指标,代码如下:
- Params
- Numeric Length(14) ;
- Numeric OverSold(30) ;
- Numeric OverBought(70) ;
- Vars
- NumericSeries NetChgAvg( 0 );
- NumericSeries TotChgAvg( 0 );
- Numeric Change( 0 );
- Numeric SF( 0 );
- Numeric ChgRatio( 0 ) ;
- Numeric RSIValue;
- Numeric curColor;
- Begin
- SF = 1/Length;
- If(CurrentBar < Length)
- {
- RSIValue = InvalidNumeric;
- }Else
- {
- If(CurrentBar == Length)
- {
- NetChgAvg = ( Close - Close[Length] ) / Length ;
- TotChgAvg = AverageFC( Abs( Close - Close[1] ), Length ) ;
- }
-
- If(CurrentBar>length)
- {
- Change = Close - Close[1] ;
- NetChgAvg = NetChgAvg[1] + SF * ( Change - NetChgAvg[1] ) ;
- TotChgAvg = TotChgAvg[1] + SF * ( Abs( Change ) - TotChgAvg[1] ) ;
- }
-
- If( TotChgAvg <> 0 )
- {
- ChgRatio = NetChgAvg / TotChgAvg ;
- }else
- {
- ChgRatio = 0 ;
- }
-
- RSIValue = 50 * ( ChgRatio + 1 ) ;
- }
- If(RSIValue > OverBought)
- {
- curColor = Red;
- }else if(RSIValue < OverSold)
- {
- curColor = DarkCyan;
- }Else
- {
- curColor = GradientColor(RSIValue,OverSold,OverBought,DarkCyan,Red);
- }
- PlotNumeric("RSI",RSIValue,curColor);
- PlotNumeric("超买",OverBought);
- PlotNumeric("超卖",OverSold);
- End
复制代码
3、插入图表,显示如下:
[ 本帖最后由 nopain 于 2007-10-16 15:39 编辑 ] |
附件: 你需要登录才可以下载或查看附件。没有帐号?注册
|