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.

cuplikan
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
cuplikan
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
cuplikan
Users have to check the validity of swings; the above example only uses 1 Top Swing for its calculations, making the Top level unreliable.

cuplikan
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"
cuplikan

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.
cuplikan

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.

cuplikan
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

Skrip open-source

Dengan semangat TradingView yang sesungguhnya, penulis skrip ini telah menerbitkannya sebagai sumber terbuka, sehingga para trader dapat memahami dan memverifikasinya. Hormat untuk penulisnya! Anda dapat menggunakannya secara gratis, namun penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib. Anda dapat memfavoritkannya untuk digunakan pada chart

Inggin menggunakan skrip ini pada chart?


PineCoder: pinecoders.com

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

Pernyataan Penyangkalan