OPEN-SOURCE SCRIPT
Aggiornato Mark the last 20th candle

This Pine Script indicator, titled "Mark last 20 candle" (short name: "Last 20"), was designed to visually highlight a specific candle on your TradingView chart.
What the indicator does:
The main function of this script is to exclusively mark the first candle within the most recent window of 20 candles on your chart. Instead of coloring all 20 candles, it precisely identifies and highlights only the beginning of this 20-candle sequence.
How the indicator works:
Usage:
This indicator is useful for traders who want to visually track the starting point of a fixed window of recent price action. It can help identify patterns or apply strategies relative to that specific candle.
To use it, simply copy the provided Pine Script code into your TradingView Pine Editor and add it to your chart. The marked candle will dynamically update as new data arrives.
What the indicator does:
The main function of this script is to exclusively mark the first candle within the most recent window of 20 candles on your chart. Instead of coloring all 20 candles, it precisely identifies and highlights only the beginning of this 20-candle sequence.
How the indicator works:
- Number of candles: The script uses a user-defined variable, num_candles_to_mark, set to 20, to specify the size of the relevant candle window.
- Dynamic Identification: The indicator uses the built-in Pine Script variables:
- bar_index: Represents the index of the currently processed candle (starting at 0).
- last_bar_index: Represents the index of the very last available candle in your chart (the most recent).
- Precise Marking: The core logic bar_index == last_bar_index - num_candles_to_mark + 1 calculates the exact index of the candle that is 20 bars before the last_bar_index. If the bar_index of the currently processed candle matches this calculated position, that specific candle is colored blue with 80% transparency.
- Automatic Shift: As new candles appear on your chart (and last_bar_index increases accordingly), the calculated target index (last_bar_index - num_candles_to_mark + 1) also automatically shifts one bar to the right. This ensures that the marked candle automatically "moves along" and always highlights the first candle of the current 20-candle window.
Usage:
This indicator is useful for traders who want to visually track the starting point of a fixed window of recent price action. It can help identify patterns or apply strategies relative to that specific candle.
To use it, simply copy the provided Pine Script code into your TradingView Pine Editor and add it to your chart. The marked candle will dynamically update as new data arrives.
Note di rilascio
[center][h1]Pine Script Indicator: "First of 20 Candles - Fixed Arrow"[/h1][/center]This Pine Script indicator, aptly named "First of 20 Candles - Fixed Arrow" (short title "Fixed Arrow"), is designed to place a highly precise, small, and visually stable arrow on your TradingView chart.
[h2]What It Does[/h2]
The core function of this script is to mark only the very first candle within the most recent window of 20 candles on your chart. Instead of coloring the entire candle, it places a tiny arrow directly on top of this specific candle.
[h2]How It Works[/h2]
[li]Dynamic Window: The script defines a num_candles_to_mark variable, set to 20, to specify the size of the relevant candle window you're interested in.[/li]
[li]Precise Identification: It leverages Pine Script's bar_index (the current candle's index) and last_bar_index (the index of the very last candle on the chart) to calculate the exact position of the "first" candle in this 20-candle sequence.[/li]
[li]Targeted Arrow Placement:
[li]The plotshape() function is used to draw a visual marker.[/li]
[li]location=location.absolute ensures the arrow is placed precisely at the high price level of the identified candle. This makes it "stick" tightly to the candle's top.[/li]
[li]style=shape.triangledown creates a downward-pointing arrow, visually indicating the top of the candle.[/li]
[li]size=size.tiny makes the arrow as small as possible, ensuring it's unobtrusive.[/li]
[li]color=color.new(color.gray, 5) gives it a light grey color with very minimal transparency, making it clearly visible without being distracting.[/li]
[/li]
[h2]Understanding "Static" Behavior[/h2]
It's important to understand how "static" is interpreted in TradingView for markers tied to chart data:
[li]Horizontal Movement: The arrow will move horizontally with the chart as new candles appear or you scroll through time. That's because its position is dynamically linked to the "first candle" of the always-updating 20-candle window.[/li]
[li]Vertical Movement (Relative to Candle): The arrow is statically positioned relative to the candle itself. This means it'll always appear directly on top of (or at the high of) the marked candle. If you drag the chart up or down (changing the price scale), the candle itself will move on your screen, and the arrow will move with it. The arrow doesn't detach from the candle; it maintains its precise position on the candle, even if the candle's screen coordinates change. [/li]
This indicator provides the closest possible "static" behavior for a visual marker bound to a price level in Pine Script, ensuring it always remains accurately placed on its target candle.
[h2]How to Use It[/h2]
[li]Open your TradingView chart.[/li]
[li]Click on "Pine Editor" at the bottom.[/li]
[li]Delete any existing code in the editor.[/li]
[li]Paste the provided Pine Script code into the Pine Editor.[/li]
[li]Click on "Add to Chart."[/li]
You'll now see a tiny, light grey arrow appearing precisely on the top of the first candle of your 20-candle window, dynamically following it as new data unfolds.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.