Indicator · Pine Script v4 · On the chart

Test 026 Lvl2

by ricardosantos79· code credited to RicardoSantos

Test 026 Lvl2 is an experimental overlay indicator designed to plot dynamic structural trend lines.

View on GitHub

GitHub stars261on the repository
Pine versionv4older, still runs
Lines of code133
Settings1inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago13 Nov 2021

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

133 lines of Pine Script v4 from beta/arrays/test-026-lvl2.pinescript, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

test-026-lvl2.pinescript
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RicardoSantos

//@version=4
study("test-026-lvl2", overlay=true)

//| Line functions:
f_initline()=>line.new(time, 0., time, 0., xloc.bar_time, width=2)
f_line_updater(_id, _x1, _y1, _x2, _y2)=>
    line.set_xy1(id=_id, x=_x1, y=_y1)
    line.set_xy2(id=_id, x=_x2, y=_y2)
    line.set_color(id=_id, color=_y1 > _y2 ? color.teal : color.orange)

var line L00 = f_initline(), var line L10 = f_initline(), var line L20 = f_initline(), var line L30 = f_initline(), var line L40 = f_initline()
var line L01 = f_initline(), var line L11 = f_initline(), var line L21 = f_initline(), var line L31 = f_initline(), var line L41 = f_initline()
var line L02 = f_initline(), var line L12 = f_initline(), var line L22 = f_initline(), var line L32 = f_initline(), var line L42 = f_initline()
var line L03 = f_initline(), var line L13 = f_initline(), var line L23 = f_initline(), var line L33 = f_initline(), var line L43 = f_initline()
var line L04 = f_initline(), var line L14 = f_initline(), var line L24 = f_initline(), var line L34 = f_initline(), var line L44 = f_initline()
var line L05 = f_initline(), var line L15 = f_initline(), var line L25 = f_initline(), var line L35 = f_initline(), var line L45 = f_initline()
var line L06 = f_initline(), var line L16 = f_initline(), var line L26 = f_initline(), var line L36 = f_initline(), var line L46 = f_initline()
var line L07 = f_initline(), var line L17 = f_initline(), var line L27 = f_initline(), var line L37 = f_initline(), var line L47 = f_initline()
var line L08 = f_initline(), var line L18 = f_initline(), var line L28 = f_initline(), var line L38 = f_initline(), var line L48 = f_initline()
var line L09 = f_initline(), var line L19 = f_initline(), var line L29 = f_initline(), var line L39 = f_initline(), var line L49 = f_initline()
f_line_id(_i)=>(_i==00?L00:(_i==01?L01:(_i==02?L02:(_i==03?L03:(_i==04?L04:(_i==05?L05:(_i==06?L06:(_i==07?L07:(_i==08?L08:(_i==09?L09:
     (_i==10?L10:(_i==11?L11:(_i==12?L12:(_i==13?L13:(_i==14?L14:(_i==15?L15:(_i==16?L16:(_i==17?L17:(_i==18?L18:(_i==19?L19:
     (_i==20?L20:(_i==21?L21:(_i==22?L22:(_i==23?L23:(_i==24?L24:(_i==25?L25:(_i==26?L26:(_i==27?L27:(_i==28?L28:(_i==29?L29:
     (_i==30?L30:(_i==31?L31:(_i==32?L32:(_i==33?L33:(_i==34?L34:(_i==35?L35:(_i==36?L36:(_i==37?L37:(_i==38?L38:(_i==39?L39:
     (_i==40?L40:(_i==41?L41:(_i==42?L42:(_i==43?L43:(_i==44?L44:(_i==45?L45:(_i==46?L46:(_i==47?L47:(_i==48?L48:(_i==49?L49:na
     )))))))))) )))))))))) )))))))))) )))))))))) ))))))))))



var bool trend = false
var bool direction = false

var float elow = low
var int tlow = time
var float ehigh = high
var int thigh = time
var float zz = open
var int tz = time

if trend
    if direction
        if high > ehigh
            ehigh := high
            thigh := time
        if high < high[1] and (low < low[1] or (close-low < (high-low) * 0.5)) //down or engulfing closing low
            elow := low
            tlow := time
            zz := ehigh
            tz := thigh
    else
        if low < elow
            elow := low
            tlow := time
        if high > high[1] and (low > low[1] or (high-close < (high-low) * 0.5))//up or engulfing closing high
            ehigh := high
            thigh := time
            zz := elow
            tz := tlow
