Custom indicator referencing in cbot

Created at 10 Nov 2021, 14:50
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!
KO

kojomidoji

Joined 13.10.2021

Custom indicator referencing in cbot
10 Nov 2021, 14:50


I have  two custom indicator am currently using to build my cbot, i applied all the steps shown in the API documents here https://help.ctrader.com/ctrader-automate/guides/indicators#referencing-custom-indicators  but unfortunately am still not able to get values from the indicator in the bot.

Someone told me there are no value in my indicator to return in the cbot but he was not able to tell me more about such values.

Please find link to my indicator below and kindly advise me how to go about it: i have also sent messages to all the consultants about this but have never received any feedback since.

 

 

 


@kojomidoji
Replies

PanagiotisCharalampous
10 Nov 2021, 14:59

Hi kojomidoji,

Please share your cBot's code so that we can have a look. 

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

kojomidoji
10 Nov 2021, 16:38

RE:

Hello Panagiotis,

I have already added links to the codes in my previous message. The complete codes are in there

 

 

PanagiotisCharalampous said:

Hi kojomidoji,

Please share your cBot's code so that we can have a look. 

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 


@kojomidoji

... Deleted by UFO ...

PanagiotisCharalampous
10 Nov 2021, 16:44

Hi kojomidoji,

The links provide the code for the indicator. We need your cBot's code as well.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

kojomidoji
12 Nov 2021, 08:58

RE:

PanagiotisCharalampous said:

Hi kojomidoji,

The links provide the code for the indicator. We need your cBot's code as well.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

 

Hello Panagiostis,

Please see below my codes which is essentially pseudo codes please help me with the correct codes , meanwhile i have also attached or added the indicator for the %b :

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 BollingerBandsSqueeze_Breakout : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private BollingerBandsSqueezeAndBreakout bbsb;
        private BollingerBandsPercentB bbpb



        protected override void OnStart()
        {
            // Put your initialization logic here
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(10, 2, MovingAverageType.Simple, 20);
            
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(HighLowPeriod)
            
            bbpb = Indicators.GetIndicator<BollingerBandsPercentB>(perid, k, MaType);
            
            //no values returns when the indicator variables are typed followed by a dot as shown in below:
            bbsb.
            bbpb.

            
        }
        public override void Calculate(int index) 
        {
        highLow[index] = 
        
        }

        protected override void OnTick()
        {
            // Put your core logic here
            bandwidthblue= bbsb.bandwith.lastvalue();
            lowred= bbsb.low.lastvalue(); //squeeze
            highgreen= bbsb.high.lastvalue(); //Bulge
            
            resultB = bbpb.result.lastvalue(); //Outbreak direction
            
            //Signal generation
            if bandwidthblue touch lowred Then Buy
            
            if bandwidthblue touch highgreen And
              If resultB equals or greater than 1 Sell 
              Else 
              If resultB equals or less than 0  then Reverse trade //take oppsite trade
              
             
            
            
            
            
            
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


@kojomidoji

PanagiotisCharalampous
12 Nov 2021, 09:02

Hi kojomidoji,

So you do not have a code and you need a sample on how to reference the indicators?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

kojomidoji
12 Nov 2021, 09:04

%b indicator

 

using System;

using cAlgo.API;

using cAlgo.API.Internals;

using cAlgo.API.Indicators;

 

namespace cAlgo.Indicators

{

    [Levels(0, 0.5, 1)]

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    public class BollingerBandsPercentB : Indicator

    {

        [Parameter()]

        public DataSeries Price { get; set; }

 

        [Parameter("Period", DefaultValue = 20)]

        public int Period { get; set; }

 

        [Parameter("Std Dev", DefaultValue = 2)]

        public double K { get; set; }

 

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]

        public MovingAverageType MaType { get; set; }

 

        [Output("Main", Color = Colors.Red)]

        public IndicatorDataSeries Result { get; set; }

 

 

        private MovingAverage _movingAverage;

        private StandardDeviation _standardDeviation;

 

        private IndicatorDataSeries middleBB;

        private IndicatorDataSeries volatility;

        private IndicatorDataSeries upperBB;

        private IndicatorDataSeries lowerBB;

 

 

        protected override void Initialize()

        {

            _movingAverage = Indicators.MovingAverage(Price, Period, MaType);

            _standardDeviation = Indicators.StandardDeviation(Price, Period, MaType);

 

            middleBB = CreateDataSeries();

            volatility = CreateDataSeries();

            upperBB = CreateDataSeries();

            lowerBB = CreateDataSeries();

        }

 

        public override void Calculate(int index)

        {

            middleBB[index] = _movingAverage.Result[index];

            volatility[index] = _standardDeviation.Result[index];

            upperBB[index] = middleBB[index] + K * volatility[index];

            lowerBB[index] = middleBB[index] - K * volatility[index];

 

            Result[index] = (MarketSeries.Close[index] - lowerBB[index]) / (upperBB[index] - lowerBB[index]);

        }

 

    }

}

Comments


@kojomidoji

kojomidoji
13 Nov 2021, 10:24

RE: %b indicator

kojomidoji said:

 

using System;

using cAlgo.API;

using cAlgo.API.Internals;

using cAlgo.API.Indicators;

 

namespace cAlgo.Indicators

{

    [Levels(0, 0.5, 1)]

    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]

    public class BollingerBandsPercentB : Indicator

    {

        [Parameter()]

        public DataSeries Price { get; set; }

 

        [Parameter("Period", DefaultValue = 20)]

        public int Period { get; set; }

 

        [Parameter("Std Dev", DefaultValue = 2)]

        public double K { get; set; }

 

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]

        public MovingAverageType MaType { get; set; }

 

        [Output("Main", Color = Colors.Red)]

        public IndicatorDataSeries Result { get; set; }

 

 

        private MovingAverage _movingAverage;

        private StandardDeviation _standardDeviation;

 

        private IndicatorDataSeries middleBB;

        private IndicatorDataSeries volatility;

        private IndicatorDataSeries upperBB;

        private IndicatorDataSeries lowerBB;

 

 

        protected override void Initialize()

        {

            _movingAverage = Indicators.MovingAverage(Price, Period, MaType);

            _standardDeviation = Indicators.StandardDeviation(Price, Period, MaType);

 

            middleBB = CreateDataSeries();

            volatility = CreateDataSeries();

            upperBB = CreateDataSeries();

            lowerBB = CreateDataSeries();

        }

 

        public override void Calculate(int index)

        {

            middleBB[index] = _movingAverage.Result[index];

            volatility[index] = _standardDeviation.Result[index];

            upperBB[index] = middleBB[index] + K * volatility[index];

            lowerBB[index] = middleBB[index] - K * volatility[index];

 

            Result[index] = (MarketSeries.Close[index] - lowerBB[index]) / (upperBB[index] - lowerBB[index]);

        }

 

    }

}

Comments

 

Hello any feedback on this issues please 


@kojomidoji

PanagiotisCharalampous
13 Nov 2021, 17:51

Hi kojomidoji,

You did not reply to my question. Can you reply please?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

kojomidoji
15 Nov 2021, 05:00

RE:

PanagiotisCharalampous said:

Hi kojomidoji,

You did not reply to my question. Can you reply please?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

Hello Panagiostis,

Please see below my codes which is essentially pseudo codes please help me with the correct codes , meanwhile i have also attached or added the indicator for the %b :

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 BollingerBandsSqueeze_Breakout : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private BollingerBandsSqueezeAndBreakout bbsb;
        private BollingerBandsPercentB bbpb



        protected override void OnStart()
        {
            // Put your initialization logic here
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(10, 2, MovingAverageType.Simple, 20);
            
            bbsb = Indicators.GetIndicator<BollingerBandsSqueezeAndBreakout>(HighLowPeriod)
            
            bbpb = Indicators.GetIndicator<BollingerBandsPercentB>(perid, k, MaType);
            
            //no values returns when the indicator variables are typed followed by a dot as shown in below:
            bbsb.
            bbpb.

            
        }
        public override void Calculate(int index) 
        {
        highLow[index] = 
        
        }

        protected override void OnTick()
        {
            // Put your core logic here
            bandwidthblue= bbsb.bandwith.lastvalue();
            lowred= bbsb.low.lastvalue(); //squeeze
            highgreen= bbsb.high.lastvalue(); //Bulge
            
            resultB = bbpb.result.lastvalue(); //Outbreak direction
            
            //Signal generation
            if bandwidthblue touch lowred Then Buy
            
            if bandwidthblue touch highgreen And
              If resultB equals or greater than 1 Sell 
              Else 
              If resultB equals or less than 0  then Reverse trade //take oppsite trade
              
          
            
        
            
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


@kojomidoji

PanagiotisCharalampous
15 Nov 2021, 08:45

Hi kojomidoji,

Unfortunately I cannot build the entire code for you but below you can find a small example of how to call the Bollinger Bandwidth - Squeeze and Bulge indicator and print the last value to the log.

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; }

        BBSqueezeBulge _bb;
        protected override void OnStart()
        {
            // Put your initialization logic here
            _bb = Indicators.GetIndicator<BBSqueezeBulge>(10, 2, MovingAverageType.Simple, 20, Bars.ClosePrices);
            Print(_bb.Bandwidth.LastValue);
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous