Indicator showing other timeframe indicator

Created at 19 Oct 2020, 12:54
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!
NO

Nobody

Joined 14.01.2016

Indicator showing other timeframe indicator
19 Oct 2020, 12:54


Hello,

i am trying to create an indicator (bollingers bands) showing an other timeframe bollingers bands values (in my case, charts is 5mn timeframe and indicator should show bollingers UT1h timeframe) but nothing is shown ( bollingers are shown only if indicator timeframe > charts timeframe)...but i can not find where is my mistake, could you help me to solve it please ?

 

thanks in advance,

 

Here the code :

 

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class BollingerOtherTimeFrame : Indicator
    {
        private Bars ms2;
        private BollingerBands boll_ms2;

        //SIGNAL SETTINGS
        [Parameter("Boll Timeframe")]
        public TimeFrame _ms2_timeframe { get; set; }

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

        [Parameter("SD Weight Coef", DefaultValue = 2)]
        public int K { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }


        //2nd timeframe Bollingers
        [Output("Boll Top UT2", LineColor = "White", Thickness = 2, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries BollTopUT2 { get; set; }

        [Output("Boll Bottom UT2", LineColor = "White", Thickness = 2, PlotType = PlotType.DiscontinuousLine)]
        public IndicatorDataSeries BollBottomUT2 { get; set; }



        protected override void Initialize()
        {
            ms2 = MarketData.GetBars(_ms2_timeframe);
            boll_ms2 = Indicators.BollingerBands(ms2.ClosePrices, Period, K, MaType);
        }

        public override void Calculate(int index)
        {

            //UT2
            BollTopUT2[index] = boll_ms2.Top[ms2.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index])];
            BollBottomUT2[index] = boll_ms2.Bottom[ms2.OpenTimes.GetIndexByExactTime(Bars.OpenTimes[index])];

        }
    }
}


@Nobody
Replies

genappsforex
19 Oct 2020, 20:18

RE:

maybe use the ms2 index? youre using the Bars index.
find the index corresponding with the Bars.OpenTimes[index] and you're OK

 


@genappsforex

PanagiotisCharalampous
20 Oct 2020, 08:53

Hi Nobody,

Try using GetIndexByTime() instead.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

Nobody
20 Oct 2020, 10:54

RE:

PanagiotisCharalampous said:

Hi Nobody,

Try using GetIndexByTime() instead.

Best Regards,

Panagiotis 

Join us on Telegram

Thanks Panagiotis, it works fine !


@Nobody

Nobody
20 Oct 2020, 10:57

RE: RE:

genappsforex said:

maybe use the ms2 index? youre using the Bars index.
find the index corresponding with the Bars.OpenTimes[index] and you're OK

 

Thannk you Genappsforex, but it is exactly what i have done, it is the "GetIndexByExactTime" that was not the proper way, it is ok with GetIndexByTime() !


@Nobody