Bug with Chart.AddIndicators which use a Secondary Timeframe
Bug with Chart.AddIndicators which use a Secondary Timeframe
28 Jul 2024, 21:14
Hello Spotware,
I've found an issue when using the new Chart.AddIndicators in which it doesn't reference properties correctly when they are of TimeFrame type.
Steps to Replicate
Indicator Code
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo;
[Indicator(AccessRights = AccessRights.None)]
public class MtfMovingAvg : Indicator
{
[Parameter("Big TF", DefaultValue = "Hour")]
public TimeFrame InputBigTf { get; set; }
[Parameter("Period", DefaultValue = 14)]
public int InputPeriod { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
private SimpleMovingAverage _sma;
private Bars _htfBars;
protected override void Initialize()
{
_htfBars = MarketData.GetBars(InputBigTf);
_sma = Indicators.SimpleMovingAverage(_htfBars.ClosePrices, InputPeriod);
}
public override void Calculate(int index)
{
var highIndex = _htfBars.OpenTimes.GetIndexByTime(Times[index]);
Result[index] = _sma.Result[highIndex];
}
public DataSeries Open => Bars.OpenPrices;
public DataSeries High => Bars.HighPrices;
public DataSeries Low => Bars.LowPrices;
public DataSeries Close => Bars.ClosePrices;
public TimeSeries Times => Bars.OpenTimes;
public int Index => Bars.Count - 1;
}
Robot Code
using System;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots;
[Robot(AccessRights = AccessRights.None)]
public class ReportIssueAddingMtfIndicator : Robot
{
[Parameter("Big TF", DefaultValue = "Hour")]
public TimeFrame InputBigTf { get; set; }
[Parameter("Period", DefaultValue = 14)]
public int InputPeriod { get; set; }
protected override void OnStart()
{
ChartIndicators.Add("MtfMovingAvg", InputBigTf, InputPeriod);
}
protected override void OnTick() { }
protected override void OnStop() { }
}
And here's a video of how it looks:
https://app.screencast.com/rtGrFUY49FzMM
Would appreciate a fix soon, thanks for your support.
Regards,