请问怎么TB的RSI指标和别的期货软件指标不一样啊?一般RSI指标都是快线 ,中线,慢线,三条线啊!麻烦老师帮忙改一下,以下是华安RSI指标。
//------------------------------------------------------------------------
// 简称:RSI
// 名称:RSI
// 类别: 交易指令
// 类型: 用户应用
//------------------------------------------------------------------------
Params
//参数定义
Integer N1(6);
Integer N2(12);
Integer N3(24);
GlobalVars
//全局变量定义
Vars
//局部变量定义
Begin
//策略执行区
Numeric LC = REF(CLOSE,1);
Numeric RSI1 =SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;
Numeric RSI2 =SMA(MAX(CLOSE-LC,0),N2,1)/SMA(ABS(CLOSE-LC),N2,1)*100;
Numeric RSI3 =SMA(MAX(CLOSE-LC,0),N3,1)/SMA(ABS(CLOSE-LC),N3,1)*100;
PlotNumeric("RSI1",RSI1);
PlotNumeric("RSI2",RSI2);
PlotNumeric("RSI3",RSI3);
End
请改成TB指标,谢谢!
我自己写了一个 供你参考,只有2个周期
Params
Numeric Length1(7) ;
Numeric Length2(14) ;
Events
OnBar(ArrayRef<Integer> indexs)
{
Range[0:DataSourceSize() - 1]
{
PlotNumeric("RSI1",RSIFC(Close,Length1));
PlotNumeric("RSI2",RSIFC(Close,Length2));
}
}
————————————————————————————————————————
RSIFC
Params
Numeric Price(1); //数值型序列值
Numeric Length(10); //周期数
Vars
Series<Numeric> NetChgAvg( 0 );
Series<Numeric> TotChgAvg( 0 );
Numeric SF( 0 );
Numeric Change( 0 );
Numeric ChgRatio( 0 ) ;
Numeric RSIValue;
Begin
If(CurrentBar <= Length - 1)
{
NetChgAvg = ( Close - Close[Length] ) / Length ;
TotChgAvg = Average( Abs( Close - Close[1] ), Length ) ;
}Else
{
SF = 1/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 );
Return RSIValue;
End
一个是快捷计算RSI 一个是多周期显示在图表上