else
    if direction
        if high > ehigh
            ehigh := high
            thigh := time
        if high < high[1] and (low < low[1] or (close-low < (high-low) * 0.5)) //down or engulfing closing low
            if low < low[1]
                elow := low
                tlow := time
            else
                elow := low[1]
                tlow := time[1]
            zz := ehigh
            tz := thigh
            direction := false
    else
        if low < elow
            elow := low
            tlow := time
        if high > high[1] and (low > low[1] or (close-low > (high-low) * 0.5))//up or engulfing closing high
            if high > high[1]
                ehigh := high
                thigh := time
            else
                ehigh := high[1]
                thigh := time[1]
            zz := elow
            tz := tlow
            direction := true

plot(zz!=zz[1]?zz:na, color=direction?color.green:color.maroon, style=plot.style_circles, linewidth=2)

int degree = input(1)
bool is_new_zig = change(zz) != 0

var int[] X = array.new_int(size=0, initial_value=0)
var float[] Y = array.new_float(size=0, initial_value=0)


f_filter_pass(_X, _Y, _degree, _value)=>
//| Alters _X, _Y vector arrays to filter out abcd type continuation patterns.
    if _degree > 0 and array.size(id=_X) > 1 + 2 * _degree
        for _i = 1 to _degree
            float _y0 = array.get(id=_Y, index=0)
            float _y1 = array.get(id=_Y, index=1)
            float _y2 = array.get(id=_Y, index=2)
            if (_value > _y0 and _value >= _y1 and _y0 > _y2) or (_value < _y0 and _value <= _y1 and _y0 < _y2)
                array.shift(id=_X)
                array.shift(id=_X)
                array.shift(id=_Y)
                array.shift(id=_Y)


if is_new_zig
    f_filter_pass(X, Y, degree, zz)
    // add new vector
    array.unshift(id=X, value=tz)
    array.unshift(id=Y, value=zz)

    // resize if too many vectors
    if array.size(id=X) > 50
        array.pop(id=X)
        array.pop(id=Y)
    
    //redraw lines
    if array.size(id=X) > 2
        for _i = 0 to array.size(id=X) - 2
            int _x1 = array.get(id=X, index=_i)
            int _x2 = array.get(id=X, index=_i + 1)
            float _y1 = array.get(id=Y, index=_i)
            float _y2 = array.get(id=Y, index=_i + 1)
            f_line_updater(f_line_id(_i), _x1, _y1, _x2, _y2)

Overview

Test 026 Lvl2 tracks local extreme high and low price points based on candle relationships and direction shifts, dynamically updating pre-allocated line drawings on the main price chart. The script colors descending lines teal and ascending lines orange to reflect directional slope. The degree setting controls the depth of the calculation. As an experimental script, its main focus is line management and chart structure visualization.

Details

Published by

ricardosantos79 on GitHub

Code credit

RicardoSantos, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
degreeint1degree
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener

AI Trend

by dearvn
257 stars

AI Trend is an indicator that plots pivot points, trend lines, and support and resistance levels directly on the price chart. It marks high and low pivots based on user-defined length, draws trend lines that check for violations at specified points, and identi

Indicator v5 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of AI Trend

Ichimoku Cloud

by harryguiacorn
219 stars

This indicator plots Ichimoku Cloud elements on the price chart, including Tenkan-sen, Kijun-sen, Senkou Span A and B lines with optional Chikou Span. It signals trend changes via Tenkan-sen and Kijun-sen crosses and places arrows at Kijun-sen direction shifts

Indicator v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ichimoku Cloud
219 stars

This indicator identifies local swing highs and swing lows to construct a Zig Zag pattern on the main price chart. It evaluates pivot points based on a customizable number of surrounding left and right bars. Using persistent variables, the script tracks previo

Indicator v4 Support & resistanceTrend Repaints
Updated 5 years ago · None stated GitHub repository of Teaching: Finding Highs and Lows 6

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

Open Source Fractal

by cantolab
183 stars

This indicator implements the Fractal Model concept to plot market structure shifts, liquidity sweeps, and Change in State of Delivery (CISD) levels. It overlays custom higher-timeframe candle previews, open prices, and time markers directly on the price chart

Indicator v6 SMC / ICT / price actionSupport & resistance
Updated 2 months ago · MIT GitHub repository of Open Source Fractal

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers