Category Volatility  Published on 08/05/2023

ADR Custom Indicator for cTrader

Description

Hiya! 

We have just released an innovative indicator exclusively designed for cTrader. 

Features

The ADR (Average Daily Range) indicator can:

  • Show the asset price average volatility over a certain period.
  • Compare the volatility strengths.
  • Record all the currency movements from the highest to the lowest peaks in every daily timeframe.
  • Predict price movements in intraday strategies.
  • Represent the market situation accurately.

Note! The formula adds up the price dynamics for each day of the week. It divides the received amount by the number of trading days. 

Note! All ADR values are indicated in ticks (not pips) when the text is placed vertically. While in the horizontal display, the additional arbitrary text is removed using the Label text parameter.


Parameters

We have equipped our indicator with more than 14 additional parameters. So, you can configure the indicator and customize the value display on the chart according to your needs and preferences!

Note! Try ADR on your demo account first before going live.

 

Other Products

PSAR Strategy: 

Ichimoku Strategy: 

Daily H/L Custom Indicator: 

 

Contact Info

Contact us via support@4xdev.com 

Check out our cozy Telegram blog for traders: https://t.me/Forexdev  

Visit our website to find more tools and programming services: https://bit.ly/44BFRG3

Take a look at our YouTube channel: https://www.youtube.com/channel/UChsDb4Q8X2Vl5DJ7H8PzlHQ   


Create your own trading Universe — with 4xDev.

 


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Text.RegularExpressions;
using System.Windows.Input;

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None, ScalePrecision = 1)]
    public class ADR : Indicator
    {
        private ChartText text;
        private Bars D1;
        private Color clrFont;
        private double adrValue = 0;
        private double tickOrPip;
        private int roundDecimals;
        private int objId = 0;
        private double textPosY;
        private string textAffix;
        private string textLabel;

        public enum TEXT_DIRECTION
        {
            RowPips,
            ColumnTicks
        }

        public enum LABEL_AFFIX
        {
            Prefix,
            Suffix
        }
        public enum ANCHOR_POINT
        {
            BarHigh,
            BarLow
        }

        #region ---------PARAMS---------
        [Parameter(DefaultValue = 14, MinValue = 1)]
        public int Period { get; set; }

        [Parameter("Font size", DefaultValue = 14, MinValue = 1)]
        public int FontSize { get; set; }

        [Parameter("Font color", DefaultValue = Colors.Gold)]
        public Colors FontColor { get; set; }

        [Parameter("Font direction", DefaultValue = TEXT_DIRECTION.RowPips)]
        public TEXT_DIRECTION FontDirection { get; set; }

        [Parameter("Anchor point", DefaultValue = ANCHOR_POINT.BarHigh)]
        public ANCHOR_POINT AnchorPoint { get; set; }

        [Parameter("Vertical alignment", DefaultValue = VerticalAlignment.Center)]
        public VerticalAlignment FontAlignY { get; set; }

        [Parameter("Vertical offset (pips)", DefaultValue = 10, MinValue = 0)]
        public int FontOffset { get; set; }

        [Parameter("Horizontal alignment", DefaultValue = HorizontalAlignment.Left)]
        public HorizontalAlignment FontAlignX { get; set; }

        [Parameter("Font bold", DefaultValue = true)]
        public bool FontBold { get; set; }

        [Parameter("Font italic", DefaultValue = false)]
        public bool FontItalic { get; set; }

        [Parameter("Font underlined", DefaultValue = false)]
        public bool FontUnderlined { get; set; }

        [Parameter("Font interactive", DefaultValue = false)]
        public bool FontInteractive { get; set; }

        [Parameter("Font locked", DefaultValue = false)]
        public bool FontLocked { get; set; }

        [Parameter("Font hidden", DefaultValue = false)]
        public bool FontHidden { get; set; }

        [Parameter("Label affix", DefaultValue = LABEL_AFFIX.Prefix)]
        public LABEL_AFFIX LabelAffix { get; set; }

        [Parameter("Label text", DefaultValue = " ADR ")]
        public string LabelText { get; set; }
        #endregion

        // plot
        [Output("Main", LineColor = "Gold")]
        public IndicatorDataSeries Result { get; set; }


        protected override void Initialize()
        {
            for (int i = 0; i < Chart.Objects.Count; i++)
            {
                if (Chart.Objects[i].Name.Contains("ADRobjLabel"))
                {
                    Chart.RemoveObject(Chart.Objects[i].Name);
                }
            }

            clrFont = Color.FromName(FontColor.ToString());
            D1 = MarketData.GetBars(TimeFrame.Daily);

            if (FontDirection == TEXT_DIRECTION.RowPips)
            {
                tickOrPip = Symbol.PipSize;
                roundDecimals = 1;
            }
            else
            {
                tickOrPip = Symbol.TickSize;
                roundDecimals = 0;
            }
        }

        public override void Calculate(int index)
        {
            if (index < 2)
                return;

            D1 = MarketData.GetBars(TimeFrame.Daily);
            textPosY = AnchorPoint == ANCHOR_POINT.BarHigh ? Bars[index].High + (FontOffset * Symbol.PipSize) : Bars[index].Low - (FontOffset * Symbol.PipSize);

            //int startD1 = Bars[index].OpenTime > D1[D1.Count - (Period + 1)].OpenTime ? D1.Count - (Period + 1) : Period;

            for (int i = Period; i < D1.Count; i++)
            {
                if (Bars[index - 1].OpenTime < D1[i].OpenTime && Bars[index].OpenTime >= D1[i].OpenTime)
                {
                    adrValue = Math.Round(ADRfn(i, i - Period) / tickOrPip, roundDecimals);
                    textAffix = LabelAffix == LABEL_AFFIX.Prefix ? LabelText + adrValue.ToString() : adrValue.ToString() + LabelText;
                    textLabel = FontDirection == TEXT_DIRECTION.RowPips ? textAffix : Regex.Replace(adrValue.ToString(), "(.{1})", "$1\n");

                    text = Chart.DrawText("ADRobjLabel" + objId++, textLabel, index, textPosY, clrFont);
                    text.FontSize = FontSize;
                    text.HorizontalAlignment = FontAlignX;
                    text.VerticalAlignment = FontAlignY;
                    text.IsBold = FontBold;
                    text.IsItalic = FontItalic;
                    text.IsUnderlined = FontUnderlined;
                    text.IsInteractive = FontInteractive;
                    text.IsLocked = FontLocked;
                    text.IsHidden = FontHidden;
                    //text.Comment = "Period: " + D1[i - Period].OpenTime + " - " + D1[i].OpenTime;

                    break;
                }
            }

            if (objId > 0)
            {
                text.Time = Bars[index].OpenTime;
                text.Y = textPosY;
            }
            Result[index] = adrValue;

        }

        private double ADRfn(int start, int end)
        {
            double SumRange = 0;
            for (int i = start; i > end; i--)
            {
                SumRange += D1[i].High - D1[i].Low;
            }
            return SumRange / Period;
        }
    }
}


4xDev's avatar
4xDev

Joined on 11.12.2019

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: ADR (1).algo
  • Rating: 5
  • Installs: 1543
  • Modified: 16/11/2021 12:51
Comments
Log in to add a comment.
PA
pawajes446 · 1 year ago

Thanks for this post <a href="https://www.google.com/">Google</a>