Multi Timeframe Indicator

Created at 15 Aug 2017, 22:13
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!
AN

andi21

Joined 14.12.2016

Multi Timeframe Indicator
15 Aug 2017, 22:13


Hello Spotware,

i have found an issue.

Code to reproduce:

    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TEST123 : Indicator
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        private MarketSeries x;

        protected override void Initialize()
        {
            // Initialize and create nested indicators
            x = MarketData.GetSeries(Symbol, TimeFrame.Daily);

            Print("1. " + MarketSeries.Open.Count + " " + MarketSeries.OpenTime[MarketSeries.Open.Count - 1]);
            Print("2. " + x.Open.Count + " " + x.OpenTime[x.Open.Count - 1]);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            // Result[index] = ...

            Print("AX0. " + index);
            Print("AX1. " + MarketSeries.Open.Count + " " + MarketSeries.OpenTime[MarketSeries.Open.Count - 1]);
            Print("AX2. " + x.Open.Count + " " + x.OpenTime[x.Open.Count - 1]);
        }
    }

Output:

15/08/2017 19:01:13.151 1. 4311 15.08.2017 19:00:00

15/08/2017 19:01:13.151 2. 8413 14.08.2017 21:00:00

 

15/08/2017 19:01:13.182 AX0. 0

15/08/2017 19:01:13.182 AX1. 1 06.12.2016 22:00:00

15/08/2017 19:01:13.182 AX2. 8413 14.08.2017 21:00:00

15/08/2017 19:01:13.182 AX0. 1

15/08/2017 19:01:13.182 AX1. 2 06.12.2016 23:00:00

15/08/2017 19:01:13.182 AX2. 8413 14.08.2017 21:00:00

 

Conclusion:

- On initialize both marketseries (current one from the chart and the daily one) have an initial count > 0

- On first Tick only the MarketSeries of the one from the chart is resetted to have only 1 bar (initial calculation)

- But the other MarketSeries remains with the complete bar count, although for intial calculation it should also open bar after bar and so should not have the complete bar count available, because we are only index 0.

 

It would be great if this behaviour could be fixed as somebody could expect.

Thank you in advance.

Best regards,

andi21


@andi21
Replies

Spotware
16 Aug 2017, 14:25

Hi andi21,

This is known behavior. Only current market series is modified until indicator is initialized and it has values for history bars. It is done to simplify workflow for developers and it was designed before multi timeframes indicators were introduced. For now we are not planning to change it as changing this behavior will break existing indicators. But we are keeping this in mind for our future development. 

There is an option to find index at other TimeSeries, you can use x.OpenTime.GetIndexByTime()

Best Regards,

cTrader Team


@Spotware