OPEN-SOURCE SCRIPT

Logarithmic Regression Alternative

Logarithmic regression is typically used to model situations where growth or decay accelerates rapidly at first and then slows over time. Bitcoin is a good example.



With this logarithmic regression (log reg) formula 𝑦 (price) is calculated with constants 𝑎 and 𝑏, where 𝑥 is the bar_index.

Instead of using the sum of log x/y values, together with the dot product of log x/y and the sum of the square of log x-values, to calculate a and b, I wanted to see if it was possible to calculate a and b differently.

In this script, the log reg is calculated with several different assumed a & b values, after which the log reg level is compared to each Swing. The log reg, where all swings on average are closest to the level, produces the final 𝑎 & 𝑏 values used to display the levels.

🔶 USAGE

The script shows the calculated logarithmic regression value from historical swings, provided there are enough swings, the price pattern fits the log reg model, and previous swings are close to the calculated Top/Bottom levels.

When the price approaches one of the calculated Top or Bottom levels, these levels could act as potential cycle Top or Bottom.

Since the logarithmic regression depends on swing values, each new value will change the calculation. A well-fitted model could not fit anymore in the future.

스냅샷
Swings are based on Weekly bars. A Top Swing, for example, with Swing setting 30, is the highest value in 60 weeks. Thirty bars at the left and right of the Swing will be lower than the Top Swing. This means that a confirmation is triggered 30 weeks after the Swing. The period will be automatically multiplied by 7 on the daily chart, where 30 becomes 210 bars.

Please note that the goal of this script is not to show swings rapidly; it is meant to show the potential next cycle's Top/Bottom levels.

🔹 Multiple Levels
스냅샷
The script includes the option to display 3 Top/Bottom levels, which uses different values for the swing calculations.
  • Top: 'high', 'maximum open/close' or 'close'
  • Bottom: 'low', 'minimum open/close' or 'close'

These levels can be adjusted up/down with a percentage.

Lastly, an "Average" is included for each set, which will only be visible when "AVG" is enabled, together with both Top and Bottom levels.

🔹 Notes
스냅샷
Users have to check the validity of swings; the above example only uses 1 Top Swing for its calculations, making the Top level unreliable.

스냅샷
Here, 1 of the Bottom Swings is pretty far from the bottom level, changing the swing settings can give a more reliable bottom level where all swings are close to that level.

Note the display was set at "Logarithmic", it can just as well be shown as "Regular"
스냅샷

In the example below, the price evolution does not fit the logarithmic regression model, where growth should accelerate rapidly at first and then slows over time.
스냅샷

Please note that this script can only be used on a daily timeframe or higher; using it at a lower timeframe will show a warning. Also, it doesn't work with bar-replay.

🔶 DETAILS

The code gathers data from historical swings. At the last bar, all swings are calculated with different a and b values. The a and b values which results in the smallest difference between all swings and Top/Bottom levels become the final a and b values.

The ranges of a and b are between -20.000 to +20.000, which means a and b will have the values -20.000, -19.999, -19.998, -19.997, -19.996, ... -> +20.000.

As you can imagine, the number of calculations is enormous. Therefore, the calculation is split into parts, first very roughly and then very fine.

The first calculations are done between -20 and +20 (-20, -19, -18, ...), resulting in, for example, 4.
The next set of calculations is performed only around the previous result, in this case between 3 (4-1) and 5 (4+1), resulting in, for example, 3.9. The next set goes even more in detail, for example, between 3.8 (3.9-0.1) and 4.0 (3.9 + 0.1), and so on.



This ensures complicated calculations with less effort.

스냅샷
These calculations are done at the last bar, where the levels are displayed, which means you can see different results when a new swing is found.

Also, note that this indicator has been developed for a daily (or higher) timeframe chart.

🔶 SETTINGS

Three sets
  • High/Low

    • color setting
    • Swing Length settings for 'High' & 'Low'
    • % adjustment for 'High' & 'Low'
    • AVG: shows average (when both 'High' and 'Low' are enabled)

  • Max/Min (maximum open/close, minimum open/close)

    • color setting
    • Swing Length settings for 'Max' & 'Min'
    • % adjustment for 'Max' & 'Min'
    • AVG: shows average (when both 'Max' and 'Min' are enabled)

  • Close H/Close L (close Top/Bottom level)

    • color setting
    • Swing Length settings for 'Close H' & 'Close L'
    • % adjustment for 'Close H' & 'Close L'
    • AVG: shows average (when both 'Close H' and 'Close L' are enabled)


  • Show Dashboard, including Top/Bottom levels of the desired source and calculated a and b values.

  • Show Swings + Dot size
Bitcoin (Cryptocurrency)CyclesLOGARITHMICPivot points and levelsregressionregressions

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?


PineCoder: pinecoders.com

- We cannot control our emotions,
but we can control our keyboard -

면책사항