EMA from other timeframe

Created at 05 Jul 2021, 17:02
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!
CT

ctid3999979

Joined 05.07.2021

EMA from other timeframe
05 Jul 2021, 17:02


Hi

I'm new to cAlgo though have programming experience.

I'm wanting to code a bot that will check the values of 3 EMA on the 15 minute timeframe and check the stochastic on the 5 and 1 minute. I have the stochastic timeframes sorted as you can specify Bars when initializing the indicator. However, there doesn't seem to be the ability to specify the timeframe for the EMAs

I'm assuming it's possible to do this? 

        private Bars data1Min;
        private Bars data5Min;
        private Bars data15Min;

        private StochasticOscillator oneMinStochasticOscillator;
        private StochasticOscillator fiveMinStochasticOscillator;

        private MovingAverage ma1ExpMovingAverage;
        private MovingAverage ma2ExpMovingAverage;
        private MovingAverage ma3ExpMovingAverage;


        protected override void OnStart()
        {
            // Define TimeFrames for indicators
            data1Min = MarketData.GetBars(TimeFrame.Minute);
            data5Min = MarketData.GetBars(TimeFrame.Minute5);
            data15Min = MarketData.GetBars(TimeFrame.Minute15);

            // Convert Lots to Units
            volumeInUnits = Symbol.QuantityToVolumeInUnits(lotSize);

            // Initiate Stochastic indicators for 1 and 5 minute TimeFrames
            oneMinStochasticOscillator = Indicators.StochasticOscillator(data1Min, oneMinKValue, oneMinDValue, oneMinDPeriod, oneMAType);
            fiveMinStochasticOscillator = Indicators.StochasticOscillator(data5Min, fiveMinKValue, fiveMinDValue, fiveMinDPeriod, fiveMAType);

            // Initiate Exponential Moving Averages for 15 minute TimeFrame
            ma1ExpMovingAverage = Indicators.MovingAverage(Source, ma1Period, ma1Type);
            ma2ExpMovingAverage = Indicators.MovingAverage(Source, ma2Period, ma2Type);
            ma3ExpMovingAverage = Indicators.MovingAverage(Source, ma3Period, ma3Type);

 


@ctid3999979
Replies

PanagiotisCharalampous
06 Jul 2021, 08:03

Hi ctid3999979,

You are passing the wrong source to the MAs. It needs to be DataSeries, not Bars. See below

            // Initiate Exponential Moving Averages for 15 minute TimeFrame
            ma1ExpMovingAverage = Indicators.MovingAverage(data1Min.ClosePrices, ma1Period, ma1Type);
            ma2ExpMovingAverage = Indicators.MovingAverage(data5Min.ClosePrices, ma2Period, ma2Type);
            ma3ExpMovingAverage = Indicators.MovingAverage(data15Min.ClosePrices, ma3Period, ma3Type);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

ctid3999979
07 Jul 2021, 12:00

RE:

PanagiotisCharalampous said:

Hi ctid3999979,

You are passing the wrong source to the MAs. It needs to be DataSeries, not Bars. See below

            // Initiate Exponential Moving Averages for 15 minute TimeFrame
            ma1ExpMovingAverage = Indicators.MovingAverage(data1Min.ClosePrices, ma1Period, ma1Type);
            ma2ExpMovingAverage = Indicators.MovingAverage(data5Min.ClosePrices, ma2Period, ma2Type);
            ma3ExpMovingAverage = Indicators.MovingAverage(data15Min.ClosePrices, ma3Period, ma3Type);

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Thanks a lot. I knew it would be something simple.

 


@ctid3999979