Problem calling custom Indicator

Created at 15 Oct 2022, 08:37
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!
MA

mark_1

Joined 15.10.2022

Problem calling custom Indicator
15 Oct 2022, 08:37


I have a very simple custom indicator with these parameters:

 

{
        [Parameter("Period", DefaultValue = 22)]
        public int Period { get; set; }

        [Parameter("Period", DefaultValue = 50)]
        public int Period1 { get; set; }

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

        [Output("Main", IsHistogram = true, PlotType = PlotType.Histogram, Thickness = 3)]
        public IndicatorDataSeries Result { get; set; }



        private ExponentialMovingAverage _ema;

        private ExponentialMovingAverage _ema1;


        protected override void Initialize()
        {
            _ema = Indicators.ExponentialMovingAverage(Source, Period);
            _ema1 = Indicators.ExponentialMovingAverage(Source, Period1);
        }

 

 

 

 

 

I have tried to call it to my algorithm with the following:

 

 

        [Parameter("Source", Group = "Difference")]
        public DataSeries Source { get; set; }

        [Parameter("DPeriod", Group = "Difference", DefaultValue = 22)]
        public int DPeriod { get; set; }

        [Parameter("DPeriod", Group = "Difference", DefaultValue = 50)]
        public int DPeriod1 { get; set; }

        [Parameter("Difference Max", Group = "Difference", DefaultValue = 0.0001)]
        public double DMAX { get; set; }

        [Parameter("Difference Min", Group = "Difference", DefaultValue = -0.0001)]
        public double DMIN { get; set; }

 

        private Difference diff;

 

          diff = Indicators.GetIndicator<Difference>(Source, DPeriod, DPeriod1);

 

(I was advised to set the same parameters In the algorithm as the indicator. If I do not do this I get an invalid parameter error)

When I set a trade condition for the indicator in my algorithm and try to backtest I get this error:

 

Crashed in OnStart with AlgoActivationException: Can not set "DataSeries (Count: 125, LastValue: 1.15019)" as a value for "Period" parameter

 

 

I have tried to set direct values of 22 and 50 in both the algorithm and indicator so as to avoid the period setting but it gives the same error, and if I then delete the period settings I get the invalid Parameter error again.


@mark_1
Replies

mark_1
15 Oct 2022, 16:21

Figured it out

I had to change the order of the parameters in the indicator and put Source at the top. For future reference for  anybody else.

 

What I am confused about is if I change the Periods in my algorithm will it automatically change the settings in the indicator?

I shall play and report...


@mark_1