Relative slopeRelative slope metric
Description:
I was in need to create a simple, naive and elegant metric that was able to tell how strong is the trend in a given rolling window. While abstaining from using more complicated and arguably more precise approaches, I’ve decided to use Linearly Weighted Linear Regression slope for this goal. Outright values are useful, but the problem was that I wasn’t able to use it in comparative analysis, i.e between different assets & different resolutions & different window sizes, because obviously the outputs are scale-variant.
Here is the asset-agnostic, resolution-agnostic and window size agnostic version of the metric.
I made it asset agnostic & resolution agnostic by including spread information to the formula. In our case it's weighted stdev over differenced data (otherwise we contaminate the spread with the trend info). And I made it window size agnostic by adding a non-linear relation of length to the output, so finally it will be aprox in (-1, 1) interval, by taking square root of length, nothing fancy. All these / 2 and * 2 in unexpected places all around the formula help us to return the data to it’s natural scale while keeping the transformations in place.
Peace TV
Regressions
Trend Line wi 3-PointsHello, my friends. This is a new version of the trend line regression indicator, which always finds quantitive trend lines with three key points.
(1) Indicator description
This indicator finds a trend line with three key points on the historical K-line
Solving the problem of calculation timeout based on a faster trend line regression algorithm
Supports filtering unwanted trend lines by setting a trendline strength threshold
It's suitable for most markets and timeframes
(2) Key parameters
- Pivot High/Low Settings
Pivot Lookback Left: Number of K-lines to look back left from the pivot top/bottom
Pivot Lookback Right: Number of K-lines to look back right from the pivot top/bottom
- Trend Line Regression
Max of Lookback Forward: The maximum number of historical K-lines
Min Regression Strength: The minimum strength threshold for trend line regression
Multiply Regression Std: The width of the trend line to display on the chart
(3) Script description
Due to some circumstances that I don't want to see, subsequent scripts will not be open source, but you can still use the script for free. Thanks for your understanding and support!
If you have any suggestions or comments about the script, please feel free to leave your comments!
Happy trading, and enjoy your life!
————————————————————————————————————————
各位朋友大家好,这是一个全新的趋势线回归指标。该指标总是会找到在图表中具有3个关键点的合理趋势线
(1) 指标说明
该指标在历史K线上找到具有3个关键点的趋势线,并绘制于图表上
基于更快速的趋势线回归算法,解决了计算超时的问题
支持通过设置趋势线强度阈值过滤不需要的趋势线
该指标适用于大部分市场和时间周期
(2) 关键参数
- Pivot High/Low Settings
Pivot Lookback Left: 枢纽顶/底点往左回顾的 K线 数量
Pivot Lookback Right: 枢纽顶/底点往右回顾的 K线 数量
- Trend Line Regression
Max of Lookback Forward: 回顾历史 K线 的最大数量
Min Regression Strength: 趋势线回归的最小强度阈值
Multiply Regression Std: 趋势线的显示宽度
(3) 脚本说明
因为出现了一些我不希望看到的情况,后续的脚本将不再开源代码,但是您依然可以免费使用该脚本,感谢理解和支持!
如果您存在对于该脚本的使用建议或者意见,欢迎各位留言!
祝大家交易愉快
Smart Reg channel [monpotejulien]This indicator calculates an adaptative regression channel over a specified period or interval.
Resources:
rosettacode.org
en.wikipedia.org
Trend Line RegressionThis is a fast trend line regressor based on least squares regression.
(1) Supports setting regression from the Nth candle
(2) Supports the minimum and maximum regression candle interval length
(3) Supports finding the optimal regression region based on the length step among the minimum and maximum regression region lengths
(4) Supports displaying the optimal regression level
(5) The size of the regression region is 0.5 times the standard deviation by default
(6) You can filter the trend line by setting minimum trend line regression level
(6) Please properly set the parameters to avoid calculation timeout
Enjoy!
这是一个基于最小二乘法回归的快速趋势线回归
(1) 支持从第N根蜡烛开始设置回归
(2) 支持最小和最大的回归蜡烛区间长度
(3) 支持在最小和最大回归区间长度的基础上寻找最佳回归区域
(4) 支持显示最佳回归水平
(5) 回归区域的大小默认为标准差的0.5倍
(6) 可以通过设置最小趋势线回归等级来过滤趋势线
(6) 请正确设置参数以避免计算超时
使用愉快!
Price Region RegressionThis is an optimized price range regressor based on least squares regression.
(1) Supports setting regression from the Nth candle
(2) Supports the minimum and maximum regression candle interval length
(3) Supports finding the optimal regression region based on the length step among the minimum and maximum regression region lengths
(4) Supports displaying the optimal regression level
(5) The size of the regression region is two times the standard deviation by default
这是一个基于最小二乘回归的价格区间回归指标
(1) 支持设置从第N个蜡烛开始回归
(2) 支持最小和最大回归蜡烛的区间长度
(3) 在最小和最大回归区间长度中,根据长度步进寻找最优的回归区间
(4) 支持显示最优回归等级
(5) 回归区间的大小默认为2倍标准差
StrengthA mathematically elegant, native & modern way how to measure velocity/ strength/ momentum. As you can see it looks like MACD, but !suddenly! has N times shorter code (disregard the functions), and only 1 parameter instead of 3. OMG HOW DID HE DO IT?!?
MACD: "Let's take one filter (1 parameter), than another filter (2 parameters), then let's take dem difference, then let's place another filter over the difference (3rd parameter + introduction of a nested calculation), and let's write a whole book about it, make thousands of multi-hours YouTube videos about it, and let's never mention about the amount of uncertainty being introduced by multiple parameters & introduction of the nested calculation."
Strength: "let's get real, let's drop a weighted linear regression & usual linear regression over the data of the same length, take dem slopes, then make the difference over these slopes, all good. And then share it with people w/o putting an ® sign".
Fyi, regressions were introduced centuries ago, maybe decades idk, the point is long time ago, and computational power enough to calculate what I'm saying is slightly more than required for macd.
Rationale.
Linearly weighted linear regression has steeper slope (W) than the usual linear regression slope (S) due to the fact that the recent datapoints got more weight. This alone is enough of a metric to measure velocity. But still I've recalled macd and decided to make smth like it cuz I knew it'll might make you happy. I realized that S can be used instead of smoothing the W, thus eliminating the nested calculation and keeping entropy & info loss in place. And see, what we get is natural, simple, makes sense and brings flex. I also wanna remind you that by applying regression we maximize the info gain by using all the data in the window, instead of taking difference between the first and the last datapoints.
This script is dedicated to my friend Fabien. Man, you were the light in the darkness in that company. You'll get your alien green Lambo if you'll really want it, no doubts on my side bout that.
Good hunting
End Point Moving Average [EPMA]The End Point Moving Average was introduced in the October 95 issue of Technical Analysis of Stocks &
Commodities in the article "The End Point Moving Average", by Patrick E. Lafferty.
The Time Series Forecast takes this value and the slope of the regression line to forecast the next day and then plots this forecasted price as today's value.
For interpretation refer to Mr. Lafferty's article.
Please note
From line 10 starts my personal experemental modifications to this script, all above is original formula by Patrick E. Lafferty.
Bitcoin Best Value CorridorHere is my interpretation of the "Best Time To Buy" Bitcoin over its lifetime using a logarithmic regression trendline. The upper and lower lines are 10% deviations from the centre line. I calculated the trendline in excel and then coded my results into pine script.
Signals Pirate™ ScalperSignalsPirate™ Scalper has been created specifically for asset scalping to help improve your short term trading by accurately identifying ‘Buy’ and ‘Sell’ opportunities!
The simplicity of this package ensures traders of all levels of expertise can utilise this tool and experience its benefits to the fullest. The only variable that alters the tools performance is the ‘Scalp Length’ option, which dictates how frequently scalping signals are identified. A value of 10 will result in more selective and less frequent signals, whereas a value of 1 will print ‘Buy’ and ‘Sell’ signals more often.
This tool has been formed using a number of trend reversal indicators, such as the RSI and Stochastics to identify overbought and oversold conditions. As well as these it incorporates crucial pivot points to identify potential support & resistance levels where scalp opportunities will have the highest chance of being successful. Combining these means when price is extremely oversold across a multitude of indicators while sitting at a pivot point support level, a ‘Buy Scalp’ label is created – and vice versa for ‘Sell Scalp’ signals.
The default settings are the best settings we’ve found so far but you can change them to build your own unique trading strategy. We’d recommend experimenting with these values to find the best results for the asset you are trading, and your own personal trading style.
Direction for use:
1. Use on any asset class and time frame, preferably on a lower timeframe (15min or less).
2. Fine tune the ‘Scalp Length’.
3. Enter a long position once a ‘Buy Scalp’ label is created, and close the position once a ‘Sell Scalp’ label is created. For short positions enter once a ‘Sell Scalp’ label is created and close once a ‘Buy Scalp’ label is created.
We hope you love this package, and it takes your trading and investing to the next level. Please let us know if you have any questions or queries regarding the logic behind the bundle, or if you have any suggestions for improvements etc. We love your feedback and are constantly striving to continuously improve!
[UPRIGHT Trading] Auto-Trendlines Pro (cc)Hello Traders -
Today I am releasing a full-featured auto-trendline indicator.
This makes it easier for beginners and professionals alike to analyze a charts trending support and resistance.
What are Trendlines and why do we use them?
In short, a trendline is a diagonal line that connects to two or more price points on a chart to show the current direction of price. These are used to identify and confirm trend direction in technical analysis and show support and resistance points.
Utilizing pivot points and different calculations for sources we're able to create the trendlines; with adjustable slopes (or just use of proprietary calculations) we are able to make these lines to line up with the current trend.
How it's different:
Accurate auto-drawn calculated trendlines.
Fully customizable - the ability to adjust the trendlines easily to exact specifications with every type of trader in mind.
Can be used to spot long trend as well as short, by adjusting length or using extend both to see previous pivots it's touched.
Then retracted, for perfect long trend.
Can show old trendlines for analysis (click image to see).
Auto-labels Higher-Highs, Higher-Lows, Lower-Highs, Lower-Lows at pivots.
Lining up trendlines with Break signals can help provide more accurate trendlines (potentially teaching) beginners how to draw them better.
Signature double trendline set.
Also notice the additional sell/buy signals (shown above).
Squeeze / Low-float mode adjusts to fit big moves.
Adjust the opacity to hide or fade a line (as seen above).
Pre-filled alerts for breakouts / breakdowns.
Please see author instructions for access.
Cheers,
Mike
(UPRIGHT Trading)
Bitcoin Power Law Bands (BTC Power Law) Indicator█ OVERVIEW
The 'Bitcoin Power Law Bands' indicator is a set of three US dollar price trendlines and two price bands for bitcoin , indicating overall long-term trend, support and resistance levels as well as oversold and overbought conditions. The magnitude and growth of the middle (Center) line is determined by double logarithmic (log-log) regression on the entire USD price history of bitcoin . The upper (Resistance) and lower (Support) lines follow the same trajectory but multiplied by respective (fixed) factors. These two lines indicate levels where the price of bitcoin is expected to meet strong long-term resistance or receive strong long-term support. The two bands between the three lines are price levels where bitcoin may be considered overbought or oversold.
All parameters and visuals may be customized by the user as needed.
█ CONCEPTS
Long-term models
Long-term price models have many challenges, the most significant of which is getting the growth curve right overall. No one can predict how a certain market, asset class, or financial instrument will unfold over several decades. In the case of bitcoin , price history is very limited and extremely volatile, and this further complicates the situation. Fortunately for us, a few smart people already had some bright ideas that seem to have stood the test of time.
Power law
The so-called power law is the only long-term bitcoin price model that has a chance of survival for the years ahead. The idea behind the power law is very simple: over time, the rapid (exponential) initial growth cannot possibly be sustained (see The seduction of the exponential curve for a fun take on this). Year-on-year returns, therefore, must decrease over time, which leads us to the concept of diminishing returns and the power law. In this context, the power law translates to linear growth on a chart with both its axes scaled logarithmically. This is called the log-log chart (as opposed to the semilog chart you see above, on which only one of the axes - price - is logarithmic).
Log-log regression
When both price and time are scaled logarithmically, the power law leads to a linear relationship between them. This in turn allows us to apply linear regression techniques, which will find the best-fitting straight line to the data points in question. The result of performing this log-log regression (i.e. linear regression on a log-log scaled dataset) is two parameters: slope (m) and intercept (b). These parameters fully describe the relationship between price and time as follows: log(P) = m * log(T) + b, where P is price and T is time. Price is measured in US dollars , and Time is counted as the number of days elapsed since bitcoin 's genesis block.
DPC model
The final piece of our puzzle is the Dynamic Power Cycle (DPC) price model of bitcoin . DPC is a long-term cyclic model that uses the power law as its foundation, to which a periodic component stemming from the block subsidy halving cycle is applied dynamically. The regression parameters of this model are re-calculated daily to ensure longevity. For the 'Bitcoin Power Law Bands' indicator, the slope and intercept parameters were calculated on publication date (March 6, 2022). The slope of the Resistance Line is the same as that of the Center Line; its intercept was determined by fitting the line onto the Nov 2021 cycle peak. The slope of the Support Line is the same as that of the Center Line; its intercept was determined by fitting the line onto the Dec 2018 trough of the previous cycle. Please see the Limitations section below on the implications of a static model.
█ FEATURES
Inputs
• Parameters
• Center Intercept (b) and Slope (m): These log-log regression parameters control the behavior of the grey line in the middle
• Resistance Intercept (b) and Slope (m): These log-log regression parameters control the behavior of the red line at the top
• Support Intercept (b) and Slope (m): These log-log regression parameters control the behavior of the green line at the bottom
• Controls
• Plot Line Fill: N/A
• Plot Opportunity Label: Controls the display of current price level relative to the Center, Resistance and Support Lines
Style
• Visuals
• Center: Control, color, opacity, thickness, price line control and line style of the Center Line
• Resistance: Control, color, opacity, thickness, price line control and line style of the Resistance Line
• Support: Control, color, opacity, thickness, price line control and line style of the Support Line
• Plots Background: Control, color and opacity of the Upper Band
• Plots Background: Control, color and opacity of the Lower Band
• Labels: N/A
• Output
• Labels on price scale: Controls the display of current Center, Resistance and Support Line values on the price scale
• Values in status line: Controls the display of current Center, Resistance and Support Line values in the indicator's status line
█ HOW TO USE
The indicator includes three price lines:
• The grey Center Line in the middle shows the overall long-term bitcoin USD price trend
• The red Resistance Line at the top is an indication of where the bitcoin USD price is expected to meet strong long-term resistance
• The green Support Line at the bottom is an indication of where the bitcoin USD price is expected to receive strong long-term support
These lines envelope two price bands:
• The red Upper Band between the Center and Resistance Lines is an area where bitcoin is considered overbought (i.e. too expensive)
• The green Lower Band between the Support and Center Lines is an area where bitcoin is considered oversold (i.e. too cheap)
The power law model assumes that the price of bitcoin will fluctuate around the Center Line, by meeting resistance at the Resistance Line and finding support at the Support Line. When the current price is well below the Center Line (i.e. well into the green Lower Band), bitcoin is considered too cheap (oversold). When the current price is well above the Center Line (i.e. well into the red Upper Band), bitcoin is considered too expensive (overbought). This idea alone is not sufficient for profitable trading, but, when combined with other factors, it could guide the user's decision-making process in the right direction.
█ LIMITATIONS
The indicator is based on a static model, and for this reason it will gradually lose its usefulness. The Center Line is the most durable of the three lines since the long-term growth trend of bitcoin seems to deviate little from the power law. However, how far price extends above and below this line will change with every halving cycle (as can be seen for past cycles). Periodic updates will be needed to keep the indicator relevant. The user is invited to adjust the slope and intercept parameters manually between two updates of the indicator.
█ RAMBLINGS
The 'Bitcoin Power Law Bands' indicator is a useful tool for users wishing to place bitcoin in a macro context. As described above, the price level relative to the three lines is a rough indication of whether bitcoin is over- or undervalued. Users wishing to gain more insight into bitcoin price trends may follow the author's periodic updates of the DPC model (contact information below).
█ NOTES
The author regularly posts on Twitter using the @DeFi_initiate handle.
█ THANKS
Many thanks to the following individuals, who - one way or another - made the 'Bitcoin Power Law Bands' indicator possible:
• TradingView user 'capriole_charles', whose open-source 'Bitcoin Power Law Corridor' script was the basis for this indicator
• Harold Christopher Burger, whose Bitcoin’s natural long-term power-law corridor of growth article (2019) was the basis for the 'Bitcoin Power Law Corridor' script
• Bitcoin Forum user "Trololo", who posted the original power law model at Logarithmic (non-linear) regression - Bitcoin estimated value (2014)
MM Chop Filter Range BoxesMatch with the MM Chop Filter
This draw Non repainting range boxes when the oscillator see a range.
-Breakout Buy/Sell Signals and Exit signals when prices enters a range just in case you did get into a trade. .
-Alarms to match the signals
How to use
Match with the oscillator and always trade the trend with your strategy confirmation and the breakout this indicator provides
Weighted Least Squares Moving AverageLinearly Weighted Ordinary Least Squares Moving Regression
aka Weighted Least Squares Moving Average -> WLSMA
^^ called it this way just to for... damn, forgot the word
Totally pwns LSMA for some purposes here's why (just look up):
- 'realistically' the same smoothness;
- less lag;
- less overshoot;
- more or less same computationally intensive.
"Pretty cool, huh?", Bucky Roberts©, thenewboston
Now, would you please (just look down) and see the comparison of impulse & step responses:
Impulse responses
Step responses
Ain't it beautiful?
"Motivation behind the concept & rationale", by gorx1
Many been trippin' applying stats methods that require normally distributed data to time series, hence all these B*ll**** Bands and stuff don't really work as it should, while people blame themselves and buy snake oil seminars bout trading psychology, instead of using proper tools. Price... Neither population nor the samples are neither normally nor log-normally distributed. So we can't use all the stuff if we wanna get better results. I'm not talking bout passing each rolling window to a stat test in order to get the proper descriptor, that's the whole different story.
Instead we can leverage the fact that our data is time-series hence we can apply linear weighting, basically we extract another info component from the data and use it to get better results. Volume, range weighting don't make much sense (saying that based on both common sense and test results). Tick count per bar, that would be nice tho... this is the way to measure "intensity". But we don't have it on TV unfortunately.
Anyways, I'm both unhappy that no1 dropped it before me during all these years so I gotta do it myself, and happy that I can give smth cool to every1
Here is it, for you.
P.S.: the script contains standalone functions to calculate linearly weighted variance, linearly weighted standard deviation, linearly weighted covariance and linearly weighted correlation.
Good hunting
Logarithmic Trend ChannelThis indicator automatically draws a regression channel plotted on logarithmic scale from the first quotation.
This model is useful for the long term series data (such as 10 or 20 years time span).
The Pearson correlation measures the strength of the linear relationship between two variables. It has a value between to 1, with a value of 0 meaning no correlation, and + 1 meaning a total positive correlation.
Logarithmic price scales are a type of scale used on a chart, plotted such that two equivalent price changes are represented by the same vertical changes on the scale.
They differ from linear price scales because they display percentage points and not dollar price increases for a stock.
Technical issues
*The user have to pan over the chart from the beginning to the end of the study range (such as 10 years of bars) so the pine script could generate those lines on the chart.
*If on the chart the number of bar is less than the lookback period, it won't generate any lines as well.
[RS]Long Term Price Range Analysis (MML)Study on Price range Regression and range (deviation multiplier needs to be accommodate manually to fit price action)
study was made for time frames above weekly
[RS]Linear Regression Bands V1experiment with linear regression, the purpose was to catch break outs early, but it creates to much visual noise
same as version 0 but with added margin filter and signal to mark entrys