Indicator · Pine Script v5 · Own pane

Stocks Seasonality Gauge

by jawauntb

This indicator calculates and visualizes seasonal performance metrics in a separate pane.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code49
Settings2inputs
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

49 lines of Pine Script v5 from seasonality-gauge.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

seasonality-gauge.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("Stocks Seasonality Gauge", overlay=false, shorttitle="SSG")

// Input Parameters
lookbackYears = input.int(5, title="Lookback Years")
emaLength = input.int(9, title="EMA Length for Current Month's Performance")

// Function to calculate monthly performance for specific month and year offsets
getReturn(monthOffset, yearOffset) =>
    startPrice = request.security(syminfo.tickerid, "M", close[12 * yearOffset + monthOffset])
    endPrice = request.security(syminfo.tickerid, "M", close[12 * yearOffset + monthOffset + 1])
    (endPrice - startPrice) / startPrice

// Calculate returns for the current month over past years
currentMonthReturns = array.new_float(lookbackYears)
monthOffset = month[0] - 1  // Current month offset from the start of the year

for i = 0 to lookbackYears - 1
    array.set(currentMonthReturns, i, getReturn(monthOffset, -i))

currentMonthAvg = array.avg(currentMonthReturns)

// Calculate returns for the current year
currentYearReturns = array.new_float(12)
for i = 0 to month[0] - 1
    array.set(currentYearReturns, i, getReturn(i, 0))
currentYearAvg = array.sum(currentYearReturns) / ta.max(month[0])

// Price change percentage function
getPriceChangePercentage(period) =>
    change = (close - close[period]) / close[period]
    change

// Calculate percentage changes
threeWeekChange = getPriceChangePercentage(21)
oneWeekChange = getPriceChangePercentage(7)

// EMA calculation
currentMonthEMA = (ta.ema(threeWeekChange, emaLength) + ta.ema(oneWeekChange, emaLength)) / 2

// Plotting
hline(0, "0% Change", color=color.rgb(237, 255, 170), linewidth=1, linestyle=hline.style_dashed)
plot(currentMonthAvg, color=color.rgb(241, 103, 106), linewidth=2, title="Avg Performance This Month Over Last 5 Years")
plot(currentYearAvg, color=color.rgb(79, 226, 101), linewidth=3, title="Avg Monthly Performance Year to Date")
plot(currentMonthEMA, color=color.rgb(55, 245, 255), linewidth=4, title="EMA of Current Months Performance")

Overview

Stocks Seasonality Gauge queries higher-timeframe monthly closes to compute the average return of the current calendar month across a user-defined lookback window, alongside the year-to-date average monthly performance. It also tracks short-term momentum by averaging smoothed one-week and three-week percentage price changes using an exponential moving average. Main settings allow customization of the lookback years and EMA length. Higher-timeframe monthly values update dynamically on unconfirmed live monthly bars.

Details

Published by

jawauntb on GitHub

Type

Indicator, Pine Script v5

Draws

Separate pane below the chart

Category

Moving averages

Markets

Stocks

Timeframes

H4 and above

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Settings

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

SettingTypeDefaultVariable
Lookback Yearsint5lookbackYears
EMA Length for Current Month's Performanceint9emaLength
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

948 stars

The Derivative Oscillator calculates a double-exponentially smoothed Relative Strength Index (RSI) and subtracts its Simple Moving Average (SMA) to form the main oscillator line. A secondary signal line is plotted using an SMA of the main oscillator values. Th

Indicator v4 Oscillators & momentumMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Derivative Oscillator

Beep Boop

by magic8bot
409 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

MACD

by Alorse
330 stars

This indicator calculates and plots the standard Moving Average Convergence Divergence oscillator in a separate pane. It computes the difference between a fast and slow moving average, derives a signal line through smoothing, and plots a histogram representing

Indicator v4 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of MACD
318 stars

Calculates and plots moving averages on selected VIX volatility terms (VIX9D, VIX, VIX3M, or VIX6M) in a separate pane. The script computes user-defined short and long moving averages using EMA or SMA. It shades the background red when the short-term moving av

Indicator v5 Volatility & bandsMoving averages
Updated 2 months ago · MIT GitHub repository of [TVT] VIX Short Term Danger

f_push()

by ricardosantos79
261 stars

This demonstration script implements a custom FIFO array push function in Pine Script v4. It maintains a fixed-length array of closing prices by popping the oldest value and inserting the newest close at the front index. The script plots the newest price eleme

Indicator v4 Moving averages
Updated 4 years ago · None stated GitHub repository of f_push()
257 stars

Donald SPX - Options Trading is an indicator designed to assist SPX index option traders by tracking session benchmarks and multi-timeframe moving average data. It calculates a 200-period weighted moving average (WMA) and requests multi-timeframe bar data from

Indicator v5 Moving averagesScreeners & dashboards Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

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