Can anybody merge ADX and ATR. Please help

05 Jan 2017, 04:57Can anybody merge ADX and ATR. Please help#1
Singletonposts: 9since: 13 Apr 2015

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.

05 Jan 2017, 16:21#2
galafrinposts: 76since: 26 Jan 2013

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