How to Plot Horizontal Lines in TradingView Using Pine Script
Автор: vlogize
Загружено: 2025-05-27
Просмотров: 21
Описание:
Learn how to plot custom horizontal lines in TradingView without displaying the baseline using Pine Script. Perfect for traders looking to visualize dynamic levels with ease!
---
This video is based on the question https://stackoverflow.com/q/65375170/ asked by the user 'Dutch Tacos' ( https://stackoverflow.com/u/14857494/ ) and on the answer https://stackoverflow.com/a/65379830/ provided by the user 'e2e4' ( https://stackoverflow.com/u/13723165/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Tradingview Pinescript quick q
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
How to Plot Horizontal Lines in TradingView Using Pine Script: A Simple Guide
TradingView is a powerful tool for traders who want to analyze financial markets through charts. A common requirement for traders is to visually represent specific price levels on their charts. Often, traders want to plot values around a particular baseline level without explicitly showing that baseline. This guide will guide you through a simple solution to achieve this using Pine Script.
Understanding the Problem
Imagine you want to plot a baseline horizontal line at a specific value (let's say 1900). You also want to add two more lines just above and below this value (at 1901 and 1899) while keeping the baseline invisible. The main questions arise:
How do you take a user-defined value (the baseline)?
How do you plot additional lines around that value without showing the baseline line itself?
Solution Explained
The solution is straightforward and involves a few simple lines of Pine Script code. Below, we will break down the steps required to create this functionality in TradingView.
1. Setting Up the Script
First, you need to define your script using the right version and give it an appropriate name. In this example, we will use version 4 of Pine Script and name our script "Baseline + -1". Here’s how you do that:
[[See Video to Reveal this Text or Code Snippet]]
2. Creating a User Input for the Baseline
Next, you want to allow users to input a baseline value. This input can be changed dynamically, which makes your script flexible. Here is how you define this input:
[[See Video to Reveal this Text or Code Snippet]]
In this line:
var float declares a variable that holds a floating-point number.
input(1900, "Baseline level") sets the default baseline value to 1900, and the text "Baseline level" is what users will see when they interact with the input.
3. Plotting the Lines Around the Baseline
Now, to plot the two lines (at 1901 and 1899), you simply add and subtract 1 from your baseline variable. You will achieve this with the plot function in Pine Script:
[[See Video to Reveal this Text or Code Snippet]]
These lines will plot:
The first line at one point above the baseline (1901).
The second line at one point below the baseline (1899).
4. Making the Baseline Invisible
If you decide later that you need to hide the baseline from your chart, you can do this by either not plotting it or setting its line transparency to zero. In our case, since we are not plotting it, there’s nothing more to do.
The Complete Pine Script
Here’s the complete Pine Script that combines all the above elements together:
[[See Video to Reveal this Text or Code Snippet]]
Conclusion
By following this guide, you can easily plot horizontal lines in TradingView at specified levels without showing the underlying baseline. This helps maintain a clean chart while still giving you the clarity you need when analyzing price movements around that baseline value.
Feel free to adjust the input values or extend the functionality as per your trading needs. Happy trading!
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: