Indicator · Pine Script v4 · On the chart

Support and Resistance Levels

by capissimo

This indicator calculates key support and resistance levels by analyzing the first and second momentum derivatives of a Double Exponential Moving Average (DEMA).

View on GitHub

GitHub stars114on the repository
Pine versionv4older, still runs
Lines of code90
Settings3inputs
LicenceNone statedfile: MPL-2.0
Last update1 year ago7 Nov 2024

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

90 lines of Pine Script v4 from scripts/093-Support-and-Resistance-Levels.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

093-Support-and-Resistance-Levels.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © capissimo

//@version=4
study("Support and Resistance Levels", '', true)

// Detecting Support and Resistance Levels

// Description: 
// Support & Resistance levels are essential for every trader to 
// define the decision points of the markets. 
// If you are long and the market falls below the previous support level, 
// you most probably have got the wrong position and better exit.

// This script uses the first and second deviation of a curve to
// find the turning points and extremes of the price curve.

// The deviation of a curve is nothing else than the momentum of a curve
// (and inertia is another name for momentum).
// It defines the slope of the curve. If the slope of a curve is zero, 
// you have found a local extreme. The curve will change from rising to 
// falling or the other way round.

// The second deviation, or the momentum of momentum, shows you the turning 
// points of the first deviation. This is important, as at this point the 
// original curve will switch from acceleration to break mode.

// Using the logic laid out above the support&resistance indicator will show 
// the turning points of the market in a timely manner.
// Depending on level of market-smoothing it will show the long term or 
// short term turning points.

// This script first calculates the first and second deviation of 
// the smoothed market, and in a second step runs the turning point detection.

// Style tags: Trend Following, Trend Analysis
// Asset class: Equities, Futures, ETFs, Currencies and Commodities
// Dataset: FX Minutes/Hours/Days

//-------------------- Inputs

lookback  = input(21,    'Lookback Window', minval=2)
filterDMI = input(false, 'Filter DMI?')
show_chan = input(false, 'Show Channal?')

//-------------------- Logic

// 1) get positive and negative directional movements.
[pdm, mdm, _] = dmi(14, lookback)    
 
// 2) the market data is smoothed.
dema = ema(ema(close, lookback), lookback)

// 3) the momentum of the market is calculated. 
mom1 = mom(dema, round(lookback/2))    // 1st momemtum of ma

// 4) the momentum of the momentum is calculated.
mom2 = mom(mom1, round(lookback/2))    // momemtum of momemtum of ma (2nd deviation)

// 5) determine criteria
crossmomover  = crossover(mom2, 0)
crossmomunder = crossunder(mom2, 0)

ll = lowest(low,   lookback)  // lowest low before now (this hour, today, etc.)
hh = highest(high, lookback)  // highest high before now

//-------------------- Rendering

// If the second momentum crosses above zero, the first momentum will have 
// local low and the market will be in a state when the trend comes to an end.

if crossmomover       // possible low (2nd deviation is zero)
    if not filterDMI or (filterDMI and pdm>mdm)
        line.new(time-lookback, ll, time + 60 * 60 * 24 * timeframe.multiplier * lookback/2, ll, 
                 color=color.green, xloc=xloc.bar_time, style=line.style_solid, width=3)

// If the second momentum crosses below zero, the first momentum will have 
// local high and the market will be in a state when the trend comes to an end.

if crossmomunder      // possible high
    if not filterDMI or (filterDMI and pdm<mdm)
        line.new(time-lookback, hh, time + 60 * 60 * 24 * timeframe.multiplier * lookback/2, hh, 
                 color=color.red, xloc=xloc.bar_time, style=line.style_solid, width=3)

// Optionally, show channal
plot(show_chan and crossmomover  and (not filterDMI or pdm>mdm) ? ll : na, style=plot.style_stepline, color=color.green)        
plot(show_chan and crossmomunder and (not filterDMI or pdm<mdm) ? hh : na, style=plot.style_stepline, color=color.red)    

// Show double exponential MA
plot(dema)

Overview

When the second derivative (momentum of momentum) crosses zero, it identifies local turning points where market acceleration wanes. The script projects horizontal support lines in green and resistance lines in red directly on the price chart. Users can adjust the lookback window, enable a Directional Movement Index (DMI) filter to align lines with the dominant trend, or toggle a price channel display.

Details

Published by

capissimo on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance, Oscillators & momentum, Trend

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
Lookback Windowint21lookback
Filter DMI?boolfalsefilterDMI
Show Channal?boolfalseshow_chan
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

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev Lunar Sniper
14 stars

Self-Aware Trend System calculates volatility-adaptive ATR trailing bands using a Trend Quality Index engine that evaluates market efficiency, momentum persistence, and structural pivots. It plots adaptive trend bands and character-flip trend signals directly

Indicator v6 TrendVolatility & bands
Updated 2 weeks ago · MIT GitHub repository of Self-Aware Trend System [WillyAlgoTrader]

SPY 0DTE Scalper - 15min

by chris-c-thomas
14 stars

This intraday overlay establishes directional bias and high-conviction swing setups for SPY on the 15-minute timeframe. It computes a weighted confluence score combining an EMA ribbon, a 50 EMA anchor, session VWAP bands, RSI divergence, ADX, TTM Squeeze, cand

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · MIT GitHub repository of SPY 0DTE Scalper - 15min

Market Trend

by azamiftikhar1000
12 stars

Market Trend is an overlay indicator that identifies market direction and key price levels. It calculates a Relative Strength Index with Bollinger Bands to construct a 20-step color gradient reflecting momentum shifts. The script incorporates exponential movin

Indicator v4 TrendOscillators & momentum
Updated 3 years ago · None stated GitHub repository of Market Trend

BTE Acc AO SMIO

by f-cksociety
11 stars

This script provides an indicator-based backtesting engine framework that simulates trade entries, exits, and filtering directly on the price chart. It evaluates selected entry rules and multi-layered filters, including moving average trends, volume increases,

Indicator v5 TrendOscillators & momentum
Updated 4 years ago · MPL-2.0 GitHub repository of BTE Acc AO SMIO
11 stars

This overlay indicator marks volume-driven buying and selling pressure on the price chart. It compares volume with a simple moving average scaled by a volatility-based multiplier, and it uses a trend simple moving average plus RSI thresholds to color bars. Swi

Indicator v6 VolumeSupport & resistance
Updated 2 months ago · Apache-2.0 GitHub repository of Institutional Insight Indicator

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