HitTestThreshold property solves.
The HitTestThreshold is an invisible buffer zone around a price line. It tells the charting engine: "If the cursor is within X pixels of this line, treat it as a click." Visually, your chart stays clean and thin. Functionally, it becomes actually clickable.
About this guide: I'm Lawrence, the writer behind supa.is. Between February and May 2026 I've published 150+ articles on supa.is across crypto and brokerage tooling โ including 20+ TradingView-specific guides (recent examples: TradingView Price Scale Range Limit Settings, TradingView Custom Session Extended Hours Settings, TradingView Keyboard Shortcuts: Order Panel & Drawing). The most-repeated reader question across that TradingView archive is exactly how to improve chart interaction and price line clickability, which is why I'm publishing this standardized guide instead of answering one-off.
What is HitTestThreshold in TradingView?
In web development, "hit testing" is the math that determines which element a user clicked. When you draw a line on a chart, it might only be 1 or 2 pixels wide. Trying to click a 1-pixel line with a mouse is frustrating, especially on high-resolution screens or when users are in a hurry.
The HitTestThreshold property solves this by expanding the clickable area of the price line. If a price line has a HitTestThreshold of 5 pixels, the charting engine will register a click if the cursor is anywhere within 5 pixels of the line. Visually, the line remains thin and clean. Functionally, it becomes much easier to interact with.
This feature is particularly relevant for developers using the TradingView Lightweight Charts library, an open-source, high-performance charting library designed for financial data. As discussed in the community, there is a known need to adjust this threshold to improve the user experience when dealing with custom price lines or indicators.
Why Adjusting HitTestThreshold Matters
If you are building a trading dashboard, a custom indicator viewer, or a backtesting interface, the default hit-test area might not be enough. Here is why tweaking the HitTestThreshold is essential:
1. Improving Click Accuracy on Thin Lines
By default, price lines and certain custom series might have a very narrow hit-test area. Traders trying to click on a specific price level to set a buy/sell order, or to trigger a custom alert, might miss the line entirely. Increasing the threshold ensures that the user's intent is accurately captured.2. Enhancing Mobile and Touch Interactions
On mobile devices, touch inputs are less precise than mouse clicks. A finger is much larger than a cursor. If a price line has a lowHitTestThreshold, a user trying to tap on a specific price level on their phone will likely tap the wrong area. A higher threshold acts as a forgiving buffer, making mobile charting much more intuitive.
3. Better Tooltip and Crosshair Interactions
When a user hovers over a chart, the crosshair and tooltip should snap to the nearest price line. If theHitTestThreshold is too small, the tooltip might skip over a price line entirely, jumping from one level to another. Adjusting the threshold ensures smoother, more responsive tooltip behavior.
How to Change the HitTestThreshold
The HitTestThreshold is configured when you create or update a price line or a custom series in the Lightweight Charts API. While the exact implementation can vary depending on the version of the library you are using, the core concept involves passing a threshold value (usually in pixels) to the line's configuration object.
Here is a conceptual breakdown of how this is handled in the Lightweight Charts API:
Setting the Threshold for Price Lines
When you add a price line to a chart, you can specify theHitTestThreshold alongside other properties like color, line width, and price level.
// Conceptual example of adding a price line with a custom HitTestThreshold
const priceLine = {
price: 45000.00, // The price level
color: '#ff0000', // Red line
lineWidth: 2, // Visually thin
lineStyle: LineStyle.Solid,
axisLabelVisible: true,
// The HitTestThreshold property expands the clickable area
hitTestThreshold: 10
};
chart.applyPriceLine(priceLine);
In this example, the line is visually only 2 pixels wide, but the user can click anywhere within 10 pixels of the line and the chart will register it as a click on the price line.
Like what you're reading? Try it yourself โ this link supports ChartedTrader at no cost to you.
Try TradingView โAdjusting for Custom Indicators
If you are drawing custom indicators (like a moving average or a custom support/resistance level) using the Lightweight Charts API, you can also apply aHitTestThreshold to those series. This is crucial if your indicator is drawn as a thin line but needs to be clickable to trigger events (like opening a modal or fetching data).
Note: The exact property name and implementation may vary slightly across different versions of the Lightweight Charts library. If you are encountering issues with price line clickability, refer to the official Lightweight Charts documentation or community issues like GitHub Issue #1610 for the most up-to-date API references.
Best Practices for HitTestThreshold
While increasing the HitTestThreshold makes lines easier to click, it can introduce new problems if you set it too high. Here are some best practices to keep in mind:
1. Don't Exceed Visual Proximity
If you have two price lines very close to each other (e.g., a support line at $45,000 and a resistance line at $45,050), a highHitTestThreshold (like 50 pixels) might cause the chart to register a click on the wrong line. Keep the threshold proportional to the visual distance between lines. A threshold of 5 to 15 pixels is usually a safe sweet spot.
2. Balance Performance and UX
Every interactive element on a chart requires the browser to calculate hit tests. If you have a chart with dozens of custom price lines and indicators, setting an extremely highHitTestThreshold on every single line could slightly impact rendering performance, especially on lower-end devices.
3. Test on Different Screen Resolutions
A threshold of 10 pixels might feel perfect on a 4K monitor, but on a high-DPI mobile screen, 10 pixels might be incredibly small. Always test your chart interaction on the actual devices your users will be using.TradingView Lightweight Charts vs. Standard TradingView
It is important to distinguish between the TradingView Lightweight Charts library and the standard TradingView web application.
The standard TradingView platform (the one you use to analyze charts and trade) has its own internal settings for chart interaction, which are not directly adjustable by the user via a HitTestThreshold setting. If you are a standard user and find it difficult to click on price lines or draw tools on the main TradingView website, you are limited to the default UI behavior.
However, if you are a developer building a custom trading application, you have full control over the Lightweight Charts API, including the HitTestThreshold. This is why this guide focuses on the developer perspective.
If you are looking for a robust, out-of-the-box charting experience without the need to code, TradingView's standard platform is the best choice. You can Try TradingView to access their premium charting tools, advanced indicators, and broker integrations.
Common Issues and Troubleshooting
Even after adjusting the HitTestThreshold, you might still encounter some interaction issues. Here are a few common problems and how to address them:
The Click Still Doesn't Register
If increasing theHitTestThreshold doesn't solve the clickability issue, check if there are other elements overlapping the price line. For example, a custom tooltip, a crosshair overlay, or another chart series might be blocking the click event. Ensure that the price line is rendered on top of other elements, or adjust the z-index of your custom overlays.
The Tooltip Jumps Around
If the tooltip is flickering or jumping between price lines when you hover, yourHitTestThreshold might be too large, causing the chart to switch which line it thinks you are hovering over. Reduce the threshold incrementally until the tooltip snapping feels smooth.
Mobile Touch Events Are Still Inaccurate
Touch events on mobile browsers sometimes behave differently than mouse clicks. If theHitTestThreshold isn't enough, you might need to implement custom touch event handlers in your application to detect when a user's finger is near a price line and manually trigger the desired action.
Conclusion
The HitTestThreshold is a small but powerful property in the TradingView Lightweight Charts API. By expanding the invisible click area around price lines, you can dramatically improve the usability of your custom charting applications, making them more accessible for both desktop and mobile users.
Whether you are building a backtesting tool, a custom indicator dashboard, or a proprietary trading interface, paying attention to the HitTestThreshold will save you from frustrating user feedback and ensure a polished, professional experience.
If you are looking to get started with charting or want to explore the full potential of TradingView's ecosystem, Try TradingView today and see how their tools can elevate your trading workflow.
Risk Warning
Risk Warning: Crypto trading involves substantial risk of loss. Never invest more than you can afford to lose. This is not financial advice.
FAQ
What is the default HitTestThreshold in Lightweight Charts?
The defaultHitTestThreshold varies depending on the specific version of the Lightweight Charts library and the type of series being drawn. For standard price lines, it is typically set to a small value to match the visual width of the line.
Can I change the HitTestThreshold on the standard TradingView website?
No. TheHitTestThreshold is a property available in the TradingView Lightweight Charts API for developers. Standard users of the TradingView web application cannot adjust this setting directly.
How does HitTestThreshold affect chart performance?
A higherHitTestThreshold means the charting engine has to process a larger area for click detection. For most modern devices, this is negligible. However, if you have hundreds of custom price lines with very high thresholds, it could slightly impact rendering performance on low-end hardware.
Is HitTestThreshold measured in pixels or points?
In the Lightweight Charts API, theHitTestThreshold is measured in pixels. This means it scales with the screen resolution and the CSS styling of your chart container.