AugustoErni

Uptrend Downtrend Loopback Candle Identification Lib

AugustoErni Actualizado   
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.
Notas de prensa:
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.
Notas de prensa:
v3

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

Biblioteca Pine

Siguiendo el verdadero espíritu de TradingView, el autor de este código de Pine lo ha publicado como biblioteca de código abierto, para que el resto de programadores de Pine de esta comunidad puedan volver a utilizarlo. ¡Un hurra por el autor! Puede utilizar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero debe ceñirse a lo establecido en las Normas internas.

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.

¿Quiere utilizar esta biblioteca?

Copie la siguiente línea y péguela en su script.