Indicator · Pine Script v4 · On the chart

Support and Resistance Strategy (v.2)

by capissimo

This script plots pivot-based support and resistance levels on the price chart while generating directional trade labels tagged with RSI values to measure momentum at turning points.

View on GitHub

Repaints

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

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

095-Support-and-Resistance-Strategy-(v2).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 Strategy (v.2)", '', true, precision=4, max_labels_count=200)

// Support and resistance Strategy (FX and Crypto)
// Description: This strategy uses “support” S and “resistance” R levels and MTF Candlestick (© agekara)
// See my Support and Resistance Strategy and MTF Candlestick by agekara.
// In addition, it uses rsi values at turning points to show the strength of the move.

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

//-------------------- Global Variables

var BUY = 1, var SELL = -1

//-------------------- Custom Functions

cGreen(g) => g>9?#006400:g>8?#1A741A:g>7?#338333:g>6?#4D934D:g>5?#66A266:g>4?#80B280:g>3?#99C199:g>2?#B3D1B3:g>1?#CCE0CC:#E6F0E6
cRed(g)   => g>9?#E00000:g>8?#E31A1A:g>7?#E63333:g>6?#E94D4D:g>5?#EC6666:g>4?#F08080:g>3?#F39999:g>2?#F6B3B3:g>1?#F9CCCC:#FCE6E6

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

C = hlc3[1]
R = 2 * C - low[1]
S = 2 * C - high[1]

signal = 0
signal := ohlc4 > C ? BUY : ohlc4 < C ? SELL : nz(signal[1])  

startLongTrade  = change(signal) and signal==BUY 
startShortTrade = change(signal) and signal==SELL
endLongTrade    = ohlc4 >= R 
endShortTrade   = ohlc4 <= S 

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

plot(endLongTrade    ? high : na, style=plot.style_cross,   color=cGreen(6),  title='StopBuy',  linewidth=3)
plot(endShortTrade   ? low  : na, style=plot.style_cross,   color=cRed(6),    title='StopSell', linewidth=3)

//-------------------- Marking Module

factorLength = input(14, "Factor Length")

var factorLastVal = 0.0
var factorVal = 0.

factorVal := round(rsi(close, factorLength))[1]

v = factorVal

if startLongTrade
    label.new(bar_index, low, text=tostring(v), textcolor=cGreen(10), color=color.new(color.white,100), size=size.small,
              style=label.style_label_up, yloc=yloc.belowbar)
else
    if startShortTrade
        label.new(bar_index, high, text=tostring(v), textcolor=cRed(10), color=color.new(color.white,100), size=size.small,
                  style=label.style_label_down, yloc=yloc.abovebar)

factorLastVal := factorVal

//==================== MTF Candlestick © agekara

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

show_bars = input(true, 'Show Bars?')
reso      = input("60", 'Resolution', input.resolution)

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

sec_open  = security(syminfo.tickerid, reso, open, lookahead=barmerge.lookahead_on)
sec_close = security(syminfo.tickerid, reso, close, lookahead=barmerge.lookahead_on)

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

plot_open  = plot(show_bars ? sec_open  : na, color=color.black, style=plot.style_stepline, transp=20, editable=false)
plot_close = plot(show_bars ? sec_close : na, color=color.black, style=plot.style_stepline, transp=20, editable=false)
fill(plot_open, plot_close, sec_open <= sec_close ? color.green : color.red, 75, editable=false)

//-------------------- Alerting

// alertcondition(startLongTrade,  title='Buy',  message='Go long!')
// alertcondition(startShortTrade, title='Sell', message='Go short!') 
alertcondition(startLongTrade or startShortTrade, title='Alert', message='Deal Time!')

//-------------------- Backtesting

Overview

Support and Resistance Strategy (v.2) overlays multi-timeframe open and close step lines with background fills to reflect broader trend conditions. Inputs allow users to customize the RSI factor length and the multi-timeframe resolution. Because the multi-timeframe data uses lookahead mode, historical higher-timeframe candles repaint and should be interpreted with caution on historical charts.

Details

Published by

capissimo on GitHub

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Support & resistance, Oscillators & momentum, Trend

Markets

Forex, Crypto

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
Factor Lengthint14factorLength
Show Bars?booltrueshow_bars
Resolutiontimeframe60reso
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