QuantConnect / Lean

Lean Algorithmic Trading Engine by QuantConnect (Python, C#)
https://lean.io
Apache License 2.0
9.47k stars 3.21k forks source link

Average Daily Range (ADR) indicator #1877

Open michaelsrew opened 6 years ago

michaelsrew commented 6 years ago

On the day that this project is 99.92% finished please add Mr. Wilders ADR indicator.

captholley commented 4 years ago

I am considering working on this one, but I have a question on what would be the best way to implement the ADR. I could simply do the difference of the high and low for the input range, though this will not take into account the user possibly inputting a resolution other than daily.

I could also have private variables for the high and low and update these as the data points flow in, which would require a large warm-up if the user chooses a lower resolution such as minute.

Or is there a way to restrict the indicator to only certain resolutions. This may be easiest if there is an option.

Once I know this I can submit a pull request as the code is very similar to the ATR indicator.

LouisSzeto commented 1 year ago

spy_adr.csv

LouisSzeto commented 10 months ago

spy_adr.csv columns: "SPY high" "SPY low" "ADR"

script:

import talib
import pandas as pd

history = pd.read_csv("https://github.com/QuantConnect/Lean/raw/master/Data/equity/usa/daily/spy.zip",
                       index_col=0, names=["open", "high", "low", "close", "volume"])

high = history.high
low = history.low

# Source: https://www.tradingview.com/script/6KVjtmOY-ADR-Average-Daily-Range-by-MikeC-AKA-TheScrutiniser/
adr = talib.SMA(high - low, 20).dropna().to_frame()
adr["spy high"] = high
adr["spy low"] = low
adr = adr.iloc[:, [1, 2, 0]]
adr.to_csv("spy_adr.csv", header=False)