Indicator · Pine Script v4 · Own pane

Test 010 Linearity

by ricardosantos79· code credited to RicardoSantos

This experimental script calculates a custom linearity metric using rolling historical close price data stored in a fixed-size array.

View on GitHub

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

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

test-010-linearity.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-010-linearity", overlay=false)

int length = input(10)
var float[] prices = array.new_float(size=length, initial_value=open)
e = array.remove(id=prices, index=0)
array.push(id=prices, value=close)

// float[] copy = array.copy(id=prices)
// array.sort(id=copy, order=true)

float start_value = e//array.sum(id=copy) / length
float lin = 0.0
for _i = length-1 to 0
    float _a = 1 / (1 + _i)
    lin := (lin) + (array.get(id=prices, index=_i) - start_value) * _a


// plot(lin)
// plot(e)
color col = lin > 0 ? color.green : color.red
// var line li = line.new(x1=bar_index, y1=0.0, x2=bar_index, y2=0.0, extend=extend.none, width=2)
// line.set_xy1(id=li, x=bar_index[length], y=start_value)
// line.set_xy2(id=li, x=bar_index[0], y=start_value + lin)
// line.set_color(id=li, color=col)
barcolor(col)
plot(lin)//, display=display.none)

Overview

Test 010 Linearity computes a weighted sum of price differences relative to the oldest price held in the array buffer. The script plots the resulting linearity value in a separate pane and colors the price chart bars green when the metric is positive and red when negative. The main length setting adjusts the array window size.

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

Trend, Oscillators & momentum

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
lengthint10length
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

Schaff Trend Cycle

by everget
948 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 10 days ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

ADX Histogram

by harryguiacorn
219 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram
218 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite
147 stars

This indicator generates trade entry signals and target levels optimized for 1-hour timeframes, designed for external signal extraction. It calculates 7-period and 16-period EMAs alongside 10-period RSI and ATR filters. Long signals occur when the fast EMA cro

Indicator v5 TrendOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of Signal Strategy 100 Candles of 1H Timeframe

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