Strategy · Pine Script v5 · On the chart

Level Search

by DaniilOkrug· code credited to icewalk

This Pine Script strategy identifies and plots horizontal support levels by searching for price clusters across historical price lows.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code213
Settings4inputs
LicenceMIT
Last update4 years ago15 Dec 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

213 lines of Pine Script v5 from [Order] Level search for telegram.txt, published under MIT. Keep the author's credit and licence lines when you reuse it.

[Order] Level search for telegram.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © icewalk

//@version=5
strategy("[Order] Level search", overlay=true, max_bars_back=500)

barsCount = input.int(100, "Bars")
CoincidenceCount = input.int(5, "Количество совпадений")
deviation = input.int(1, "Deviation")
showRupture = input.bool(true)

deviationCurrent = (deviation + 0.1) * syminfo.mintick

var oldLevels_low = array.new_float()
var oldLevels_high = array.new_float()

levels = array.new_float()
count = array.new_int()
barIndexes = array.new_int()

var lines = array.new_line()

//Deleta lines
for l in lines
    line.delete(l)

array.clear(lines)

//Lows
for i = 1 to barsCount
    levelsNumber = array.size(levels)
    if levelsNumber == 0
        array.push(levels, low[i])
        array.push(count, 1)
        array.push(barIndexes, bar_index[i])
        continue
    
    if levelsNumber == 1
        if array.get(levels, 0) - low[i] < deviationCurrent
            if array.get(count, 0) < CoincidenceCount
                array.set(levels, 0, ((array.get(levels, 0) * array.get(count, 0)) + low[i]) / (array.get(count, 0) + 1))
                array.set(count, 0, array.get(count, 0) + 1)
                array.set(barIndexes, 0, bar_index[i])
        else
            array.push(levels, low[i])
            array.push(count, 1)
            array.push(barIndexes, bar_index[i])
        continue
    
    found = false
    for j = levelsNumber - 1 to 0
        if math.abs(array.get(levels, j) - low[i]) < deviationCurrent
            found := true
            if array.get(count, j) < CoincidenceCount
                array.set(levels, j, ((array.get(levels, j) * array.get(count, j)) + low[i]) / (array.get(count, j) + 1))
                array.set(count, j, array.get(count, j) + 1)
                array.set(barIndexes, j, bar_index[i])
    
    if not found
        array.push(levels, low[i])
        array.push(count, 1)
        array.push(barIndexes, bar_index[i])
        
    
for i = array.size(levels) - 1 to 0
    if array.get(count, i) < CoincidenceCount
        array.remove(levels, i)
        array.remove(count, i)
        array.remove(barIndexes, i)
        continue
    
    if array.get(count, i) >= CoincidenceCount
        if not showRupture
            for j = bar_index - array.get(barIndexes, i) to 0
                if (low[j] + deviationCurrent - array.get(levels, i)) *  (high[j] - deviationCurrent - array.get(levels, i)) < 0
                    array.remove(levels, i)
                    array.remove(count, i)
                    array.remove(barIndexes, i)
                    break
            
    
if barstate.islast
    //Lows
    if array.size(levels) > 1
        for i = array.size(levels) - 1 to 0
            if array.get(count, i) >= CoincidenceCount
                level = array.get(levels, i)
                index = bar_index - array.get(barIndexes, i)
                new_line = line.new(bar_index[index], level, bar_index, level, style=line.style_dashed, color=color.blue)
                array.push(lines, new_line)
    else
        if array.size(levels) == 1
            level = array.get(levels, 0)
            index = bar_index - array.get(barIndexes, 0)
            new_line = line.new(bar_index[index], level, bar_index, level, style=line.style_dashed, color=color.blue)
            array.push(lines, new_line)

//Determine new low level
newLevels_low = array.new_float()
if array.size(oldLevels_low) > 0 and array.size(levels) > 0
    for level in levels
        if not array.includes(oldLevels_low, level)
            array.push(newLevels_low, level)
            array.push(oldLevels_low, level)
        
if array.size(oldLevels_low) == 0 and array.size(levels) > 0
    for level in levels
        array.push(oldLevels_low, level)

array.clear(levels)
array.clear(count)
array.clear(barIndexes)

// //Highs
for i = 1 to barsCount
    if array.size(levels) == 0
        array.push(levels, high[i])
        array.push(count, 1)
        array.push(barIndexes, bar_index[i])
        continue
    
    if array.size(levels) == 1
        if array.get(levels, 0) - high[i] < deviationCurrent
            if array.get(count, 0) < CoincidenceCount
                array.set(levels, 0, ((array.get(levels, 0) * array.get(count, 0)) + high[i]) / (array.get(count, 0) + 1))
                array.set(count, 0, array.get(count, 0) + 1)
                array.set(barIndexes, 0, bar_index[i])
        else
            array.push(levels, high[i])
            array.push(count, 1)
            array.push(barIndexes, bar_index[i])
        continue
    
    found = false
    for j = array.size(levels) - 1 to 0
        if math.abs(array.get(levels, j) - high[i]) < deviationCurrent
            found := true
            if array.get(count, j) < CoincidenceCount
                array.set(levels, j, ((array.get(levels, j) * array.get(count, j)) + high[i]) / (array.get(count, j) + 1))
                array.set(count, j, array.get(count, j) + 1)
                array.set(barIndexes, j, bar_index[i])
    
    if not found
        array.push(levels, high[i])
        array.push(count, 1)
        array.push(barIndexes, bar_index[i])
        

for i = array.size(levels) - 1 to 0
    if array.get(count, i) < CoincidenceCount
        array.remove(levels, i)
        array.remove(count, i)
        array.remove(barIndexes, i)
        continue
    
    if array.get(count, i) >= CoincidenceCount
        if not showRupture
            for j = bar_index - array.get(barIndexes, i) to 0
                if (low[j] + deviationCurrent - array.get(levels, i)) *  (high[j] - deviationCurrent - array.get(levels, i)) < 0
                    array.remove(levels, i)
                    array.remove(count, i)
                    array.remove(barIndexes, i)
                    break

if barstate.islast
    //Highs
    if array.size(levels) > 1
        for i = array.size(levels) - 1 to 0
            if array.get(count, i) >= CoincidenceCount
                level = array.get(levels, i)
                index = bar_index - array.get(barIndexes, i)
                new_line = line.new(bar_index[index], level, bar_index, level, style=line.style_dashed, color=color.red)
                array.push(lines, new_line)
    else
        if array.size(levels) == 1
            level = array.get(levels, 0)
            index = bar_index - array.get(barIndexes, 0)
            new_line = line.new(bar_index[index], level, bar_index, level, style=line.style_dashed, color=color.red)
            array.push(lines, new_line)
    
//Determine new low level
newLevels_high = array.new_float()
if array.size(oldLevels_high) > 0 and array.size(levels) > 0
    for level in levels
        if not array.includes(oldLevels_high, level)
            array.push(newLevels_high, level)
            array.push(oldLevels_high, level)
        
if array.size(oldLevels_high) == 0 and array.size(levels) > 0
    for level in levels
        array.push(oldLevels_high, level)
   
string message = na
if array.size(newLevels_high) > 0
    message += 'Количество касаний: ' + str.tostring(CoincidenceCount) + '\n'
    message += 'Новые high уровни: '
    for level in newLevels_high
        message += str.tostring(level) + ' '
    
    message += '\n'

if array.size(newLevels_low) > 0
    if na(message)
        message += 'Количество касаний: ' + str.tostring(CoincidenceCount) + '\n'
    message += 'Новые low уровни: '
    for level in newLevels_low
        message += str.tostring(level) + ' '

if not na(message) and barstate.islast and barstate.isconfirmed
    if strategy.opentrades > 0
        strategy.close_all(alert_message=message)
    else
        strategy.entry('new level', strategy.short, alert_message=message)

Overview

Level Search scans a configurable number of past bars to group nearby low prices within a user-defined tick deviation. When a price level achieves the minimum required number of coincidences, the script draws a dashed horizontal line on the price chart from the initial touch point to the current bar. Users can adjust settings to filter out broken levels or alter the match sensitivity.

Details

Published by

DaniilOkrug on GitHub

Code credit

icewalk, as written in the script's header

Draws

On the price chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Barsint100barsCount
Количество совпаденийint5CoincidenceCount
Deviationint1deviation
showRupturebooltrueshowRupture
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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated 2 days ago · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
330 stars

This strategy divides a fixed price range between an upper and a lower limit into equally spaced grid levels and plots them on the price chart. It marks a buy when price crosses down through a grid and a sell when price crosses up through a grid, using either

Strategy v5 Support & resistanceMean reversion Repaints
Updated 2 months ago · None stated GitHub repository of Grid Bot Simulator [Alorse]
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 7 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

STRG-HOLP

by harryguiacorn
220 stars

STRG-HOLP is a trading strategy that identifies High of Low Period (HOLP) and Low of High Period (LOHP) breakout setups. It tracks the lowest low or highest high over a user-defined lookback window. A long trade opens when the close breaks above the high of th

Strategy v5 BreakoutSupport & resistance
Updated 1 year ago · None stated GitHub repository of STRG-HOLP
106 stars

This script monitors opening gap conditions and breakout behavior relative to the first candle's range across up to twenty configurable stock tickers. It detects whether following bars remain inside the opening range before breaking out, displaying the status

Strategy v4 Screeners & dashboardsBreakout Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of 1St Bar GAP+BkOut Screener v2 by RM

More Support & resistance scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers