Topics

Forum Topics not found

Replies

JasperWalter99
18 Apr 2025, 03:46 ( Updated at: 22 Apr 2025, 23:14 )

In TradingView's Pine Script, you cannot directly get the pixel width of a candle, but you can calculate the candle width using the parameters of the number of candles on the time axis and the window width.

You can Calculates the width of each candle based on the time interval between candles and the current window size ratio.

// Get chart widthint chart_width = WindowWidth();// Get number of bars that can be displayed on the window (based on the time span of visible candles)int bars_on_screen = (Time[0] - Time[Bars-1]) / PeriodSeconds();// Calculate pixel width of the candleint candle_width = chart_width / bars_on_screen;// Print the candle widthPrint("Candle width: ", candle_width, " pixels");

Here Geometry Vibes:

WindowWidth() returns the width of the chart window.

PeriodSeconds() gives the time span between each candle.


@JasperWalter99