Profile Picture

Using RSI in my own indicator

Posted By kaizen 5 Years Ago
Message
Posted Friday December 21 2012
I am building my own indicator and it uses RSI for one of the calculations so rather than writing a new one I am trying to use RE own RSI.

For some reason it always throws a an error when I call RSI.Newbar() saying use the new keyword to create an instance. From what I can see though I have already created the instance.

Any ideas?

System.NullReferenceException was unhandled by user code
Message=Object reference not set to an instance of an object.
Source=Common
StackTrace:
at RightEdge.Common.SeriesCalculatorBase.get_OldValuesChange()
at RightEdge.Common.SeriesCalculatorBaseWithValues.NewBar()
at James_Indicators.ConnorsRSI.CalcNextValue(BarData bar) in C:\Users\Jimmy\Documents\Trading Systems\RE 2010\James Indicator\ConnorsRSI.vb:line 85
at RightEdge.Common.IndicatorBase.CalcSeriesValues(RList`1 bars)
at James_Indicators.ConnorsRSI.CalcSeriesValues(RList`1 bars) in C:\Users\Jimmy\Documents\Trading Systems\RE 2010\James Indicator\ConnorsRSI.vb:line 72
at RightEdge.Common.IndicatorBase.SetBars(RList`1 bars)
at RightEdge.Shared.IndicatorWrapper.SetBars(RList`1 bars)
InnerException:




Imports System
Imports System.Collections.Generic
Imports System.Text
Imports RightEdge.Indicators
Imports RightEdge.Common


Author:="James", _
CompanyName:="Wd", _
Description:="ConnorsRSI", _
GroupName:="~James", _
HelpText:="", _
Id:="{5F4E3D6C-492D-4212-9259-5F10W8SB44C8}", _
DefaultDrawingPane:="ConnorsRSI", _
Name:="ConnorsRSI")> _
_
Public Class ConnorsRSI : Inherits IndicatorBase


Dim streakValue As StreakValue
Dim daily_retuns As DailyReturns
Dim pntRank As PercentRank
Dim RSI2 As RelativeStrength
Dim RSIStreak As RelativeStrength
Dim RSIPcnt_Rank As RelativeStrength
Dim closeSeries As MySeries
Private pBars As RList(Of BarData) = Nothing 'bar data series

Dim RSI_Period As Integer = 3
Dim percent_rank_period As Integer = 100
Dim streak_period As Integer = 2


_
_
_
Public Sub New(ByVal RSIPeriod As Integer, PercentRankPeriod As Integer, StreakPeriod As Integer)
MyBase.New()
If RSIPeriod <= 0 Then
Throw New ArgumentException("Lookback period must be greater than zero")
End If
If PercentRankPeriod <= 0 Then
Throw New ArgumentException("ATR Lookback period must be greater than zero.")
End If
If StreakPeriod <= 0 Then
Throw New ArgumentException("ATR Lookback period must be greater than zero.")
End If

Me.RSI_Period = RSIPeriod
Me.percent_rank_period = PercentRankPeriod
Me.streak_period = StreakPeriod

pBars = New RList(Of BarData)()
closeSeries = New MySeries(pBars, BarElement.Close)
RSI2 = New RelativeStrength(Me.RSI_Period, closeSeries)
pntRank = New PercentRank(Me.percent_rank_period)
streakValue = New StreakValue
RSIStreak = New RelativeStrength(Me.streak_period)

streakValue.SetInputs(closeSeries)
pntRank.SetInputs(daily_retuns)
RSI2.SetInputs(closeSeries)
RSIStreak.SetInputs(streakValue)


End Sub


Public Overrides Function CalcSeriesValues(ByVal bars As RList(Of BarData)) As RList(Of Double)

Return MyBase.CalcSeriesValues(bars)

End Function

Public Overrides Function CalcNextValue(ByVal bar As BarData) As Double

Dim connorsRSI As Double = 0
pBars.Add(bar)


If pBars.Count < 5 Then Return Double.NaN

streakValue.NewBar()
pntRank.NewBar()
RSIStreak.NewBar() ================This line and the one below throws the error above.
RSI2.NewBar()

If pBars.Count < Math.Max(Math.Max(Me.streak_period, Me.percent_rank_period), Me.RSI_Period) Then
Return Double.NaN
End If

connorsRSI = ((RSI2.Current + pntRank.Current + RSIStreak.Current) / 3)

Return connorsRSI


End Function

End Class



Edited: Friday December 21 2012 by kaizen
Posted Friday December 21 2012
I'm not sure exactly why you're getting that error, it appears to be an issue with the inputs to your RSIs (ie the close series or streak value). In any case, I'd highly recommend using the RSIQueue class instead of the RSI indicator itself when you need to calculate the RSI in code. It is complicated to get the code correct for using one indicator inside another, and the RSIQueue class provides an easy-to-use API for calculating the RSI.

Thanks,
Daniel
Posted Thursday December 27 2012
I updated it t use RSIQueue but get them same error:

