Bug with Chart.AddIndicators which use a Secondary Timeframe

Created at 28 Jul 2024, 21:14
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
Waxy's avatar

Waxy

Joined 12.05.2015

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,


@Waxy