Indicator · Pine Script v4 · Own pane

Test-020-Freq

by ricardosantos79· code credited to RicardoSantos

This indicator counts how often rounded high-low ranges appear.

View on GitHub

GitHub stars261on the repository
Pine versionv4older, still runs
Lines of code64
Settings0inputs
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

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

test-020-freq.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(title='test-020-freq')
float rounding_value = syminfo.mintick * 10

f_hl(_length)=>
    _h = high
    _l = low
    for _i = 0 to _length-1
        if high[_i] >= _h
            _h := high[_i]
        if low[_i] <= _l
            _l := low[_i]
    [_h, _l]

var int[] ranges = array.new_int(size=9999, initial_value=0)
//var float[] avgbars = array.new_float(size=9999, initial_value=0.0)
var int[] clean_ranges = array.new_int(size=0, initial_value=0)
var int[] clean_hits = array.new_int(size=0, initial_value=0)

//register the ranges as indices and its number of hits as value:
if bar_index > 100
    for _i = 1 to 100
        [_h, _l] = f_hl(_i)
        int _r = round((_h - _l) / rounding_value)
        int _hits = array.get(id=ranges, index=int(_r)) + 1
        // if i comment this block out it gives no error:
        array.set(id=ranges, index=int(_r), value=_hits)
        // register the average hits for this range
        // float _alpha = 1 / _hits
        // float _avgbars_for_this_range = array.get(id=avgbars, index=int(_r)) * (1 - _alpha) + (_i * (1 + _alpha))
        // array.set(id=avgbars, index=int(_r), value=_avgbars_for_this_range)
else
    //to avoid warning:
    //line 23: The function 'anonym_function_0' should be called on each calculation for consistency. It is recommended to extract the call from this scope.
    [_h, _l] = f_hl(0)

// filter empty ranges out:
if bar_index > 100
    clean_ranges := array.new_int(size=0, initial_value=0)
    clean_hits := array.new_int(size=0, initial_value=0)
    for _i = 9998 to 0
        _value = array.get(id=ranges, index=_i)
        if _value != 0
//line 48: Cannot call 'array.push' with arguments (id=series[array], value=const integer); available overloads: array.push(array[<array_type>], <array_type>) => void;
            array.push(id=clean_ranges, value=_i)
            array.push(id=clean_hits, value=_value)

total = array.size(id=clean_ranges)
plot(total)
// plot(array.size(id=ranges))
// int[] ranges_clean = array.copy(id=ranges)
// for _i = array.size(id=ranges_clean)-1 to 0
//     _value = array.get(id=ranges_clean, index=_i)
//     if _value == 0
//         array.remove(id=ranges_clean, index=_i)
// plot(array.size(id=ranges_clean))

// var label debug = label.new(x=bar_index, y=open, text='')
// label.set_xy(id=debug, x=bar_index, y=open)
// t = tostring(ranges)
// label.set_text(id=debug, text=t)

Overview

After the first 100 bars, it measures the highest high and lowest low for every lookback from 1 to 100 bars, converts each range into bins of ten minticks, and stores a hit count in a large integer array. It then copies only non-zero bins into two cleaned arrays and plots the number of occupied bins in a separate pane. There are no user inputs, signals, or trade rules.

Details

Published by

ricardosantos79 on GitHub

Code credit

RicardoSantos, as written in the script's header

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Volatility & bands

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.

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 indicator calculates the distribution of close-to-close percentage changes using rate of change on closing prices. It bins percentage changes into intervals of 0.25 percent increments from negative to positive values and plots a normalized cumulative hist

Indicator v4 Volatility & bands
Updated 10 days ago · GPL-3.0 GitHub repository of Close-to-Close % Change Distribution

This indicator plots a Supertrend-based trend-following setup in a separate pane and skips conditions it treats as a sideways market. A volatility range is built from an ATR value, with RMA, SMA, EMA, or WMA smoothing, or from a fixed point distance. Optional

Indicator v5 TrendVolatility & bands
Updated 1 year ago · MPL-2.0 GitHub repository of Trend Following Setup - Sideways Market Skipper
330 stars

This indicator plots candle range and open-to-close movement as percentages in a separate pane. Range is the high-low difference divided by the low, and change is the close-open difference divided by the open. Both series draw as columns. Teal columns show ran

Indicator v5 Volatility & bands
Updated 2 months ago · None stated GitHub repository of Percent & Volatility [Alorse]

Mojito v3 Strategy

by namuan
318 stars

The Mojito v3 Strategy indicator evaluates volatility term structure by calculating the ratio between front-month and second-month VIX futures contracts. It smooths this ratio using a configurable median filter and compares the result against user-defined uppe

Indicator v5 Volatility & bands
Updated 2 months ago · MIT GitHub repository of Mojito v3 Strategy

MACD-V

by harryguiacorn
219 stars

MACD-V is a volatility-normalized momentum indicator based on research by Alex Spiroglou. It calculates the standard MACD histogram and normalizes it by dividing by the Average True Range (ATR). Plotted in a separate pane as a colored histogram, it includes us

Indicator v5 Oscillators & momentumVolatility & bands
Updated 1 year ago · None stated GitHub repository of MACD-V
218 stars

This indicator detects a Bollinger Band squeeze when the bands sit inside Keltner Channels, marking low volatility. It plots red dots during a squeeze and green dots when the bands are outside, in a separate pane. An optional histogram shows momentum as the cl

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Bollinger Band Squeeze Detector

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