Profile Picture

New Indicator Error

Posted By jimbob 8 Years Ago
Message
Posted Thursday December 31 2009
I am trying to build a new indicator and keep getting an error. The below is a test that should just return 20.

The error says "Need exactly 3 input series, 1 was passed in."

Not sure where or how to input 3 series. I have input set to 1.

Any ideas?

Imports System

Imports System.Collections.Generic

Imports System.Text

Imports RightEdge.Indicators

Imports RightEdge.Common

' Indicators that implement SeriesCalculatorBaseSimple will support chaining since they can view the calculated

' values of other series inputs.

' See the readme.txt included in this project for more information.

' Use the Indicator Attribute to provide information such as the

' name and description of your indicator. If you do not include

' this attribute, your indicator will not show up in the indicator

' list.

' The Id attribute needs to be set to a unique code that will identify

' your indicator. A GUID is a good candidate.

' Indicators must be marked Serializable in order to be used in

' trading systems.

' Use the SeriesInputAttribute to specify how many inputs your

' indicator uses.

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

Author:="Name", _

CompanyName:="Company", _

Description:="Test", _

GroupName:="~Jimmy", _

HelpText:="Help", _

Id:="{5F6EFD6C-492C-4312-9259-5F10Q8SB44F8}", _

DefaultDrawingPane:="Test", _

Name:="Test")> _

<Serializable()> _

<SeriesInputAttribute("Input", 1, Value:=BarElement.Close)> _

Public Class Test : Inherits SeriesCalculatorBaseWithValues

<ConstructorArgument("Volatility Period", ConstructorArgumentType.Integer, "10", 1)> _

Public Sub New(ByVal myVOLATILITY_PERIOD As Integer)

MyBase.New(3)

If myVOLATILITY_PERIOD <= 0 Then

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

End If

End Sub

Protected Overloads Overrides Function CalcNewValue(ByVal index As Integer) As Double

Return 20

End Function

Protected Overrides Sub Reset()

End Sub

Public Overloads Overrides Sub SetInputs(ByVal ParamArray newInputs As ISeries())

MyBase.SetInputs(newInputs(0))

End Sub

Posted Saturday January 02 2010
No worries fixed it.

But have another question. If I am creating an indicator that uses ATR and SMA's what should I use? IndicatorBase, SeriesCalculatorBaseWithValues or SeriesCalculatorBase?

The indicator will only use a close series but ATR needs all the inputs to work and the SMA only needs the close series.

All other inputs are integers or doubles.

Thanks.
Posted Monday January 04 2010
See this help topic about creating indicators for a rundown on what to derive from depending on your needs.

jimbob (1/2/2010)
No worries fixed it.

But have another question. If I am creating an indicator that uses ATR and SMA's what should I use? IndicatorBase, SeriesCalculatorBaseWithValues or SeriesCalculatorBase?

The indicator will only use a close series but ATR needs all the inputs to work and the SMA only needs the close series.

All other inputs are integers or doubles.

Thanks.
Posted Thursday January 07 2010
OK seam to be on the track now.

How can I create an ISeries from a Rlist?

I use

Private pBars As RList(Of BarData)

To keep track of the bar data but I need an ISeries to feed into the SMA indicator how can I do that?

Thanks.
Posted Thursday January 07 2010
An ISeries is a double backed interface for use with indicators.  An RList is a generic collection, so one way to provide ISeries functionality from an RList would be to derive from ISeries and use your RList as the double based backing.  Try something like this:

public class MySeries : ISeries
{
   
RList<BarData> data;

   
public MySeries(RList<BarData> barSeries)
   
{
       
data = barSeries;
    }

    protected RList<BarData> barSeries
   
{
        
get
        
{
           
return data;
        }
    }

#region ISeries Members

public double LookBack(int nBars)
{
   
// Note, change this to accept which element of the bar you want to use, it's hard coded to close
   
return BarUtils.GetValueForBarElement(barSeries.LookBack(nBars), BarElement.Close);
}

 

public double Current
{
    
get
    
{
       
return LookBack(0);
     }
}


public
int Count
{
   
get
   
{
       
return barSeries.Count;
    }
}

 

public virtual bool OldValuesChange
{
   
get
   
{   return false;   }
}

 

public int OldestValueChanged
{
    get { return 0; }
}

 

public SeriesChartSettings ChartSettings
{
   
get { throw new NotSupportedException(); }
   
set { throw new NotSupportedException(); }
}

#endregion

}

Posted Thursday January 07 2010
While you can create an implementation of ISeries that reads from an RList, in practice you probably don't want to do this. Indicator values for a new bar are all calculated before NewBar is called. So you won't have a chance to update the current value for the RList/ISeries before it is used as an input for the SMA or whatever other indicator you are using.

If you just need an ISeries of the Close or other bar element, these already exist for you to use. The Open, Low, High, Close, and Volume properties of the symbol script class are all of type ISeries.

Thanks,
Daniel
Posted Friday January 08 2010
Great work - It is working now.

Thanks.


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems