AugustoErni

Uptrend Downtrend Loopback Candle Identification Lib

AugustoErni Telah dikemas kini   
This library is for identifying uptrends and downtrends using a loopback candle analysis method. Which contains two functions:
uptrendLoopbackCandleIdentification() and downtrendLoopbackCandleIdentification(). These functions check if the current candle is part of an uptrend or downtrend, respectively, based on the specified lookback period.

The uptrendLoopbackCandleIdentification() takes two arguments: index, which is the index of the current bar, and lookbackPeriod, which is the number of previous candles to check for an uptrend. The function returns false if the index is less than the lookback period. Otherwise, it initializes a boolean variable isHigherHigh as true and loops through the previous candles. If any of the previous candles have a higher high than the current candle, isHigherHigh is set to false, and the loop breaks. Finally, the function returns the value of isHigherHigh.

The downtrendLoopbackCandleIdentification() takes the same arguments and returns false if the index is less than the lookback period. The function initializes a boolean variable isHigherLow as true and loops through the previous candles. If any of the previous candles have a higher low than the current candle, isHigherLow is set to false, and the loop breaks. The function returns the value of isHigherLow.
Nota Keluaran:
v2

Updated:
uptrendLoopbackCandleIdentification(lookbackPeriod)
  Parameters:
    lookbackPeriod (int)

downtrendLoopbackCandleIdentification(lookbackPeriod)
  Parameters:
    lookbackPeriod (int)

uptrendLoopbackCandleIdentification:
The function starts by declaring a variable isUptrend and initializes it as false. This variable will be used to store the result of the loop analysis.
A for loop is used to iterate through the specified lookbackPeriod with the loop index variable i.
Inside the loop, the code checks if the low of the current bar (low) is greater than or equal to the low of the bar i bars ago (low).
If the condition in step 3 is met, the variable isUptrend is set to true.
After the loop has finished, the function returns the final value of isUptrend.

downtrendLoopbackCandleIdentification:
The function starts by declaring a variable isDowntrend and initializes it as false. This variable will be used to store the result of the loop analysis.
A for loop is used to iterate through the specified lookbackPeriod with the loop index variable i.
Inside the loop, the code checks if the low of the current bar (low) is less than or equal to the low of the bar i bars ago (low).
If the condition in step 3 is met, the variable isDowntrend is set to true.
After the loop has finished, the function returns the final value of isDowntrend.

Each function will return true if the respective condition is met for any bar within the lookback period. The loops will not terminate early if the conditions are met.
Nota Keluaran:
v3

add else to change variable value and break the loop to return the expected result.

Perpustakaan Pine

Di dalam semangat sebenar TradingView, pengarang telah menerbitkan kod Pine ini sebagai perpustakaan sumber terbuka, jadi pengaturcara-pengaturcara Pine yang lain dari komuniti kami boleh menggunakannya semula. Sorakan kepada penulis! Anda boleh menggunakan perpustakaan ini secara peribadi atau pada penerbitan-penerbitan sumber terbuka lain, tetapi penggunaan semula kod ini di dalam penerbitan adalah ditadbir oleh Peraturan Dalaman.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.

Mahu gunakan perpustakaan ini?

Salin garisan ini dan tampalkan ia di dalam skrip anda.