RSI的第一個值是怎么來的 [開拓者 TB]
- 咨詢內容:
剛開始學TB,請教一下RSI的計算。
If(CurrentBar <= Length - 1)的時候Close[Length] 的值都是空的,那么NetChgAvg = ( Close - Close[Length] ) / Length 應該也是空值,那么第一個NetChgAvg的值是怎么計算來的,謝謝。- //------------------------------------------------------------------------
- // 簡稱: RSI
- // 名稱: 相對強弱指數
- // 類別: 公式應用
- // 類型: 內建應用
- //------------------------------------------------------------------------
- Params
- Numeric Length(14) ;
- Numeric OverSold(30) ;
- Numeric OverBought(70) ;
- Vars
- NumericSeries NetChgAvg( 0 );
- NumericSeries 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 );
- PlotNumeric("RSI",RSIValue);
- PlotNumeric("超買",OverBought);
- PlotNumeric("超賣",OverSold);
- End
- //------------------------------------------------------------------------
- // 編譯版本 GS2010.12.08
- // 版權所有 TradeBlazer Software 2003-2010
- // 更改聲明 TradeBlazer Software保留對TradeBlazer平
- // 臺每一版本的TradeBlazer公式修改和重寫的權利
- //------------------------------------------------------------------------
- //------------------------------------------------------------------------
- TB技術人員:
自己搞明白了,原來Bar數據、序列變量在回溯越界時用該數據源的第1個值代替,而不是返回空值。
- TB客服:
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)那一段貌似也得加上跳空判斷~ 本人在實盤觀察過的確有實盤閃爍過。還要自己仔細看一看啦!
- 網友回復:
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)那一段貌似也得加上跳空判斷~ 本人在實盤觀察過的確有實盤閃爍過。還要自己仔細看一看啦!
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 1145508240 進行 有償 編寫!(不貴!點擊查看價格!)
相關文章
-
沒有相關內容