DEV Community

Cover image for How to detect the trend using only 3 lines
Carlos Alberto
Carlos Alberto

Posted on • Updated on

How to detect the trend using only 3 lines

How to draw 3 lines in a chart using Pine language from tradingview:

study("Line", overlay=true)
L =, high, bar_index[10], low[10], width = 2)
M =, high, bar_index[30], low[30], width = 2)
N =, high, bar_index[60], low[60], width = 2)
line.set_color(L,  // la linea mas corta
line.set_color(M,   // la mediana
line.set_color(N,  // la linea mas larga

Enter fullscreen mode Exit fullscreen mode

The result is like in the next graph:
Graficando tres lineas de las ultimas pendientes en trading view


The shortest line is green (10 candles)
The medium line is red (30 candles)
The largest line is blue(60 candles)

How to Use ?

You need to identify the slope of every line and the respective moment or the value of the trend in a forex instrument graph.
And using the slope you can program more complex algorithms, to make decisions about buy or sell.

Use this code in your programs and let us to know.

Thanks for read

Top comments (0)