Offset indicator

Created at 29 Jul 2019, 22:40
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!
HU

hugo_carpegianny

Joined 11.05.2019

Offset indicator
29 Jul 2019, 22:40


hello traders. How do I plot a 3-period exponential moving average indicator with a 3-offset? I am grateful


@hugo_carpegianny
Replies

PanagiotisCharalampous
30 Jul 2019, 09:16

Hi Hugo,

See an example below

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        [Parameter(DefaultValue = 1)]
        public int Offset { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        ExponentialMovingAverage _ema;
        protected override void Initialize()
        {
            _ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 14);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            Result[index + Offset] = _ema.Result[index];
        }
    }
}

Best Regards,

Panagiotis


@PanagiotisCharalampous

hugo_carpegianny
30 Jul 2019, 13:03

RE:

Panagiotis Charalampous said:

Hi Hugo,

See an example below

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

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewIndicator : Indicator
    {
        [Parameter(DefaultValue = 1)]
        public int Offset { get; set; }

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

        ExponentialMovingAverage _ema;
        protected override void Initialize()
        {
            _ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 14);
        }

        public override void Calculate(int index)
        {
            // Calculate value at specified index
            Result[index + Offset] = _ema.Result[index];
        }
    }
}

Best Regards,

Panagiotis

 

 

ow, thank you very much. It worked, but it has 14 periods. How do I put with 3 periods?

gratitude

 


@hugo_carpegianny

PanagiotisCharalampous
30 Jul 2019, 15:14

Hi Hugo,

Change the line below

_ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 14);

to

_ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 3);

Best Regards,

Panagiotis


@PanagiotisCharalampous

hugo_carpegianny
30 Jul 2019, 16:10

Panagiots

got it. thank you very much


@hugo_carpegianny

hugo_carpegianny
30 Jul 2019, 16:11

RE:

Panagiotis Charalampous said:

Hi Hugo,

Change the line below

_ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 14);

to

_ema = Indicators.ExponentialMovingAverage(MarketSeries.Close, 3);

Best Regards,

Panagiotis

got it. thank you very much

 


@hugo_carpegianny