Indicator · Pine Script v4 · Own pane

SpreadTrade: Distance (v.2)

by capissimo

This indicator implements a distance-based pair trading strategy applied across two timeframes of the same instrument.

View on GitHub

GitHub stars114on the repository
Pine versionv4older, still runs
Lines of code102
Settings8inputs
LicenceNone stated
Last update1 year ago7 Nov 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above. It reads the file straight from GitHub.
  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

The code stays on GitHub. The author has not published this script under an open licence, so ForexR does not show its code. Copy script reads the file straight from GitHub into your clipboard, so you can still try it on your own chart. Ask the author before reusing the code anywhere else.

Overview

SpreadTrade: Distance (v.2) calculates the spread or statistical distance between price data on the active chart and a secondary timeframe using selected metrics like Euclidean, Manhattan, or Cosine similarity. The script plots standard deviation bands around a moving average of the spread in a separate pane to identify potential mean-reverting market conditions.

Details

Published by

capissimo on GitHub

Type

Indicator, Pine Script v4

Draws

Separate pane below the chart

Category

Mean reversion

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
Price Datasourcecloseprice
2nd Time Frameint2tf
Lookback Windowint15p
Multiplier for Stdfloat1.2mult
Distance TypestringSpreaddtype
AveragingstringSMAatype
Repaint?boolfalserepnt
Show Middle Line?boolfalseusemid
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

261 stars

This indicator calculates standardized z-scores of price data across four different lookback periods (6, 14, 26, and 100). Standardizing data subtracts the moving average from the price and divides by the standard deviation. It applies a Double Exponential Mov

Indicator v5 Mean reversionVolatility & bands
99 stars

The Augmented Dickey-Fuller indicator calculates statistical stationarity and tests for unit roots in price series over a rolling window. It performs ordinary least squares regression on differenced historical price data to compute a t-statistic and an estimat

Indicator v6 Mean reversionTrend
Updated 4 weeks ago · Apache-2.0 GitHub repository of ADF - Augmented Dickey-Fuller Test
47 stars

This indicator applies the hyperbolic tangent to a chosen source series and plots the result in a separate pane. It centers the transform on a 200-bar simple moving average of that source, multiplies the deviation by a steepness factor, and maps the output int

Indicator v6 Moving averagesMean reversion
Updated 8 months ago · MIT GitHub repository of Hyperbolic Tangent (TANH)

AutoCorrelation Function

by Anderson-ALGO
9 stars

This indicator calculates sample autocorrelation across multiple lag intervals for a selected price series. It computes correlation values over a user-specified lookback period using raw prices, log returns, absolute log returns, or squared log returns. Plotte

Indicator v4 TrendMean reversion
Updated 5 years ago · None stated GitHub repository of AutoCorrelation Function

Calculates a composite carry and decay oscillator fusing impulse-autocorrelation half-life, a Hurst exponent approximation, path efficiency, and range expansion ratios. It evaluates whether an impulse is likely to persist or mean-revert, plotting the oscillato

Indicator v6 TrendOscillators & momentum
Updated yesterday · MIT GitHub repository of Market Memory & Decay Oscillator [WavesUnchained]

This indicator builds a channel from a Hull moving average of the source and an ATR scaled by a band multiplier, then normalizes price inside that channel into a 0 to 100 oscillator. It smooths the result with a weighted moving average and plots the line in a

Indicator v6 Mean reversionVolatility & bands
Updated 3 months ago · None stated GitHub repository of Radiant Mean Reversion Channels [Pineify]

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