System.NullReferenceException was unhandled by user code
  Message=Object reference not set to an instance of an object.
  Source=Common
  StackTrace:
       at RightEdge.Common.SeriesCalculatorBase.get_OldValuesChange()
       at RightEdge.Common.SeriesCalculatorBaseWithValues.NewBar()
       at James_Indicators.ConnorsRSI.CalcNextValue(BarData bar) in C:\Users\Jimmy\Documents\Trading Systems\RE 2010\James Indicator\ConnorsRSI.vb:line 84
       at RightEdge.Common.IndicatorBase.CalcSeriesValues(RList`1 bars)
       at James_Indicators.ConnorsRSI.CalcSeriesValues(RList`1 bars) in C:\Users\Jimmy\Documents\Trading Systems\RE 2010\James Indicator\ConnorsRSI.vb:line 71
       at RightEdge.Common.IndicatorBase.SetBars(RList`1 bars)
       at RightEdge.Shared.IndicatorWrapper.SetBars(RList`1 bars)
  InnerException:

Is indicatorBase right for what I am trying to do here?

Does the CalcSeriesValues function need anything in it?

Has me beat as to why it won't work:

Imports System

Imports System.Collections.Generic

Imports System.Text

Imports RightEdge.Indicators

Imports RightEdge.Common

 

<Indicator(System.Drawing.KnownColor.Black, _

Author:="James", _

CompanyName:="Wild", _

Description:="ConnorsRSI", _

GroupName:="~James", _

HelpText:="", _

Id:="{5F4E3D6C-492D-4212-9259-5F10W8SB44C8}", _

DefaultDrawingPane:="ConnorsRSI", _

Name:="ConnorsRSI")> _

<Serializable()> _

Public Class ConnorsRSI : Inherits IndicatorBase

 

Dim streakValue As StreakValue

Dim daily_retuns As DailyReturns

Dim pntRank As PercentRank

Dim RSI2 As New RSIQueue(3)

Dim RSIStreak As New RSIQueue(2)

Dim closeSeries As MySeries

Private pBars As RList(Of BarData) = Nothing 'bar data series

Dim RSI_Period As Integer = 3

Dim percent_rank_period As Integer = 100

Dim streak_period As Integer = 2

 

<ConstructorArgument("RSI Period", ConstructorArgumentType.Integer, "3", 1)> _

<ConstructorArgument("Percent Rank Period", ConstructorArgumentType.Integer, "100", 2)> _

<ConstructorArgument("RSI Streak Period", ConstructorArgumentType.Integer, "2", 3)> _

Public Sub New(ByVal RSIPeriod As Integer, PercentRankPeriod As Integer, StreakPeriod As Integer)

MyBase.New()

If RSIPeriod <= 0 Then

Throw New ArgumentException("Lookback period must be greater than zero")

End If

If PercentRankPeriod <= 0 Then

Throw New ArgumentException("ATR Lookback period must be greater than zero.")

End If

If StreakPeriod <= 0 Then

Throw New ArgumentException("ATR Lookback period must be greater than zero.")

End If

Me.RSI_Period = RSIPeriod

Me.percent_rank_period = PercentRankPeriod

Me.streak_period = StreakPeriod

pBars = New RList(Of BarData)()

closeSeries = New MySeries(pBars, BarElement.Close)

'RSI2 = New RSIQueue(Me.RSI_Period)

pntRank = New PercentRank(Me.percent_rank_period)

streakValue = New StreakValue

'RSIStreak = New RSIQueue(Me.streak_period)

streakValue.SetInputs(closeSeries)

pntRank.SetInputs(daily_retuns)

'RSI2.SetInputs(closeSeries)

'RSIStreak.SetInputs(streakValue)

 

End Sub

 

Public Overrides Function CalcSeriesValues(ByVal bars As RList(Of BarData)) As RList(Of Double)

Return MyBase.CalcSeriesValues(bars)

End Function

Public Overrides Function CalcNextValue(ByVal bar As BarData) As Double

Dim connorsRSI As Double = 0

pBars.Add(bar)

 

If pBars.Count < 5 Then Return Double.NaN

streakValue.NewBar()

pntRank.NewBar()

RSI2.AddValue(pBars.Current.Close)

RSIStreak.AddValue(streakValue.Current)

If pBars.Count < Math.Max(Math.Max(Me.streak_period, Me.percent_rank_period), Me.RSI_Period) Then

Return Double.NaN

End If

If Not RSIStreak.Full Or Not RSI2.Full Then

Return Double.NaN

End If

connorsRSI = ((RSI2.Value + pntRank.Current + RSIStreak.Value) / 3)

Return connorsRSI

 

End Function

End Class




Posted Monday December 31 2012
All good I got it fixed.

Thanks


Posted Sunday January 13 2013
Please, can you share your ConnorsRSI indicator?
Posted Monday January 28 2013
The problem is my ConnorsRSI uses other indicators I developed as well so it is nto just one.The above does most of what you need anyway.

FYI - I do not think it is that good anyway. I have developed better overbought/oversold indicators.




Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems