DEV Community

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

Posted on • Edited on

3 1

How to detect the trend using only 3 lines

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

//@version=4
study("Line", overlay=true)
L = line.new(bar_index, high, bar_index[10], low[10], width = 2)
line.delete(L[1])
M = line.new(bar_index, high, bar_index[30], low[30], width = 2)
line.delete(M[1])
N = line.new(bar_index, high, bar_index[60], low[60], width = 2)
line.delete(N[1])
line.set_color(L,color=color.green)  // la linea mas corta
line.set_color(M,color=color.red)   // la mediana
line.set_color(N,color=color.blue)  // 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

Explanation:

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

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay