Custom Indicator not showing present data in low time frames

Created at 17 Oct 2022, 09:48
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!
MA

mark_1

Joined 15.10.2022

Custom Indicator not showing present data in low time frames
17 Oct 2022, 09:48


Works fine in high timeframes referencing to lower timeframes, but low timeframes (1-5M) referencing higher timeframes data only appears up to a few days previous to present.

Also How do I set the different timeframes to use source instead of ClosePrices?

 

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Difference1 : Indicator
    {


        [Parameter("Source")]
        public DataSeries Source { get; set; }

        [Parameter("Period", DefaultValue = 22)]
        public int DPeriod { get; set; }

        [Parameter("Period1", DefaultValue = 50)]
        public int DPeriod1 { get; set; }

        [Parameter("MA Type", Group = "Moving Average Type")]
        public MovingAverageType MAType { get; set; }



        [Parameter("TimeFrame1", Group = "TimeFrame 1", DefaultValue = 0.02, MinValue = 0)]
        public TimeFrame TF1 { get; set; }

        [Parameter("TimeFrame2", Group = "TimeFrame 2", DefaultValue = 0.02, MinValue = 0)]
        public TimeFrame TF2 { get; set; }


        [Output("Main", IsHistogram = true, PlotType = PlotType.Histogram, Thickness = 3)]
        public IndicatorDataSeries Result { get; set; }

        [Output("TF1", IsHistogram = true, PlotType = PlotType.Histogram, Thickness = 3)]
        public IndicatorDataSeries Result1 { get; set; }

        [Output("TF2", IsHistogram = true, PlotType = PlotType.Histogram, Thickness = 3)]
        public IndicatorDataSeries Result2 { get; set; }


        public Bars Time1;
        public Bars Time2;

        public MovingAverage ma;
        public MovingAverage ma1;

        public MovingAverage mat;
        public MovingAverage ma1t;

        public MovingAverage mat2;
        public MovingAverage ma1t2;




        protected override void Initialize()
        {
            Time1 = MarketData.GetBars(TF1);
            Time2 = MarketData.GetBars(TF2);

            ma = Indicators.MovingAverage(Source, DPeriod, MAType);
            ma1 = Indicators.MovingAverage(Source, DPeriod1, MAType);

            mat = Indicators.MovingAverage(Time1.ClosePrices, DPeriod, MAType);
            ma1t = Indicators.MovingAverage(Time1.ClosePrices, DPeriod1, MAType);


            mat2 = Indicators.MovingAverage(Time2.ClosePrices, DPeriod, MAType);
            ma1t2 = Indicators.MovingAverage(Time2.ClosePrices, DPeriod1, MAType);


        }


        public override void Calculate(int index)
        {
            Result[index] = ma.Result[index] - ma1.Result[index];

            Result1[index] = mat.Result[index] - ma1t.Result[index];

            Result2[index] = mat2.Result[index] - ma1t2.Result[index];

        }
    }
}


@mark_1