OPEN-SOURCE SCRIPT

Supertrend + Moving Average

Supertrend indicator with a Moving Average (MA) to provide trading signals and trend analysis. Below is a detailed description of the script:

Indicator Overview
Name: Supertrend + Moving Average

Purpose: This indicator overlays the Supertrend and Moving Average on the price chart to help identify trends, potential buy/sell signals, and trend direction changes.

Overlay: The indicator is plotted directly on the price chart (overlay = true).

Inputs
Supertrend Inputs:

ATR Period: The period for calculating the Average True Range (ATR). Default is 10.

Source: The price source for Supertrend calculations. Default is hl2 (the average of high and low prices).

ATR Multiplier: A multiplier applied to the ATR to determine the Supertrend bands. Default is 3.0.

Change ATR Calculation Method: A toggle to switch between using ta.atr() or ta.sma(ta.tr) for ATR calculation. Default is true (uses ta.atr()).

Show Buy/Sell Signals: A toggle to display buy/sell signals on the chart. Default is true.

Highlighter On/Off: A toggle to enable/disable highlighting of the uptrend and downtrend areas. Default is true.

Moving Average Inputs:

MA Period: The period for the Moving Average. Default is 50.

MA Type: The type of Moving Average to use. Options are SMA (Simple Moving Average) or EMA (Exponential Moving Average). Default is SMA.

Calculations
Supertrend Calculation:

The ATR is calculated using either ta.atr() or ta.sma(ta.tr) based on the Change ATR Calculation Method input.

Upper (up) and lower (dn) bands are calculated using the formula:

up = src - Multiplier * atr

dn = src + Multiplier * atr

The trend direction is determined based on the price crossing the upper or lower bands:

trend = 1 for an uptrend.

trend = -1 for a downtrend.

Moving Average Calculation:

The Moving Average is calculated based on the selected type (SMA or EMA) and period.

Plotting
Supertrend:

The upper band (up) is plotted as a green line during an uptrend.

The lower band (dn) is plotted as a red line during a downtrend.

Buy signals are displayed as green labels or circles when the trend changes from downtrend to uptrend.

Sell signals are displayed as red labels or circles when the trend changes from uptrend to downtrend.

The background is highlighted in green during an uptrend and red during a downtrend (if highlighting is enabled).

Moving Average:

The Moving Average is plotted as a blue line on the chart.

Alert Conditions
Buy Signal: Triggers when the Supertrend changes from a downtrend to an uptrend.

Sell Signal: Triggers when the Supertrend changes from an uptrend to a downtrend.

Trend Direction Change: Triggers when the Supertrend direction changes (from uptrend to downtrend or vice versa).

Key Features
Combines Supertrend and Moving Average for enhanced trend analysis.

Customizable inputs for ATR period, multiplier, and Moving Average type/period.

Visual buy/sell signals and trend highlighting.

Alert conditions for real-time notifications.

This script is useful for traders who want to identify trends, confirm signals with a Moving Average, and receive alerts for potential trading opportunities.

Disclaimer