Indicator · Pine Script v5 · Own pane

Drift [DojiEmoji]

by kevinhhl· code credited to DojiEmoji

This indicator calculates market drift using logarithmic returns adjusted for variance over a configurable lookback period.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code24
Settings2inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago6 Oct 2023

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

24 lines of Pine Script v5 from Scripts/Drift.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Drift.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © DojiEmoji

//@version=5


indicator("Drift [DojiEmoji]", overlay=false)

var int len_drift = input(14, title="Lookback")
var string _repaint_mode = input.string("Off", title="Repaint mode on/off", options=["On", "Off"])
var bool repaint_mode = _repaint_mode == "On"

// @function get_drift()
// @param int n : lookback period
// @returns float drift, a value that depicts trend with +/- signs signifying up/down (respectively)
get_drift(int n) =>
    _pc = math.log(close / close[1])
    return_drift = ta.sma(_pc, len_drift) - math.pow(ta.stdev(_pc, len_drift), 2) * 0.5
    return_drift

float drift = get_drift(len_drift)
color _col = drift > 0 ? color.blue : color.red
plot(drift[repaint_mode?0:1], color=_col[repaint_mode?0:1], linewidth=2, offset=repaint_mode?0:-1)
plot(0, color=color.new(color.gray, 0)) // zeroline

Overview

Drift [DojiEmoji] measures underlying directional movement and plots a continuous line in a separate pane, colored blue when drift is positive and red when negative, alongside a zero reference line. An optional repaint setting toggles between real-time plotting on the active bar and a one-bar lag offset designed to display strictly confirmed values.

Details

Published by

kevinhhl on GitHub

Code credit

DojiEmoji, as written in the script's header

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Trend, 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.

Settings

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

SettingTypeDefaultVariable
Lookbackint14len_drift
Repaint mode on/offstringOff_repaint_mode
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 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
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

MultiIndicator

by capissimo
114 stars

MultiIndicator combines multiple technical indicators into a single separate pane to save chart space. It calculates and displays market regime detection based on ordinary least squares regression, a Holt exponential smoothing crossover, normalized RSI, ADX, a

Indicator v4 Oscillators & momentumTrend
Updated 1 year ago · None stated GitHub repository of MultiIndicator

This indicator plots an oscillator in a separate pane. It builds several SuperTrend series across a user-defined factor range and step, using ATR as the band width. On each bar it measures the distance between the close and each SuperTrend output, then groups

Indicator v5 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of AI SuperTrend Clustering Oscillator [LuxAlgo]

Choppiness Index

by mihakralj
99 stars

The script plots the Choppiness Index in a separate pane. It sums true range over a lookback and compares that sum with the highest-high to lowest-low range, then scales the result from 0 to 100. Lower readings indicate a trending market and higher readings in

Indicator v6 TrendVolatility & bands
Updated 4 weeks ago · Apache-2.0 GitHub repository of Choppiness Index

This indicator combines Chaikin Money Flow (CMF), a SuperTrend baseline, and an Average True Range (ATR) calculation inside a separate sub-pane. It calculates a standard 20-period CMF plotted as a line and colored histogram columns around a zero baseline, trac

Indicator v6 TrendVolume
Updated 6 months ago · Apache-2.0 GitHub repository of Institutional View: CMF & SuperTrend

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