Vertical Lines

nagihatoum Aktualisiert   
This script plots vertical lines on charts or indicators. Unfortunately pinescript is lacking a vertical line plotting function. Vertical lines are useful to mark events, such as crossover of levels, indicators signals or as a time marker.

After searching the internet for a long time and trying different scripts, this script is the simplest and visually the best. You would think that plotting a vertical line would be relatively easy, it is not! I thank the unknow author for sharing this solution and now I will share it on tradingview to make it readily available to anybody that needs it.

RSI crossover signals are used as an example in this script. When the RSI crosses over 70 or below 30, the script plots a red or green vertical line.
The script plots a vertical line as a histogram bar. The histogram bar must have a height.
Setting the height near infinity like 1e20 will cover all the ranges from top to bottom in most charts, but doesn't work all the time. If the chart range is small in values, the line is not plotted or the chart is visually compressed because the top of the bar is also a data point in the chart. Another solution is to find the highest point in the chart and multiply it by a number from 2 to 10 to set the top of the histogram bar. But this solution doesn't work if the line is drawn in the indicator window. additionally if the chart or indicator includes negative values, a histogram bar with a negative height must be concatenated to the histogram bar with a positive height to cover the positive and negative range.

It would seem intuitive to include a vertical plot function since it is very useful and pinescript already has a horizontal line plot function called Hline. But pinescript is becoming less intuitive, and redundant. A case in point is Version 4 variable declaration and naming, it less intuitive and more redundant than previous versions. I beg Tradingview to adopt a more refined scripting language such as Matlab or Python for charting purposes. These languages can be easily ported to other analysis programs for AI or statistical analysis.
1. Added comments to make the code more readable.

2. Used consistent naming conventions.

3. Used "var" keyword when declaring variables: In Pine Script, it's recommended to use the "var" keyword when declaring variables, especially in if-else statements, to avoid the creation of multiple instances of the same variable.

4. Used ":= operator" instead of "=": The ":=" operator is more efficient than "=" as it allows the script to compute values in a more optimized manner.
You can add the script to indicators by choosing the indicator as a source.

Open-source Skript

Ganz im Spirit von TradingView hat der Autor dieses Skripts es als Open-Source veröffentlicht, damit Trader es besser verstehen und überprüfen können. Herzlichen Glückwunsch an den Autor! Sie können es kostenlos verwenden, aber die Wiederverwendung dieses Codes in einer Veröffentlichung unterliegt den Hausregeln. Sie können es als Favoriten auswählen, um es in einem Chart zu verwenden.


Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.

Möchten Sie dieses Skript auf einem Chart verwenden?