What is SuperTrend V5?

SuperTrend is one of the most widely used trend-following indicators in technical analysis. Version 5 of this AmiBroker AFL is a comprehensive upgrade that combines the classic ATR-based SuperTrend calculation with a full alert system and a real-time GFX graphical dashboard overlaid directly on the price chart.

Originally developed by Rajandran R of marketcalls.in, this version adds popup window alerts with de-duplication (so you don't get spammed with repeated alerts), sound file playback, and gradient GFX data panels that display the current signal state without leaving the chart.

โœ…
This AFL is 100% free. No registration, no watermarks, no DLL dependencies. Pure AmiBroker formula code.

Technical Specifications

Default ATR Period
7
Default Multiplier
3.0
Alert System
Popup + Sound
GFX Dashboard
Yes (Overlay)
Bars Required
100,000
Futures Mode
Enabled
Initial Equity
โ‚น10,00,000
Background Color
Black (default)

How SuperTrend Works

SuperTrend calculates two dynamic bands around price using the Average True Range (ATR):

  • โ–ฒ
    Upper Band (Resistance) = MA(High, Period) + Multiplier ร— ATR(Period)
  • โ–ผ
    Lower Band (Support) = MA(Low, Period) โˆ’ Multiplier ร— ATR(Period)

When price closes above the upper band โ†’ trend flips to Bullish โ†’ Buy signal generated.
When price closes below the lower band โ†’ trend flips to Bearish โ†’ Sell signal generated.

The trailing stop adjusts dynamically with every new ATR value, widening during volatile periods and tightening in calm conditions โ€” allowing you to stay in trends longer while protecting profits.

Key Code Sections

SuperTrend-V5.afl โ€” Alert & Sound Logic
// Popup alert with de-duplication function PopupWindowEx(popupID, bodytext, captiontext, timeout, left, top) { displayText = bodytext + captiontext; if(StaticVarGetText("prevPopup"+popupID) != displayText OR StaticVarGet("prevPopupTime"+popupID) < GetSecondNum()) { StaticVarSetText("prevPopup"+popupID, displayText); StaticVarSet("prevPopupTime"+popupID, GetSecondNum() + timeout); PopupWindow(bodytext, captiontext + popupID, timeout, left, top); PlaySound("c:\\windows\\media\\ding.wav"); } } // GFX gradient data panel procedure DrawData(Text, x1, y1, x2, y2, colorFrom, colorTo) { GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo); GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16); }

Configurable Parameters

ParameterDefaultRangeDescription
ATR Period73โ€“50Lookback period for ATR calculation. Lower = more sensitive, higher = smoother.
ATR Multiplier3.01.5โ€“5.0Band width multiplier. Higher = wider stops, fewer signals.
Candle UP ColorGreenAnyBullish candle body color
Candle Down ColorRedAnyBearish candle body color
Background ColorBlackAnyChart background (black recommended for dark trading terminals)
Alert Timeout10s5โ€“60sHow long the popup alert stays on screen

Installation Instructions

Download the AFL

Click the โฌ‡ Download button above. Save SuperTrend-V5.afl to your computer.

Copy to AmiBroker Formulas Folder

Copy the file to: C:\Program Files\AmiBroker\Formulas\Custom\
Create the Custom folder if it doesn't exist.

Apply to Chart

Open AmiBroker โ†’ Right-click on chart โ†’ Insert Indicator โ†’ Navigate to Custom โ†’ SuperTrend Ver 5.0 โ†’ Click OK.

Set Timeframe

Switch to a 5-minute or 15-minute chart for intraday trading. Use Daily for positional trades. For real-time alerts, connect AmiFeeder or Amidata live data โ€” both provide identical NSE/MCX tick feeds.

Tune Parameters

Right-click chart โ†’ Parameters to adjust ATR period and multiplier. Start with defaults (7, 3.0) and optimize for your instrument.

Trading Tips & Best Practices

โš ๏ธ
SuperTrend performs best in trending markets. In sideways/range-bound conditions it can generate false signals. Always combine with a broader market view.
โœ…

Works Best When

Market is trending with clear directional bias. Use on Nifty Futures, BankNifty, MCX Gold and Crude for best results on 5-min charts.

โŒ

Avoid When

Market is in a tight range near major support/resistance. During news events, expiry days, or pre-market opening gaps that distort ATR.

๐Ÿ’ก
Pro Tip: For Nifty Options trading โ€” use SuperTrend signal direction to select call or put, then use your strike selection based on premium and time to expiry. Combine with ORB AFL for confluence entries.