So, if you have patience and are willing to help, thanks in advance. This will likely bore more experienced coders, so apologies for that.
The formula for RSI is pretty straightforward from a math standpoint.
RSI = 100 - (100/(1 + RS)
where RS = (Avg Up Closes for X periods) / (Avg Down Closes for X periods)
And then there is the script, repeated below.
It contains the usual inputs and variables, plus two If/Then/Else statements. It's the If/Then/Else statements I don't understand. Particularly the use of CurrentBar, which is apparently connected to MaxBarsBack. This makes no sense to me. If I have MaxBarsBack set to 200 because I am using a 200day EMA as a filter, it seems this would totally screw up my RSI calculation. Perhaps the definition of CurrentBar should be (or is) related to the number of periods used in the RSI calculation instead of MaxBarsBack? But that's not what the definition says, hence my confusion.
Code: Select all
PriceValue( numericseries ),
Len( numericsimple ) ;
var0( 0 ),
var1( 0 ),
var2( 0 ),
var3( 1 / Len ),
var4( 0 ) ;
if CurrentBar = 1 then
var0 = ( PriceValue - PriceValue[Len] ) / Len ;
var1 = Average( AbsValue( PriceValue - PriceValue ), Len ) ;
var2 = PriceValue - PriceValue ;
var0 = var0 + var3 * ( var2 - var0 ) ;
var1 = var1 + var3 * ( AbsValue( var2 ) - var1 ) ;
if var1 <> 0 then
var4 = var0 / var1
var4 = 0 ;
RSI = 50 * ( var4 + 1 ) ;
I have many more questions, but perhaps we should start with that one, as it may clear up some of the other questions. Again, thanks in advance.