AugustoErni

Uptrend Downtrend Loopback Candle Identification Lib

AugustoErni 已更新   
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.
版本注释:
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.
版本注释:
v3

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

Pine脚本库

本着真正的TradingView精神,作者将此Pine代码以开源脚本库发布,以便我们社区的其他Pine程序员可以重用它。向作者致敬!您可以私下或在其他开源出版物中使用此库,但在出版物中重用此代码受网站规则约束。

免责声明

这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。

想使用这个脚本库吗?

复制以下行并将其粘贴到您的脚本中。