Indicator · Pine Script v5 · On the chart

Skew Weighted Average Price (SWAP)

by jawauntb

Skew Weighted Average Price (SWAP) calculates a skew-weighted average price for nuanced analysis of price dynamics and potential trading opportunities.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code52
Settings3inputs
LicenceGPL-3.0
Last update2 years ago22 May 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

52 lines of Pine Script v5 from Skew-Weighted-Avg-Price-SWAP.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Skew-Weighted-Avg-Price-SWAP.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jawauntb


//@version=5
indicator("Skew Weighted Average Price (SWAP)", shorttitle="SWAP", overlay=true)

// Define lengths for EMAs and other parameters
SkewLength = 30
alpha = 2.0/(1.0+SkewLength)

deviation_max = 1.
deviation_min = 1.
trueRange = math.max(math.max(high - low, math.abs(high - close[1])), math.abs(low - close[1]))/close[1]

var float deviation_max_series = na
var float deviation_min_series = na

deviation_max_series := alpha*(close > close[1] ? trueRange:0) + (1.0-alpha)*nz(deviation_max_series[1])
deviation_min_series := alpha*(close < close[1] ? trueRange:0) + (1.0-alpha)*nz(deviation_min_series[1])

// Calculate skew
skew = deviation_max_series / deviation_min_series

// Define thresholds
highSkewThreshold = input(1.1, title="High skew threshold") // User can adjust these
lowSkewThreshold = input(1.05, title="Low skew threshold") // User can adjust these

// Define SWAP and its range
var float SWAP = na
var float rangeHigh = na
var float rangeLow = na
rangePercent = input(0.5, title="Range around SWAP (%)") // User can adjust this

if skew > highSkewThreshold
    SWAP := high
    rangeHigh := SWAP * (1 + rangePercent / 100)
    rangeLow := SWAP * (1 - rangePercent / 100)
else if skew < lowSkewThreshold
    SWAP := low
    rangeHigh := SWAP * (1 + rangePercent / 100)
    rangeLow := SWAP * (1 - rangePercent / 100)
else
    SWAP := close

// Plotting
p1 = plot(rangeHigh, title="SWAP High", color=color.rgb(38, 240, 223), linewidth=2, style=plot.style_linebr)
p2 = plot(SWAP, title="SWAP", color=color.rgb(12, 106, 183), linewidth=2, style=plot.style_linebr)
p3 = plot(rangeLow, title="SWAP Low", color=color.rgb(38, 240, 223), linewidth=2,  style=plot.style_linebr)

fill(p1, p2, color=color.new(#1e9066, 70), title="Upper Range")
fill(p2, p3, color=color.new(#425de6, 70), title="Lower Range")

Overview

The script determines skew by comparing smoothed positive and negative true ranges derived from price direction changes. Based on whether the skew exceeds a high threshold or falls below a low threshold, SWAP is assigned the high, low, or close price. It then plots the SWAP value and surrounding high and low bands representing a user-defined percentage range around it on the price chart. Users can modify the high and low skew thresholds as well as the range percentage. The indicator draws directly on the price chart and offers insights into price behavior without generating buy or sell signals.

Details

Published by

jawauntb on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Volatility & bands, Support & resistance, 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
High skew thresholdfloat1.1highSkewThreshold
Low skew thresholdfloat1.05lowSkewThreshold
Range around SWAP (%)float0.5rangePercent
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]

Cerebr Wave

by jerryinyang
5 stars

Cerebr Wave is an overlay indicator that combines multi-timeframe Keltner Channels with a Wave Trend oscillator to analyze market structure and momentum. It calculates higher-timeframe and lower-timeframe Keltner Channels alongside Wave Trend crossover signals

Indicator v4 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of Cerebr Wave

Cyber HUD XAU

by panzmoravylab
3 stars

Cyber HUD XAU is an overlay indicator designed for XAUUSD that combines trend, momentum, and volatility filters. It calculates fast and slow ATR ratios alongside local price ranges to detect consolidation and chop filter states. The script evaluates candle bod

Indicator v6 Volatility & bandsOscillators & momentum
Updated 3 months ago · None stated GitHub repository of Cyber HUD XAU

Setup-1

by IAMATOMIC001
3 stars

This indicator plots multiple technical analysis components directly on the price chart, including a Nadaraya-Watson envelope, pivot-based trendlines, and a kernel regression oscillator. It also renders visual overlay panels for the Relative Strength Index and

Indicator v5 TrendOscillators & momentum Repaints
Updated 12 months ago · None stated GitHub repository of Setup-1

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