Profile Picture

using ranking system with custom indicator, index is not incrementing in subsequent calls to...

Posted By jsmarion 2 Years Ago

using ranking system with custom indicator, index is not incrementing...

Message
Posted Wednesday December 23 2015
Hi all -

I am trying to create a ranking system using my own indicator based on SeriesCalculatorBaseWithValues, The problem is that the index is not being incremented in subsequent calls to CalcNewValue(index). It's always 0. Any idea why this is the case?

Thanks
John

Ranking system code
-----------------------------------------------------------------------------------------------------------------------------
public class MySystem : MySystemBase
{
public override void NewBar()
{
base.NewBar();
List<MySymbolScript> orderedSymbolScripts = SymbolScripts.OrderByDescending(ss => ss.RankValue).ToList();
for (int i=0; i < orderedSymbolScripts.Count; i++)
{
orderedSymbolScripts[i].Rank = i + 1;
}
foreach (MySymbolScript ss in orderedSymbolScripts)
{
ss.Trade();
}
}
}

public class MySymbolScript : MySymbolScriptBase
{
public double RankValue { get; private set; }
public int Rank { get; set; }

Alpha _alpha;

public override void Startup()
{
    _alpha = new Alpha((int)SystemParameters["AlphaPeriods"]);
    _alpha.SetInputs(Close, OtherSymbols["SPY"].Close);
  }

public override void NewBar()
{
    if (double.IsNaN(_alpha.Current))
{
RankValue = 0;
}
else
{
RankValue = Math.Abs(_alpha.Current);
    }
}

indicator code:
-----------------------------------------------------------------------------------------------------------------------------

namespace MyIndicator
{
  [Indicator(KnownColor.LightBlue,
   Author = "John",
   CompanyName = "John",
   Description = "Alpha",
   GroupName = "Trend",
   HelpText = "Computes the Alpha of the input.",
   Id = "{6288c487-9867-468a-b848-98c50e6ddd2b}",
   Name = "Alpha")]
  [Serializable]
  [SeriesInputAttribute("Input", 2, Value = BarElement.Close)]

  public class Alpha : SeriesCalculatorBaseWithValues
  {
   private readonly int _periods;

    public void Initialize(SystemData sd, Symbol sym)
   {
    }

   [ConstructorArgument("AlphaPeriods", ConstructorArgumentType.Integer, "10", 1)]

   public Alpha(int periods) : base(2)
   {
    if (periods <= 0)
    {
      throw new ArgumentException("Periods1 must be greater than zero");
    }
    _periods = periods;
    }

   protected override double CalcNewValue(int index)
   {
    if (index < _periods - 1)
    {
      return double.NaN;
    }

    return /* somevalue*/;
    }



Posted Thursday December 24 2015
The "index" parameter to CalcNewValue is (confusingly enough), the "lookback" index.  IE it counts backwards from the current bar, so 0 is always the index of the current bar.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems