Comments (5)
there's another issue where this is discussed in the strategy repo: freqtrade/freqtrade-strategies#30
Feel free to improve performance (but honestly, you'll have problems with that i'll think).
The way ATR is calculated requires a loop (current value is based on the result of the same calculation for the previous value).
Every indicator that requires a loop will automatically be a lot slower than any indicator that can be vectorized (calculated in one go across the whole timerange) - and there is very little possibility to optimize these calls.
That said, i just noticed that we have 2 different calculations of atr:
one in volatility.py
(this will most likely be wrong as it seems to only use close - but uses the average_true_range
directly from pyti - so having that fixed would require an issue against the pyti repository.
The second version is in indicators (which is vendored from qtpylib). At first glance, the calculation seems ... better aligned to investopedia ...
however please investigate in the linked issue above, as i think also this calculation does not match with tradingview (however i don't see tradingview as gold standard, maybe their implementation is wrong).
from technical.
well i found this code on stackoverflow https://stackoverflow.com/questions/40256338/calculating-average-true-range-atr-on-ohlc-data-with-python and tested myself
def wwma(values, n):
"""
J. Welles Wilder's EMA
"""
return values.ewm(alpha=1/n, adjust=False).mean()
def atr(df, n=14):
data = df.copy()
high = data[HIGH]
low = data[LOW]
close = data[CLOSE]
data['tr0'] = abs(high - low)
data['tr1'] = abs(high - close.shift())
data['tr2'] = abs(low - close.shift())
tr = data[['tr0', 'tr1', 'tr2']].max(axis=1)
atr = wwma(tr, n)
return atr
It's extremely extremely extremely fast
from technical.
it might be fast - but it's most likely not aligned to the calculation of investopedia - which does not mention the use of Wilders MA at all.
You can also use from technical.vendor.qtpylib.indicators import atr
- which will also be extremely fast (as said, it's in technical twice for no real reason)
from technical.
i could change to values.rolling(14).mean(). Haven't tested it yet
from technical.
as said, technical does contain an implementation of atr already, which is fast.
I'll remove the pyti mapper so it'll be clear which one to use.
from technical.
Related Issues (20)
- Resampled dataframes are shifted 1 candle. HOT 4
- Trend Step Channel - appreciate it HOT 4
- resample_to_interval date shifted HOT 1
- Help with Trend Trader Strategy HOT 1
- ichimoku different value proposal HOT 1
- How to import external data to populate entry/exit trend conditions HOT 14
- Multiple timeframe merge HOT 10
- Laguerre RSI wrong computation HOT 3
- ```crossed``` function throws error with numpy integers
- utils bug HOT 4
- How to plot segtrends or gentrends using freqtrade plot-dataframe ? HOT 1
- Phase Change Index HOT 18
- I try to convert Predictive Ranges [LuxAlgo] to the py, whats the problem? HOT 7
- Involvement of Heikenashi candles could be helpful in trend prediction HOT 1
- Help needed with: AttributeError: 'SSL' object has no attribute 'copy' HOT 3
- warning util.py
- 16 tests failed HOT 4
- Pandas warning when setting fillna(0) on RMI calc HOT 2
- Issues with PMAX indicator HOT 1
- A few Pinescript lines HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from technical.