Skip to main content

How to Draw Lines in TradingView Pinescript

 How to draw lines in TradingView pinescript?

Free TradingView Scripts - How to Draw Lines in TradingView Pinescript


There are 3 ways that I know of on how to draw lines in TradingView  pinescript. And, these are:
  • hline()
  • plot()
  • line.new()

hline()

The hline() or Levels are used to plot horizontal lines across the chart. It is commonly used in RSI to indicate the oversold and overbought levels.

Let's say we have an oscillator that is very similar to RSI and we want to plot the oversold and overbought levels,  we can do that easily by calling the hline function:
hline(price, title, color, linestyle, linewidth, editable) → hline
And here's the example of trying to use the function:


And here's the result when plotted to chart

Free TradingView Scripts - RSI w/ overbought and oversold levels drawn by hline() function
RSI + Levels (30, 50, 70)


plot()

The plot() function is often used to draw almost all lines in TradingView pinescript. We can plot many things from a wave-like line to a straight line.

For example we want to plot a Simple Moving Average on our chart:


Free TradingView Scripts - plotting a simple moving average (sma)
Plotting a Simple Moving Average using plot()

What if let's say we want the ability to draw major support and resistances on our chart? Then we can also use the plot() for that. Here's an example:


Then let's change the settings of our Support and Resistance indicator to this:

Free TradingView Scripts - TradingView indicator settings for support and resistance
Support and Resistance Indicator Settings

Then let's check the chart to see what happened...

Free TradingView Scripts - Support and Resistance lines using plot() function
Support and Resistance Indicator using plot()

Now, we can draw major support and resistances with this indicator so that we always know the important levels of the market. Also, this is the same result as hline, so you can use them too if you want. In fact, when drawing straight lines i prefer  to use the hline.

line.new()

The line.new() is mostly used to draw line segments and zigzags over the chart. You can even draw a ray line that extends to the right or left, depending on the parameter that is set.

One drawback for using this function is that TradingView limits the total number of drawings of this because it might consume server resources. And because of that TradingView delete's the old drawings of this lines and replaces it with the most recent ones.

For this one, let's say we want to draw a ray line starting from the highest highs on the most recent 30 days. And the line should extend to the right, acting as resistance.

We can do that by:


Now, if you look at the picture below, we have a nice-looking ray that acts as immediate resistance.

Free TradingView Scripts - line.new() to create a ray line for immediate resistance
Nice-Looking Resistance using line.new()


Conclusion

As you can see, there are many different ways to draw lines in TradingView and each of them has a different use. 

My advise is to use them when:

plot() - as much as possible use this one as this one have no limits compared to line.new(). Use this one for non-straight lines.

hline() - drawing levels for oscillators like RSI.

line.new() - drawing line.segments or lines that you need to modify because this one is deletable and updateable.

With these 3 we can now draw any kind of lines that we may need to complete our trading strategy. We can draw profit targets, stop loss targets, zigzags, support and resistances, and many more. You can even draw important support and resistance so that you have one glance look every time you are checking the chart.

A Little Favor From You ๐Ÿ˜…

Since I give everything for free in this blog, please have time to support the blog by following or subscribing to some of my social media accounts:

๐Ÿ‘‰ Youtube Channel

๐Ÿ‘‰ Blog


Comments

Popular posts from this blog

Simple 3-EMA Crossover Trading Strategy - Free Profitable TradingView Strategy Script (+ Source Code)

SIMPLE 3-EMA CROSSOVER TRADING STRATEGY FOR BEGINNERS Risk Disclaimer ❗ The information provided on this post does not constitute investment advice, financial advice, trading advice, or any other sort of advice, and you should not treat any of the posts's content as such. Free Trading View Scripts does not recommend any cryptocurrency should be bought, sold or held by you. Do conduct your own due diligence and consult your financial advisor before making any investment decisions. Introduction In this post, I’m gonna show you a simple yet profitable trading strategy that anyone can use to trade crypto. We’ll only be using one type of indicator and that is the Exponential Moving Average. Later in this post i’ll help you code this strategy using tradingview pinescript so that we can easily backtest historical data and see if this strategy has a chance or not. Before we start, you might want to use my referral link on Binance

How to Add an ATR Trailing Stoploss to Your Strategy - TradingView Script (+ Source Code)

How to Add an ATR Trailing Stoploss to Your Strategy in TradingView Risk Disclaimer ❗ The information provided on this post does not constitute investment advice, financial advice, trading advice, or any other sort of advice, and you should not treat any of the posts's content as such. Free Trading View Scripts does not recommend any cryptocurrency should be bought, sold or held by you. Do conduct your own due diligence and consult your financial advisor before making any investment decisions. Introduction As promised, in this post we are going to add a trailing stoploss strategy to avoid giving back the profits to the market. Out of all the strategies available for trailing stop, I am choosing the ATR . The main reason I chose this is that the ATR changes based on the volatility of the candles. It takes into account the huge movements of the candle to avoid being whipsawed more often . You’ll see what I’m t

Source Code - Simple 3-EMA Crossover TradingView Strategy

Source Code of Simple 3-EMA Crossover TradingView Strategy Script Related links Link to the blog post Link to youtube video version Source Code A Little Favor From You ๐Ÿ˜… Since I give everything for free in this blog, please have time to support the blog by following or subscribing to some of my social media accounts: ๐Ÿ‘‰ Youtube Channel ๐Ÿ‘‰ Blog