How to get source for MA in different time frame?

Created at 21 Feb 2021, 16:10
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!
FI

firemyst

Joined 26.03.2019

How to get source for MA in different time frame?
21 Feb 2021, 16:10


Hello @Spotware / @Panagiotis / Anyone:

I want to be able to allow the user to select the source (high, low, open, close) for their EMA that's in a different time frame.


        [Parameter()]
        public TimeFrame SourceTimeFrame { get; set; }

        [Parameter("Fast Period", Group = "Fast MA", DefaultValue = 55, MinValue = 1)]
        public int MAFastPeriod { get; set; }
        [Parameter("Fast Type", Group = "Fast MA", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MAFastType { get; set; }
        [Parameter("Fast Source", Group = "Fast MA")]
        public DataSeries MAFastSource { get; set; }

private Bars _marketSeries;
private MovingAverage _movingAverageFast;

        protected override void Initialize()
        {
            _marketSeries = MarketData.GetBars(SourceTimeFrame, Symbol.Name);


//this is the part that is giving me trouble. How do I set the _marketSeries.HighPrices,
// .ClosePrices, .LowPrices, .OpenPrices to whatever the user selects as the source 
//from above?
//Right now, it's just coded as ".ClosePrices" as you can see below.
            _movingAverageFast = Indicators.MovingAverage(_marketSeries.ClosePrices, MAFastPeriod, MAFastType);

}

 

Thank you.

 

 


@firemyst
Replies

PanagiotisCharalampous
22 Feb 2021, 08:22

Hi firemyst,

You can create a custom enum and then a method that would return the respective data source.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

firemyst
22 Feb 2021, 08:55

RE:

PanagiotisCharalampous said:

Hi firemyst,

You can create a custom enum and then a method that would return the respective data source.

Best Regards,

Panagiotis 

Join us on Telegram

Thank you @Panagiotis.

I was hoping I wouldn't have to do that though, because in the future I might want other sources to be other indicators that are on the chart. Currently, the source let's us select those and it changes dynamically depending on the indicators on the screen. I was hoping there would be a similar, easy way with the MTF approach.


@firemyst