OPEN-SOURCE SCRIPT

Moving Average Band Strategy

272
Overview

The Moving Average Band Strategy is a fully customizable breakout and trend-continuation system designed for traders who need both simplicity and control.
The strategy creates adaptive bands around a user-selected moving average and executes trades when price breaks out of these bands, with advanced risk-management settings including optional Risk:Reward targets.

This script is suitable for intraday, swing, and positional traders across all markets — equities, futures, crypto, and forex.

Key Features
✔ Six Moving Average Types

Choose the MA that best matches your trading style:

SMA

EMA

WMA

HMA

VWMA

RMA

✔ Dynamic Bands

Upper Band built from MA of highs

Lower Band built from MA of lows

Adjustable band offset (%)

Color-coded band fill indicating price position

✔ Configurable Strategy Preferences

Toggle Long and/or Short trades

Toggle Risk:Reward Take-Profit

Adjustable Risk:Reward Ratio

Default position sizing: % of equity (configurable via strategy settings)

Entry Conditions
Long Entry

A long trade triggers when:

Price crosses above the Upper Band

Long trades are enabled

No existing long position is active

Short Entry

A short trade triggers when:

Price crosses below the Lower Band

Short trades are enabled

No existing short position is active

Clear entry markers and price labels appear on the chart.

Risk Management

This strategy includes a complete set of risk-controls:

Stop-Loss (Fixed at Entry)

Long SL: Lower Band

Short SL: Upper Band

These levels remain constant for the entire trade.

Optional Risk:Reward Take-Profit

Enabled/disabled using a toggle switch.

When enabled:

Long TP = Entry + (Risk × Risk:Reward Ratio)

Short TP = Entry – (Risk × Risk:Reward Ratio)

When disabled:

Exits are handled by reverse crossover signals.

Exit Conditions
Long Exit

Stop-Loss Hit (touch-based)

Take-Profit Hit (if enabled)

Reverse Band Crossover (if TP disabled)

Short Exit

Stop-Loss Hit (touch-based)

Take-Profit Hit (if enabled)

Reverse Band Crossover (if TP disabled)

Exit markers and price labels are plotted automatically.

Visual Tools

To improve clarity:

Upper & Lower Band (blue, adjustable width)

Middle Line

Dynamic band fill (green/red/yellow)

SL & TP line plotting when in position

Entry/Exit markers

Price labels for all executed trades

These are built to help users visually follow the strategy logic.

Alerts Included

Every trading event is covered:

Long Entry

Short Entry

Long SL / TP / Cross Exit

Short SL / TP / Cross Exit

Combined Alert for webhook/automation (JSON-formatted)

Perfect for algo trading, Discord bots, or automation platforms.

Best For

This strategy performs best in:

Trending markets

Breakout environments

High-momentum instruments

Clean intraday swings

Works seamlessly on:

Stocks

Index futures

Commodities

Crypto

Forex

⚠️ Important Disclaimer

This script is for educational purposes only.
Trading involves risk. Backtest results are not indicative of future performance.
Always validate settings and use proper position sizing.

Pernyataan Penyangkalan

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.