Can anybody merge ADX and ATR. Please help

Created at 05 Jan 2017, 04:57
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!
Singleton's avatar

Singleton

Joined 13.04.2015

Can anybody merge ADX and ATR. Please help
05 Jan 2017, 04:57


Can anybody merge ADX and ATR? I am talking about the default indicators. I wish to see both in the same indicator window.

But I have no idea how to merge it as it requires programming to get that.

So I was wondering whether I can make a request here, since it is a very simple job for those familiar with C+ to combine indicators

 

Thank you.


@Singleton
Replies

galafrin
05 Jan 2017, 16:21

Hello, you may try this

// -------------------------------------------------------------------------------------------------
//
//    This code is a cAlgo API example.
//    
//    All changes to this file will be lost on next application start.
//    If you are going to modify this file please make a copy using the "Duplicate" command.
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AutoRescale = false, AccessRights = AccessRights.None)]
    public class SampleA : Indicator
    {
        [Parameter(DefaultValue = 14)]
        public int Periods { get; set; }

        [Parameter(DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType maType { get; set; }

        [Output("dp", Color = Colors.Lime)]
        public IndicatorDataSeries dp { get; set; }

        [Output("dm", Color = Colors.Red)]
        public IndicatorDataSeries dm { get; set; }

        [Output("ad", Color = Colors.DodgerBlue)]
        public IndicatorDataSeries ad { get; set; }

        [Output("atr", Color = Colors.Gold)]
        public IndicatorDataSeries at { get; set; }
        
        private DirectionalMovementSystem dms;
        private AverageTrueRange atr;

        protected override void Initialize()
        {

            dms = Indicators.DirectionalMovementSystem ( Periods ) ;
            atr = Indicators.AverageTrueRange ( Periods , maType) ;
        }

        public override void Calculate(int index)
        {
            dp [index] = dms.DIPlus[index];
            dm [index] = dms.DIMinus[index];
            ad [index] = dms.ADX[index];
            at [index] = atr.Result[index]/Symbol.Bid*10000;
        }
    }
}

 


@galafrin