How to use/ref an indicator in a cBOT

Created at 25 May 2015, 07:44
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!
DA

davidp13

Joined 06.05.2014

How to use/ref an indicator in a cBOT
25 May 2015, 07:44


Hi. How will one use the following indicator in a cBot to build a cross-over strategy? I know you can use the 'Manage Ref' function, but how to I get the values of Result and Lag in order to test the cross?

using cAlgo.API;
 
namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    [Levels(0.0)]
    public class TrendIndicator : Indicator
    {
        [Parameter]
        public DataSeries Source { get; set; }
 
        [Parameter(DefaultValue = 0.07)]
        public double Alpha { get; set; }
 
        [Output("Main", Color = Colors.Red)]
        public IndicatorDataSeries Result { get; set; }
 
        [Output("Lag", Color = Colors.Turquoise)]
        public IndicatorDataSeries Lag { get; set; }
 
        public override void Calculate(int index)
        {
            if (index < 3)
                Result[index] = Source[index];
            else
            {
                if (index < 7)
                    Result[index] = (Source[index] - 2*Source[index - 1] + Source[index - 2])/4;
                else
                    Result[index] = (Alpha - Alpha*Alpha/4)*Source[index]
                                    + Alpha*Alpha*Source[index - 1]/2
                                    - (Alpha - 0.75*Alpha*Alpha)*Source[index - 2]
                                    + 2*(1 - Alpha)*Result[index - 1]
                                    - (1 - Alpha)*(1 - Alpha)*Result[index - 2];
 
                Lag[index] = 2*Result[index] - Result[index - 2];
            }
        }
    }
}

 

Thanks


@davidp13
Replies

davidp13
27 May 2015, 15:24

Anyone to help me pls?


@davidp13

mindbreaker
27 May 2015, 15:30

RE:

davidp13 said:

Anyone to help me pls?

Hi, look at this how use custom indicator and get his values :

https://github.com/breakermind/cAlgoRobotsIndicators/blob/master/Regression2000


@mindbreaker

mindbreaker
27 May 2015, 15:34

And in regression indicator there is https://github.com/breakermind/cAlgoRobotsIndicators/blob/master/Regression2000.Indicator:

Have this values: sql sqh You can use it in cBot

        [Parameter(DefaultValue = 3.0, MinValue = 1, MaxValue = 4)]
        public int degree { get; set; }
 
        [Parameter(DefaultValue = 2000)]
        public int period { get; set; }
 
        [Parameter(DefaultValue = 1.7)]
        public double strdDev { get; set; }
 
        [Output("PRC", Color = Colors.Gray, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries prc { get; set; }
 
        [Output("SQH", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries sqh { get; set; }
 
        [Output("SQL", Color = Colors.DodgerBlue, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries sql { get; set; }

 


@mindbreaker

mindbreaker
27 May 2015, 15:36

RE:

mindbreaker said:

And in regression indicator there is https://github.com/breakermind/cAlgoRobotsIndicators/blob/master/Regression2000.Indicator:

Have this values: sql sqh You can use it in cBot

        [Parameter(DefaultValue = 3.0, MinValue = 1, MaxValue = 4)]
        public int degree { get; set; }
 
        [Parameter(DefaultValue = 2000)]
        public int period { get; set; }
 
        [Parameter(DefaultValue = 1.7)]
        public double strdDev { get; set; }
 
        [Output("PRC", Color = Colors.Gray, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries prc { get; set; }
 
        [Output("SQH", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries sqh { get; set; }
 
        [Output("SQL", Color = Colors.DodgerBlue, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries sql { get; set; }

 

 

in cBot

        protected override void OnStart()
        {

            //How to Use custom indicator
            cog = Indicators.GetIndicator<Regression>(RegDegree, RegPeriod, RegStrdDev);
        }
 
        protected override void OnTick()
        {
            double up = cog.sqh.LastValue;
            double zero = cog.prc.LastValue;
            double dn = cog.sql.LastValue;
}

 


@mindbreaker

jani
28 Oct 2019, 15:17

RE: RE:

mindbreaker said:

mindbreaker said:

And in regression indicator there is https://github.com/breakermind/cAlgoRobotsIndicators/blob/master/Regression2000.Indicator:

Have this values: sql sqh You can use it in cBot

        [Parameter(DefaultValue = 3.0, MinValue = 1, MaxValue = 4)]
        public int degree { get; set; }
 
        [Parameter(DefaultValue = 2000)]
        public int period { get; set; }
 
        [Parameter(DefaultValue = 1.7)]
        public double strdDev { get; set; }
 
        [Output("PRC", Color = Colors.Gray, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries prc { get; set; }
 
        [Output("SQH", Color = Colors.Red, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries sqh { get; set; }
 
        [Output("SQL", Color = Colors.DodgerBlue, LineStyle = LineStyle.Lines)]
        public IndicatorDataSeries sql { get; set; }

 

 

in cBot

        protected override void OnStart()
        {

            //How to Use custom indicator
            cog = Indicators.GetIndicator<Regression>(RegDegree, RegPeriod, RegStrdDev);
        }
 
        protected override void OnTick()
        {
            double up = cog.sqh.LastValue;
            double zero = cog.prc.LastValue;
            double dn = cog.sql.LastValue;
}

 

Thank you so much for this info!  

The cAlgo API guide has pretty much neglected the custom indicator cBot referencing.  


@jani