Indicator not picking up last day of month

Created at 18 Nov 2020, 15:27
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!
LU

lucrum

Joined 06.08.2019

Indicator not picking up last day of month
18 Nov 2020, 15:27


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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ChartDateTime : Indicator
    {
        [Output("Last Monthly H", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.LinesDots, LineColor = "Red", Thickness = 1)]
        public IndicatorDataSeries MonthlyHigh { get; set; }

        [Output("Last Monthly L", PlotType = PlotType.DiscontinuousLine, LineStyle = LineStyle.Lines, LineColor = "Red", Thickness = 1)]
        public IndicatorDataSeries MonthlyLow { get; set; }

        protected override void Initialize()
        {

        }

        public override void Calculate(int index)
        {

            var seriesMonth = MarketData.GetBars(TimeFrame.Monthly);
            MonthlyHigh[index] = seriesMonth.HighPrices[seriesMonth.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]) - 1];
            if (MonthlyHigh[index] != MonthlyHigh[index - 1])
            {
                MonthlyHigh[index - 1] = double.NaN;
            }

            MonthlyLow[index] = seriesMonth.LowPrices[seriesMonth.OpenTimes.GetIndexByTime(Bars.OpenTimes[index - 1]) - 1];
            if (MonthlyLow[index] != MonthlyLow[index - 1])
            {
                MonthlyLow[index - 1] = double.NaN;
            }

        }
    }
}

The chart is daily cable. The arrows mark those days at the end of a month where that day is included in the following month Also, I note that this occurs where a weekend does not straddle a month end. Plus, the horizontal lines do not extend across every month as intended. I would be grateful if someone could point out my coding error.

  


@lucrum