MACD different timeframe

Created at 03 Nov 2022, 20:15
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!
V.

v.fiodorov83

Joined 24.07.2019

MACD different timeframe
03 Nov 2022, 20:15


Hello!

I want cBot to trade on the m1 timeframe, but make calculations based on the MacdHistogram indicator with the ability to select a timeframe, for example h1


        private MacdHistogram mcd;
     
        private Bars source;



        protected override void OnStart()

        {
            
            source = MarketData.GetBars(TimeFrame.Hour, SymbolName);

            mcd = Indicators.MacdHistogram(source.ClosePrices,shortCycle, longCycle, signalPeriod);
            
        }

I did it. OK. But then, when trying to use the MASD () data in the OnBar and OnTick methods, he doesn't care, he counts by closing the bar of the current timeframe/tick. Seems I need to create some kind of "dancing with a tambourine" so that he, like, waits until 12 M5 bars are collected, for example, in order to calculate the closing price of an hourly bar?


@v.fiodorov83
Replies

Alwin123
03 Nov 2022, 22:16 ( Updated at: 03 Nov 2022, 22:17 )

RE: https://ctrader.com/forum/calgo-support/39249 have a look here

v.fiodorov83 said: 

Hello!

I want cBot to trade on the m1 timeframe, but make calculations based on the MacdHistogram indicator with the ability to select a timeframe, for example h1


        private MacdHistogram mcd;
     
        private Bars source;



        protected override void OnStart()

        {
            
            source = MarketData.GetBars(TimeFrame.Hour, SymbolName);

            mcd = Indicators.MacdHistogram(source.ClosePrices,shortCycle, longCycle, signalPeriod);
            
        }

I did it. OK. But then, when trying to use the MASD () data in the OnBar and OnTick methods, he doesn't care, he counts by closing the bar of the current timeframe/tick. Seems I need to create some kind of "dancing with a tambourine" so that he, like, waits until 12 M5 bars are collected, for example, in order to calculate the closing price of an hourly bar?

 


@Alwin123

v.fiodorov83
03 Nov 2022, 22:58

RE: RE: https://ctrader.com/forum/calgo-support/39249 have a look here

Alwin123 said:

v.fiodorov83 said: 

Hello!

I want cBot to trade on the m1 timeframe, but make calculations based on the MacdHistogram indicator with the ability to select a timeframe, for example h1


        private MacdHistogram mcd;
     
        private Bars source;



        protected override void OnStart()

        {
            
            source = MarketData.GetBars(TimeFrame.Hour, SymbolName);

            mcd = Indicators.MacdHistogram(source.ClosePrices,shortCycle, longCycle, signalPeriod);
            
        }

I did it. OK. But then, when trying to use the MASD () data in the OnBar and OnTick methods, he doesn't care, he counts by closing the bar of the current timeframe/tick. Seems I need to create some kind of "dancing with a tambourine" so that he, like, waits until 12 M5 bars are collected, for example, in order to calculate the closing price of an hourly bar?

 

Yes. I saw this post, and thats my correct code for this task here in my post - Intitialize on start. But then begins bugs which I described


@v.fiodorov83

Alwin123
03 Nov 2022, 23:08

I don't have a solution for that Sorry
I don't have a solution for that 

@Alwin123