firos_meethal

Difference from Highest Price (Last N Candles)

The output of this TradingView indicator is a label that appears below the latest candle on the chart. This label provides information about:

The highest high of the last N candles.
The highest close of the last N candles.
The current trading price.
The percentage difference between the highest high and the current trading price.
The percentage difference between the highest close and the current trading price.
The percentage change in price from the previous candle.
The N-day average percentage change.
This information is useful for traders to understand the relationship between the current price and recent price action, as well as to identify potential overbought or oversold conditions based on the comparison with recent highs and closes.

Here's a breakdown of what the code does:

It takes an input parameter for the number of days (or candles) to consider (input_days).
It calculates the highest high and highest close of the last N candles (highest_last_n_high and highest_last_n_close).
It calculates the difference between the close of the current candle and the close of the previous candle (diff), along with the percentage change.
It maintains an array of percentage changes of the last N days (percentage_changes), updating it with the latest percentage change.
It calculates the sum of percentage changes and the N-day average percentage change.
It calculates the difference between the highest high/highest close of the last N candles and the current trading price, along with their percentage differences.
Finally, it plots this information as a label below the candle for the latest bar.

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?