Simple Lines


Making lines is great in technical analysis since it can highlights principal movements and make the analysis of the price easier when using certain methodologies ( Elliott Waves , patterns).
However most of the indicators making lines ( Zig-Zag , simple linear regression ) are non causal (repaint), this is the challenge i tried to overcome, making an indicator capable of making lines in a smart way (able to follow price without loosing a linear approach) and with the least lag possible, i inspired myself from the behaviour of the renko when using a small brick size. This indicator does not repaint.

The code is short and i hope, understandable for all of you, making lines is not a difficult task and its important to know that when a problem appear complex it does not mean that the code used to solve this problem must be complex. Lets see the indicator in details.

The indicator

The indicator have 4 parameters, the length parameter who control the length of lines, the emphasis parameter who control the stability and also the ability to make lines closer to the price (thus minimizing the sum of squares), the mult parameter which is similar to emphasis and a point option that we will discuss later.

When emphasis and mult are both equal to 1 the indicator will sometimes draw a perfect line, however this line will try to follow the price and thus can create a noisy result.

This is where emphasis and mult will correct this behaviour. The emphasis parameter give a more periodic look as well as some control to the lines but can also destroy them.

This should not happen with mult, this parameter also give more predictability to the lines. Overall it correct the drawbacks of the parameters combinations mentioned earlier.

Its also possible to mix both the emphasis and mult parameter, but take into account that when both are equals the result consist of less reactive lengthy lines with low accuracy. Its better to only use one of them and let the other stay to 1.

Point Option

The indicator can sometimes have a weird look, appearing almost flat or just dont appearing at all. When such thing happen use the point option.

XPDUSD without point option.

with point option :

Time Frame Problem and Its Fix

When using higher time-frames the result of the indicator can appear different, in general the higher the time frame the lengthier are the lines. In order to fix this you can use decimals in the length parameter

length and mult both equal to 5.5, emphasis cant use decimals.


I have highlighted a simple way to make use of the small renko box size method in order to return reactive lines without making the indicator repaint. However Its ability to be close to the price as well as being always super reactive is not a guarantee.

For any suggestion/help feel free to pm me, i would be happy to help you :)

Release Notes: Can display color based on indicator direction.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Become a Patreon and get access to exclusive technical indicators!

You can also check out some of the indicators I made for luxalgo :


Hi Alex, I was trying to use this in a pine v3 strategy, but I can't get around the Undeclared identifier 'a' error. If I define a at the beginning with 0.0, it won't work anymore. Any suggestion? Cheers man!
+4 Reply
nilux nilux
@nilux, alright, a = na worked :)
+1 Reply
@nilux, In the version 3 you must declare the variable before using recursion, this look like this :

a = 0. (0. or 0.0 mean that you variable "a" is a float, if you put only 0 you say that your variable is an integer and then it wont work if "a" is non integer.)
a := x > nz(a,x) + s ? nz(a,x) + s : x < nz(a,x) - s ? nz(a,x) - s : nz(a,x) (dont forget to put ":" after "=")

It is also possible to use na and fixnan for recursion but the right way to do it is as showed above. This is why i use version 2, its more efficient when dealing with recursion.

Hope this help :)
+1 Reply
nilux alexgrover
@alexgrover, thanks bud, you're a legend!
+1 Reply
@nilux, Thanks, i rectify what i said, don't forget to put ":" before "=", sorry for the mistake.
Hello, I had to upgrade this indicator to v4 and by changing the index to get the previous "A" variable(a1 instead of a0) i got it working exactly like the v2 version.
If anyone needs it here's the source code just change the \1\ with square brackets, for some reason the platform removes them from comments

study("Simple Lines v4",overlay=true)
length = input(10),emphasis = input(1),mult=input(10),point = input(false),paint = input(false,title="Color Based On Direction")
float a=na

x = close + change(nz(a\1\,close),emphasis)*mult
s = point ? syminfo.pointvalue*10*(1/length) : syminfo.mintick*100*(1/length)
a := x > nz(a\1\,x) + s ? nz(a\1\,x) + s : x < nz(a\1\,x) - s ? nz(a\1\,x) - s : nz(a\1\,x)
css = paint ? (a > a\1\ ? #0080FF : #FE2E64) : #FE2E64

Hope it helps someone
+3 Reply
Thank you very much.
I was waiting for someone to create this and works extremely well when combined with other code.
Thank you again.

+2 Reply
alexgrover aaahopper
@aaahopper, Glad you like it, i appreciate your support :)
+1 Reply
aaahopper alexgrover
@alexgrover, Your Welcome
Thank you very much. Your idea is interesting and your code is concise.
+2 Reply
Home Stock Screener Forex Screener Crypto Screener Economic Calendar How It Works Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Private Messages Chat Sign Out