AugustoErni

Uptrend Downtrend Loopback Candle Identification Lib

AugustoErni Aktualisiert   
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.
Versionshinweise:
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.
Versionshinweise:
v3

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

Pine Bibliothek

In echter TradingView-Manier hat der Autor diesen Pine-Code als Open-Source-Bibliothek veröffentlicht, so dass andere Pine-Programmierer aus unserer Community ihn weiterverwenden können. Ein Hoch auf den Autor! Sie können diese Bibliothek privat oder in anderen Open-Source-Publikationen verwenden, aber die Wiederverwendung dieses Codes in einer Publikation unterliegt den Hausregeln.

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie diese Bibliothek nutzen?

Kopieren Sie die folgende Zeile und fügen Sie sie in Ihr Skript ein.