MA of different time frame is not displayed

Created at 29 May 2020, 22:34
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!
yomm0401's avatar

yomm0401

Joined 11.04.2020

MA of different time frame is not displayed
29 May 2020, 22:34


MA of different time frame is not displayed as in the below image.

What is wrong?

This is my code.

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 testMA : Indicator
    {

        [Parameter("Color", DefaultValue = "Blue")]
        public string color { get; set; }

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

        [Parameter("Period", DefaultValue = 10, MinValue = 1)]
        public int _Period { get; set; }

        [Parameter("Time Frame MA", DefaultValue = "Minute15")]
        public TimeFrame timeFrame { get; set; }

        [Output("ma", LineColor = "Green", PlotType = PlotType.Line, Thickness = 1)]
        public IndicatorDataSeries MA { get; set; }

        public Bars _Series;

        public MovingAverage _MA;

        protected override void Initialize()
        {
            if (timeFrame == Bars.TimeFrame)
            {
                _Series = Bars;


                _MA = Indicators.MovingAverage(Bars.ClosePrices, _Period, maType);
            }
            else
            {
                _Series = MarketData.GetBars(timeFrame);

                _MA = Indicators.MovingAverage(_Series.ClosePrices, _Period, maType);
            }
        }

        public override void Calculate(int index)
        {

            var _Index = _Series.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);

            if (_Index == -1)
            {
                return;
            }
            if (Bars.OpenTimes[index] == _Series.OpenTimes[_Index])
            {

                MA[index] = _MA.Result[_Index];
            }

        }
    }
}


@yomm0401
Replies

firemyst
30 May 2020, 12:39

I'm not sure what you're expecting to see?

When I load up your indicator on an M5 chart, and select the timeframe to be M15, it shows. When I change it from M15 to M5, they overlap.

When I change the chart to M15 chart, and put the timeframe on M5, they both show as they should. When I set them both to M15 on the M15 chart, they both overlap.

 

??


@firemyst

yomm0401
30 May 2020, 15:26

RE:

firemyst said:

I'm not sure what you're expecting to see?

When I load up your indicator on an M5 chart, and select the timeframe to be M15, it shows. When I change it from M15 to M5, they overlap.

When I change the chart to M15 chart, and put the timeframe on M5, they both show as they should. When I set them both to M15 on the M15 chart, they both overlap.

 

??

 

Thank you very much for your quick response.

If the MA of the 15-minute time frame is displayed on the 5-minute chart, the MA will be displayed from the middle when you look at the past charts.

In that case, change the chart to the 15-minute bar, scroll to the past data, return to the 5-minute bar chart and scroll to the past data, and it will be displayed.
I was able to confirm it. Thank you very much.

The problem I want to solve is whether I can update the MA when I look at the historical data in the 5-minute chart without changing the chart to the 15-minute chart.

Does the data of different time frame have to be read only after changing to the specified time frame chart?

 


@yomm0401