Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Average Daily Range (ADR) #1250

Open
bobtabor opened this issue Sep 12, 2024 · 1 comment
Open

Average Daily Range (ADR) #1250

bobtabor opened this issue Sep 12, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@bobtabor
Copy link

bobtabor commented Sep 12, 2024

the problem

The library contains ATR (Average True Range). The ADR (Average Daily Range) has been popularized recently by popular trader Qullamaggie (Kristjan Kullamägi ... https://qullamaggie.com/). The formula and intent is slightly different -- ATR captures movement with pre-market gaps, but ADR captures intraday only and is used by swing traders (and maybe day traders) to decide if there's enough movement in the stock to warrant taking a position.

See: https://www.alpharithms.com/average-daily-range-adr-090415/

I was able to ask ChatGPT for an implementation, but I have no confidence in the algorithm.

an idea

No response

code example

public static decimal CalculateDailyRangePercentage(Daily day)
        {
            return ((day.High - day.Low) / day.Close) * 100;
        }

        public static decimal CalculateAverageDailyRangePercentage(List<Daily> data, int period = 20)
        {
            List<decimal> dailyRangePercentages = new List<decimal>();

            if (data.Count < period) return 0M;

            for (int i = data.Count - period; i < data.Count; i++)
            {
                decimal dailyRangePercentage = CalculateDailyRangePercentage(data[i]);
                dailyRangePercentages.Add(dailyRangePercentage);
            }

            return dailyRangePercentages.Average();
        }
@DaveSkender
Copy link
Owner

DaveSkender commented Sep 12, 2024

❤️ Thanks for the recommendation!
This does look similar in nature to True Range and Average True Range.

From your link, average daily range is an SMA of High - Low for each candle.

I'll take a closer look later for adding to the library. For now, this can be done with a fairly simple implementation:

IEnumerable<SmaResult> adr = quotes
  .Select(x => new BasicData()
   {
     Date = x.Date,
     Value = (double)(x.High - x.Low)  // dr
   })
  .GetSma(lookbackPeriods);

The normalization to a percentage that you're showing with /Close makes sense too as an extra returned property; though, I'd probably do the percentage as ADR/close (not shown) instead of avg(DR/close) (below).

IEnumerable<SmaResult> adrp = quotes
  .Select(x => new BasicData()
   {
     Date = x.Date,
     Value = (double)(x.High - x.Low)/x.Close
   })
  .GetSma(lookbackPeriods);

@DaveSkender DaveSkender changed the title Average Daily Range (ADR)? Average Daily Range (ADR) Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants