| Hello, I have decided that over the next few days I am going to post some example code of indicators. There are three different base classes that can be used to write an indicator and I am going to also try to explain when to use each type and why. First: SeriesCalculatorBaseSimple - Indicators of this sort are useful when you do not need to look backwards into the series. For example, if you were going to create a indicator that simple doubled the value of every input it would not ever need to look at previous values, just muliply the current value by two. For this example I have choosen an 'Absolute Value' indicator. Now the code. using System;using System.Collections.Generic;using System.Text;using RightEdge.Common; namespace Indicators{ [ YYEIndicatorAttribute(System.Drawing.KnownColor.Black, YYEIndicatorAttribute.EIndicatorGroup.Other, Name = "Absolute Value", Description = "Returns the absolute value of the input.", Id = "uniqueid-0000000", HelpText = "")] [ Serializable] [ SeriesInputAttribute("Input", 1)] public class AbsoluteValue : SeriesCalculatorBaseSimple { /// <summary> /// Constructs an Absolute Value indicator instance. /// </summary> public AbsoluteValue() : base(1) { } /// <summary> /// Returns a series value at the specified index. /// </summary> /// <param name="index">The index to retrieve series value.</param> /// <returns>A double containing the calculated value.</returns> public override double this[int index] { get { return Math.Abs(inputs[0][index]); } } } }
Now the runthrough of what everything here does. [YYEIndicatorAttribute(System.Drawing.KnownColor.Black, YYEIndicatorAttribute.EIndicatorGroup.Other, Name = "Absolute Value", Description = "Returns the absolute value of the input.", Id = "uniqueid-0000000", HelpText = "")] This attribute contains a number of parameters that help the UI of rightedge know how to present your indicator. The first paramter is the default drawing color of your indicator. The second is the group, which is used to place your indicator into our treeview of indicators. Next is the name that is shown in the treeview. The description is shown on the indicator information page. Next is a unique id for your indicator. Suggest you use your company name and then a unique number here. Internally we use GUIDS for this. Next is the friendly helptext for the indicator. Usually good to have a description of what the indicator does, how it does it and when it might be useful. [Serializable] Every indicator needs this attribute. Don't forget it. [SeriesInputAttribute("Input", 1)] This attribute lets RE know how many inputs are required for this indicator to work. In our case we accept one since we're just doing an absolute value on the members of a single series. If we needed two (or more) we would just specify the number here. public class AbsoluteValue : SeriesCalculatorBaseSimple We are deriving from SeriesCalulatorBaseSimplere here. public AbsoluteValue() : base(1) { } Our constructor does not do anything but call the base constructor, passing in the number of series (one, in this case). public override double this[int index] { get { return Math.Abs(inputs[0][index]); } } Overide the indexer for this class, returning the absolute value of the index of the first series. That's about it for a simple indicator. Any questions, please ask. We'd really like to see folks creating indicators and getting up to speed with this.
|