Referencing Custom Indicator on Code

Created at 23 Jul 2020, 17:25
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!
AC

ac15x

Joined 22.07.2020

Referencing Custom Indicator on Code
23 Jul 2020, 17:25


Hi,

I installed and tried referencing this custom indicator to my code but cannot seemed to access it.

 

https://ctrader.com/algos/indicators/show/379

 

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var highLow = Indicators.HighestHigh_LowestLow();
        }
    }

    [Indicator("Highest High Lowest Low Bands", IsOverlay = true, AccessRights = AccessRights.None)]
    [Obsolete]
    public class HighestHigh_LowestLow : Indicator
    {

        [Parameter(DefaultValue = 10, MinValue = 1)]
        public int PeriodsHigh { get; set; }

        [Parameter(DefaultValue = 10, MinValue = 1)]
        public int PeriodsLow { get; set; }

        [Output("Top", Color = Colors.Red)]
        public IndicatorDataSeries Top { get; set; }

        [Output("Bottom", Color = Colors.Blue)]
        public IndicatorDataSeries Bottom { get; set; }


        public override void Calculate(int index)
        {
            Top[index] = MarketSeries.High.Maximum(PeriodsHigh);
            Bottom[index] = MarketSeries.Low.Minimum(PeriodsLow);
        }
    }


}

 


@ac15x
Replies

PanagiotisCharalampous
24 Jul 2020, 08:10

Hi ac15x,

Read here how to reference custom indicators.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

ac15x
24 Jul 2020, 15:20 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi ac15x,

Read here how to reference custom indicators.

Best Regards,

Panagiotis 

Join us on Telegram

 

Hi made sure to do this but cannot seem to make it work 

 

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        protected override void OnStart()
        {
            var indicator = Indicators.HighestHigh_LowestLow();
        }
    }

    [Indicator("Highest High Lowest Low Bands", IsOverlay = true, AccessRights = AccessRights.None)]
    public class HighestHigh_LowestLow : Indicator
    {

        [Parameter(DefaultValue = 10, MinValue = 1)]
        public int PeriodsHigh { get; set; }

        [Parameter(DefaultValue = 10, MinValue = 1)]
        public int PeriodsLow { get; set; }

        [Output("Top", LineColor  = "Red")]
        public IndicatorDataSeries Top { get; set; }

        [Output("Bottom", LineColor = "Blue")]
        public IndicatorDataSeries Bottom { get; set; }

        private HighestHigh_LowestLow _hl;
        protected override void Initialize()
        {
            _hl = Indicators.GetIndicator(PeriodsHigh, PeriodsLow, Top, Bottom);
        }

        public override void Calculate(int index)
        {
            Top[index] = Bars.HighPrices.Maximum(PeriodsHigh);
            Bottom[index] = Bars.HighPrices.Minimum(PeriodsLow);
        }
    }


}

 


@ac15x

PanagiotisCharalampous
24 Jul 2020, 15:46

Hi ac15x,

It does not seem you read the documentation. Your code doesn't make much sense. For example there is no such method. I don't know where you got this from

var indicator = Indicators.HighestHigh_LowestLow();

You can initialize the custom indicator as follows

 _hl = Indicators.GetIndicator<HighestHigh_LowestLow>(PeriodsHigh, PeriodsLow);

Also I do not understand what the indicator class is doing inside the cBot code. It should be in a separate indicator instance.

At last, you are initializing the indicator within the indicator 

        private HighestHigh_LowestLow _hl;
        protected override void Initialize()
        {
            _hl = Indicators.GetIndicator(PeriodsHigh, PeriodsLow, Top, Bottom);
        }

I do not understand why do you do it. This will probably lead to a stack overflow.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous