Envelopes Algo

Created at 07 May 2019, 23:18
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!
RY

ryan.a.blake

Joined 28.01.2019

Envelopes Algo
07 May 2019, 23:18


Hi, 

Been recently having trouble coding the envelopes indicator into my calgo. 

Below is the indicator code.-

using cAlgo.API;

using cAlgo.API.Indicators;

 

namespace cAlgo.Indicators

{

    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]

    public class EnvelopeChannels : Indicator

    {

        private int Period = 10;

        private MovingAverage expo;

 

 

        [Parameter(DefaultValue = 20)]

        public int EnvelopePeriod { get; set; }

 

        [Parameter(DefaultValue = 0.5)]

        public double BandDistance { get; set; }

 

        [Output("Main")]

        public IndicatorDataSeries EnvelopeMain { get; set; }

 

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

        public IndicatorDataSeries ChannelUp { get; set; }

 

        [Output("ChannelLow", Color = Colors.Blue)]

        public IndicatorDataSeries ChannelLow { get; set; }

 

        [Parameter("MAType")]

        public MovingAverageType matype { get; set; }

 

        protected override void Initialize()

        {

            expo = Indicators.MovingAverage(MarketSeries.Close, EnvelopePeriod, matype);

        }

 

        public override void Calculate(int index)

        {

            EnvelopeMain[index] = expo.Result[index];

            ChannelUp[index] = expo.Result[index] + (expo.Result[index] * BandDistance) / 100;

            ChannelLow[index] = expo.Result[index] - (expo.Result[index] * BandDistance) / 100;

        }

   

 


@ryan.a.blake
Replies

PanagiotisCharalampous
08 May 2019, 09:32

Hi ryan.a.blake,

Can you explain to us what help do you need here?

Best Regards,

Panagiotis


@PanagiotisCharalampous

ryan.a.blake
08 May 2019, 15:18

I have been having trouble coding the Envelopes indicator to automate a strategy. it is currently placed in the custom indicator section, which i can easily use the following method - env.indicator.Getindicator<Envelopes>(Period 1, Banddistance) which works, however i seem to run into problems when writing the ontick method marketseries.close > env....... How could i code this to open a trade when close is above the upper band and the lower band?

Would appreciate any suuggestions.

 

Kind regards.


@ryan.a.blake

PanagiotisCharalampous
08 May 2019, 15:30

Hi ryan.a.blake,

The indicator code does not seemd complete. Can you please share the full indicator cBot and any code you might have written till now?

Best Regards,

Panagiotis


@PanagiotisCharalampous

ryan.a.blake
08 May 2019, 15:44

Hi,

Below is something i have quickly put together based on a bollinger band algo i have found in the forum. They are similar indicator so i assume the prinicples would be the same. Would this be correct, or does it require additional coding. In terms of the parameters such as band distance and period, im aware these will need to be included which i will do in due course, but in terms of the algo placing trades based on the implementation of the indicator, have i represented that correctly.

 

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

        Envelopes _env;

 

        protected override void OnStart()

        {

            _env = Indicators.GetIndicator<Envelopes>(MarketSeries.Close, 20, 0.07);

        }

 

        protected override void OnTick()

        {

            if ((Marketseries.close > _env.Upperband.LastValue))

            {

                // Trade...

            }

        }

 

        protected override void OnStop()

        {

            // Put your deinitialization logic here

        }

    }

}


@ryan.a.blake