Category Trend  Published on 16/01/2015

ADR - Average Daily Range

Description

Hi all.

Here an indicator to print the average daily range just as a number (+ current range of today, adr + 50%, adr + 100%).

Update: Made it a bit more user friendly, by adding some more parameters (switch for daily timeframe/current timeframe and customizable colors). Personally I only need daily ranges and like the default colors. But perhaps someone else wants to see these ranges on other timeframes and/or wants to change the colors, because of a bright background...

Cheers, Dirk

 


// -------------------------------------------------------------------------------------------------
//
//    ADR - Average Daily Range
//
// -------------------------------------------------------------------------------------------------

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class myADR : Indicator
    {
        [Parameter("ADR Period", DefaultValue = 5, MinValue = 1, MaxValue = 999)]
        public int adr_period { get; set; }

        [Parameter("Color Label", DefaultValue = "Lime")]
        public string color_label_str { get; set; }

        [Parameter("Color Text", DefaultValue = "White")]
        public string color_value_str { get; set; }

        [Parameter("Timeframe Daily", DefaultValue = true)]
        public bool timeframe_daily { get; set; }

        private MarketSeries mseries;
        private Colors color_label;
        private Colors color_value;

        protected override void Initialize()
        {
            if (!Enum.TryParse(color_label_str, out color_label))
                color_label = Colors.Lime;

            if (!Enum.TryParse(color_value_str, out color_value))
                color_value = Colors.White;

            if (timeframe_daily)
                mseries = MarketData.GetSeries(TimeFrame.Daily);
            else
                mseries = MarketSeries;
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;

            int index_last = 0;
            double range_today = 0;
            double range_adr = 0;
            double range_adr_150 = 0;
            double range_adr_200 = 0;
            string tf_str = "";

            index_last = mseries.Close.Count - 1;

            range_today = (mseries.High[index_last] - mseries.Low[index_last]) * Math.Pow(10, Symbol.Digits - 1);
            range_today = Math.Round(range_today, 0);

            for (int i = index_last; i > index_last - adr_period; i--)
                range_adr += (mseries.High[i] - mseries.Low[i]) * Math.Pow(10, Symbol.Digits - 1);

            range_adr /= adr_period;
            range_adr = Math.Round(range_adr, 0);

            range_adr_150 = range_adr * 1.5;
            range_adr_150 = Math.Round(range_adr_150, 0);

            range_adr_200 = range_adr * 2.0;
            range_adr_200 = Math.Round(range_adr_200, 0);

            tf_str = mseries.TimeFrame.ToString();

            ChartObjects.DrawText("RLabels", "R" + tf_str + "\n" + "RAvg" + adr_period + "\n" + "R150" + "\n" + "R200", StaticPosition.TopLeft, color_label);
            ChartObjects.DrawText("RValues", "\t" + range_today + "\n\t" + range_adr + "\n\t" + range_adr_150 + "\n\t" + range_adr_200, StaticPosition.TopLeft, color_value);
        }
    }
}


DI
diran76

Joined on 05.12.2014

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: myADR.algo
  • Rating: 5
  • Installs: 9066
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
PR
PRIVATE · 6 years ago

Hey Dirk, killer indicator.!!!

 

How hard would it be to add % change from prev day (+Green/-Red) +

possibly % change from prev day week against the prev weekly ave.?  :D

ZU
zumzum · 8 years ago

Hi Dirk,

thanks for sharing.

One idea, put the range_adr, range_adr_150 and range_adr_200 calculation into the Initialise function otherwise there is a lot of unnecessary calculation on each tick.

Cheers

HE
hedgehog · 8 years ago

I got it! 

HE
hedgehog · 8 years ago
Hello Dirk, great work. I would like to add to your indicator another one info - H/L range of last closed candle. In daily range "yesterday candle". Can you help me how to code this. Thanks
DI
diran76 · 8 years ago

Hi Ian, please change it to 'Black'.

http://ctrader.com/api/reference/colors - for further color names.

Regards, Dirk

 

I.
i.oldham · 8 years ago

Hi Dirk

Great indicator. I can not change the colour. I use a white back and do not seem able to chane the setting to black.

I'm I doing somthing wrong?

regards

Ian

DI
diran76 · 9 years ago

You're welcome... I've added some further parameters, so it's a bit more customizable without editing it with the cAlgo environment.

KE
kechel · 9 years ago

Thanks Dirk, thumbs up.