Using custom indicators in a cBot

Created at 28 Jul 2015, 02: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!
EN

enginedave

Joined 28.10.2013

Using custom indicators in a cBot
28 Jul 2015, 02:10


I have coded an indicator within cAlgo. I want to use this indicator within a new cBot to decide when to open a trade. How do I access the custom indicator? 


@enginedave
Replies

Spotware
28 Jul 2015, 11:38

Dear Trader,

Please have a look at Referencing Custom Indicators section of API Programmers Guides.


@Spotware

bitcoinspeak
12 Sep 2019, 08:29

RE:

Spotware said:

Dear Trader,

Please have a look at Referencing Custom Indicators section of API Programmers Guides.

I have the same problem, can you help me, how do I call the range_adr contained in the indicator into the bot, so that it becomes a Pipstep parameter in the bot.

this is the indicator code.
Thank you in advance

// -------------------------------------------------------------------------------------------------
//
//    ADR - Average Daily Range
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class myADR : Indicator
    {
        [Parameter("ADR Period", DefaultValue = 5, MinValue = 1, MaxValue = 999)]
        public int adr_period { get; set; }

        [Parameter("Color Label", DefaultValue = "Lime")]
        public string color_label_str { get; set; }

        [Parameter("Color Text", DefaultValue = "White")]
        public string color_value_str { get; set; }

        [Parameter("Timeframe Daily", DefaultValue = true)]
        public bool timeframe_daily { get; set; }


        private MarketSeries mseries;
        private Colors color_label;
        private Colors color_value;

        protected override void Initialize()
        {
            if (!Enum.TryParse(color_label_str, out color_label))
                color_label = Colors.Lime;

            if (!Enum.TryParse(color_value_str, out color_value))
                color_value = Colors.White;

            if (timeframe_daily)
                mseries = MarketData.GetSeries(TimeFrame.Daily);
            else
                mseries = MarketSeries;
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;

            int index_last = 0;
            double range_today = 0;
            double range_adr = 0;
            double range_adr_150 = 0;
            double range_adr_200 = 0;
            string tf_str = "";

            index_last = mseries.Close.Count - 1;

            range_today = (mseries.High[index_last] - mseries.Low[index_last]) * Math.Pow(10, Symbol.Digits - 1);
            range_today = Math.Round(range_today, 0);

            for (int i = index_last; i > index_last - adr_period; i--)
                range_adr += (mseries.High[i] - mseries.Low[i]) * Math.Pow(10, Symbol.Digits - 1);

            range_adr /= adr_period;
            range_adr = Math.Round(range_adr, 0);

            range_adr_150 = range_adr * 1.5;
            range_adr_150 = Math.Round(range_adr_150, 0);

            range_adr_200 = range_adr * 2.0;
            range_adr_200 = Math.Round(range_adr_200, 0);

            tf_str = mseries.TimeFrame.ToString();

            ChartObjects.DrawText("RLabels", "R" + tf_str + "\n" + "RAvg" + adr_period + "\n" + "R150" + "\n" + "R200", StaticPosition.BottomLeft, color_label);
            ChartObjects.DrawText("RValues", "\t" + range_today + "\n\t" + range_adr + "\n\t" + range_adr_150 + "\n\t" + range_adr_200, StaticPosition.BottomLeft, color_value);
        }
    }
}

 


@bitcoinspeak

PanagiotisCharalampous
12 Sep 2019, 09:05

Hi indra,

Thanks for posting in our forum. The indicator does not have any output series that can be accessed by a cBot. You will need to add an  IndicatorDataSeries and save the range_adr value there, so that it can be accessed by a cBot.

Best Regards,

Panagiotis


@PanagiotisCharalampous

bitcoinspeak
13 Sep 2019, 21:29

RE:

Panagiotis Charalampous said:

Hi indra,

Thanks for posting in our forum. The indicator does not have any output series that can be accessed by a cBot. You will need to add an  IndicatorDataSeries and save the range_adr value there, so that it can be accessed by a cBot.

Best Regards,

Panagiotis

hi Panagiotis
thank you for your answer, can you help me, what syntax should I input into the indicator and the cbot? because I'm still learning the C # language, and haven't fully understood it.

Thank you 


@bitcoinspeak

PanagiotisCharalampous
16 Sep 2019, 08:56

Hi indra,

To add an IndicatorDataSeries you can use the syntax below

        [Output("Range ADR", Color = Colors.Lime, Thickness = 1)]
        public IndicatorDataSeries Range_ADR { get; set; }

However from what I see you cannot just add it and use it on the existing indicator as there are a lot of changes that need to take place. It would be better to rewrite it from scratch. If you need assistance, you can consider contacting a Consultant.

Best Regards,

Panagiotis


@PanagiotisCharalampous

desmaster236
27 Feb 2022, 18:54

RE: Access Custom Indicator outputs

PanagiotisCharalampous said:

Hi indra,

To add an IndicatorDataSeries you can use the syntax below

        [Output("Range ADR", Color = Colors.Lime, Thickness = 1)]
        public IndicatorDataSeries Range_ADR { get; set; }

However from what I see you cannot just add it and use it on the existing indicator as there are a lot of changes that need to take place. It would be better to rewrite it from scratch. If you need assistance, you can consider contacting a Consultant.

Best Regards,

Panagiotis

Hi Dear Panagiotis,

I have the same problem, Accessing custom indicator outputs within a cBot.

while i have used some outputs in my indicator.

please help me why i haven't access to my indicator outputs from my cBot.

Regards.


@desmaster236

amusleh
28 Feb 2022, 08:55

RE: RE: Access Custom Indicator outputs

desmaster236 said:

Hi Dear Panagiotis,

I have the same problem, Accessing custom indicator outputs within a cBot.

while i have used some outputs in my indicator.

please help me why i haven't access to my indicator outputs from my cBot.

Regards.

Hi,

You can use custom indicators on your cBot, you have to reference it then you will be able to create an instance of it inside your cBot and access it's public members.

Please follow this guide: https://help.ctrader.com/ctrader-automate/guides/indicators#referencing-custom-indicators


@amusleh

desmaster236
13 Nov 2022, 11:20

RE: RE: RE: Access Custom Indicator outputs

amusleh said:

desmaster236 said:

Hi Dear Panagiotis,

I have the same problem, Accessing custom indicator outputs within a cBot.

while i have used some outputs in my indicator.

please help me why i haven't access to my indicator outputs from my cBot.

Regards.

Hi,

You can use custom indicators on your cBot, you have to reference it then you will be able to create an instance of it inside your cBot and access it's public members.

Please follow this guide: https://help.ctrader.com/ctrader-automate/guides/indicators#referencing-custom-indicators

Thanks amusleh,

it was solved.

Regards


@desmaster236

cortimigliafabio
20 Mar 2023, 16:12

Referencing Custom Indicator

Hello, I apologize in advance if this is the wrong section or for any answer already available on the forum that I missed. I have a technical problem that I can't solve. I understood that in order to reference a custom Indicator within a cBot it is necessary to check the relative box in 'Manage References'. The problem manifests itself when I compile the code, the compilation hangs. If this helps the solution, when I compile from Visual Studio I get the error 'NU1108 Cycle detected'.
I would really appreciate any suggestions, thanks.


@cortimigliafabio

PanagiotisChar
21 Mar 2023, 08:24

RE: Referencing Custom Indicator

cortimigliafabio said:

Hello, I apologize in advance if this is the wrong section or for any answer already available on the forum that I missed. I have a technical problem that I can't solve. I understood that in order to reference a custom Indicator within a cBot it is necessary to check the relative box in 'Manage References'. The problem manifests itself when I compile the code, the compilation hangs. If this helps the solution, when I compile from Visual Studio I get the error 'NU1108 Cycle detected'.
I would really appreciate any suggestions, thanks.

Hi there,

In order to help you further, you need to provide us the source code of the indicator and cBot, as well as some screenshots of the error message.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

cortimigliafabio
21 Mar 2023, 09:58

Using custom indicators in a cBot

Hello, luckily I fixed it. If this helps others, the problem was that I had naively set references on some custom indexes and then duplicated the robot for testing and this caused a compiling blocking loop.
Once all the references were removed, the compilation started working perfectly again.
Thanks anyway for the assistance.


@cortimigliafabio