Dividing two moving averages

Created at 19 Jul 2015, 09:13
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!
BBalazs's avatar

BBalazs

Joined 13.07.2015

Dividing two moving averages
19 Jul 2015, 09:13


Hi guys!

I'm having some trouble just when I thought I managed to create my indicator =/

I'm receiving the following error message when I try to divide a moving average with another one (WMA(3) / WMA(5))

"Operator "/" cannot be applied to operands of type 'c.Algo.API.Indicators.MovingAverage' and c.Algo.API.Indicators.MovingAverage'."

What can I do about the issue?

-Balazs


@BBalazs
Replies

Spotware
20 Jul 2015, 04:55

Dear Trader,

You cannot divide 2 indicators with each other in the way you described in your post.

You need to access the value of an indicator using the index at a certain period. The following example illustrates a division between two indicators.

        protected override void Initialize()
        {
            sma = Indicators.GetIndicator<SampleSMA>(Source, 10);
            sma2 = Indicators.GetIndicator<SampleSMA>(Source, 15);

        }

        public override void Calculate(int index)
        {
            refSMA[index] = sma.Result[index] / sma2.Result[index];
        }

Additionally please take a look at the following link: /api/guides/indicators

We hope this helps you.

 


@Spotware

BBalazs
02 Aug 2015, 12:07

Thank you for the answer, I managed to get it done.


@BBalazs