Profile Picture

Userseries.SetValue error

Posted By stanleyu 4 Years Ago
Posted Saturday January 03 2015
I'm developing an indicator that inherits the IndicatorBase class. In this indicator, I need to use EMA values of the stock closing price in the calculation. Since the EMA parameter requires ISeries[] object, so I created a variable of Class "UserSeries", but I'm running into an error on the line CloseBars.SetValue(...), that I'm not sure what caused it. 

The error message is "An exception of type 'System.NullReferenceException' occurred in Common.dll but was not handled in user code"
When I mouse over the CloseBars object in Visual Studio, the property Count and Current are null and an error "NullReferenceException" is displayed.
The error is inituative, but I'm not sure what have I not done right here to instantiate this object properly. Please advise.

        public override RList<double> CalcSeriesValues(RList<BarData> bars)
            BarData bar;
            UserSeries CloseBars = new UserSeries();

            for (int i = 0; i < bars.Count; i++) {
                bar = bars.LookBack(i);
                CloseBars.SetValue(i, bar.Close);
            ema50 = new EMA(50, CloseBars);
Posted Sunday January 04 2015
Using an indicator from inside another is a bit tricky.  In this case the easiest thing to do is to avoid it altogether and use the IndicatorMath.EMAValue method to calculate the EMA instead of using the EMA indicator class.

In general, I don't think there's a very good way to use a SeriesCalculator indicator from inside an IndicatorBase indicator.  If you needed to do so, I'd suggest changing your indicator to be a SeriesCalculator that takes the bar elements it needs as inputs.

See the SampleAverageAverage2 example from this post for how to use a SeriesCalculator inside another one (this is also included in the SampleIndicators project in the RightEdge samples).

Posted Monday January 05 2015
Daniel, I've tried having my indicator extend the class "SeriesCalculatorBaseWithValues", and I run into another problem.
In the class, i defined 'Close' as my indicator input:     [SeriesInputAttribute("Input", 1, Value = BarElement.Close)]

In the method below, I got the 'System.ArgumentOutofRangeException' error. When I traced into the code, both ema50 and atr50 variables were instantiated, but they contain no value. I am sure the inputs[0] has values, because the barCounts returned is greater than 0. Any suggestions will be much appreciated.
         protected override void Reset()
            barCounts = inputs[0].Count;
            ema50 = new EMA(shortEMAdays, inputs[0]);
            atr50 = new AverageTrueRange(50);
Posted Thursday January 08 2015
You're trying to use both an EMA indicator and an AverageTrueRange indicator.  EMA is a series calculator and the AverageTrueRange is an IndicatorBase indicator, and unfortunately RightEdge doesn't really support having an indicator which internally uses both types of indicators.

In your case, I recommend deriving your indicator from IndicatorBase, and using the IndicatorMath.EMAValue method to calculate the EMA instead of the EMA indicator class.  In your indicator, you'll need to override the SetBars and AppendBar methods, and call the same method on the AverageTrueRange indicator before calling the class version of the method.


Similar Topics

Reading This Topic

2005-2019 © RightEdge Systems