Reference custom indicator

Created at 16 Feb 2019, 12: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!
JO

joshc1092

Joined 24.01.2018

Reference custom indicator
16 Feb 2019, 12:10


Hi,

I tried to reference this custom indicator "ZeroLagEMA" from spka111 (https://ctrader.com/algos/indicators/show/145)

to be used in my custom indicator "ZLMACD", but only NaN shows in my indicator.

No idea what's wrong with my indicator. (I'm a newbie coder)

Hope someone can help to point out the error in my code.

Thanks.

 

//#reference : ..\Indicators\ZeroLagEMA.algo

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = false)]
    public class ZLMACD : Indicator
    {

        private ZeroLagEMA ma1;
        private ZeroLagEMA ma2;

        [Parameter()]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 14, MinValue = 5)]
        public int X1 { get; set; }
        [Parameter(DefaultValue = 14, MinValue = 5)]
        public int X2 { get; set; }

        [Output("Main", Color = Colors.LimeGreen)]
        public IndicatorDataSeries Result { get; set; }
        [Output("Main1", Color = Colors.Red)]
        public IndicatorDataSeries Result1 { get; set; }
        [Output("Main2", Color = Colors.Yellow)]
        public IndicatorDataSeries Result2 { get; set; }

        protected override void Initialize()
        {
            ma1 = Indicators.GetIndicator<ZeroLagEMA>(Source, X1);
            ma2 = Indicators.GetIndicator<ZeroLagEMA>(Source, X2);
        }

        public override void Calculate(int index)
        {
            Result[index] = Source[index] - ma1.Result[index];
            Result1[index] = Source[index] - ma2.Result[index];
            Result2[index] = Result[index] - Result1[index];
        }
    }

@joshc1092
Replies

PanagiotisCharalampous
18 Feb 2019, 12:05

Hi joshc1092,

You have entered the parameters the wrong way round. See below the correct way

            ma1 = Indicators.GetIndicator<ZeroLagEMA>(X1, Source);
            ma2 = Indicators.GetIndicator<ZeroLagEMA>(X2, Source);

Best Regards,

Panagiotis


@PanagiotisCharalampous

joshc1092
20 Feb 2019, 18:48

Hi Panagiotis,

It works. Thanks for the help. 


@joshc1092