OPEN-SOURCE SCRIPT
Adaptive Supertrend MA Crossover Strategy

Adaptive Supertrend MA Crossover
Overview
This strategy trades the crossover between a Moving Average and a Supertrend line - a classic trend-following combination - but with two design choices that set it apart from the standard version of this idea already published elsewhere:
1. The Supertrend and the Moving Average each take their own independently selectable price source (Open, High, Low, Close, HL2, HLC3, OHLC4, or HLCC4), rather than both being locked to Close.
2. A new Moving Average source option: "EMA of Supertrend." Instead of feeding the MA a raw price series, this applies an EMA directly to the Supertrend line itself, and then runs your chosen MA type (SMA/EMA/HMA/WMA) on top of that smoothed line. The result is a crossover between two different "views" of the same underlying trend structure, rather than a crossover between price and trend.
Why "EMA of Supertrend" matters
A standard Supertrend line is deliberately steppy - it holds a level and jumps, rather than moving smoothly, which is what makes it useful as a stop/trend marker but also means a plain price-vs-Supertrend crossover can be noisy on choppy days (price whipsaws across a flat Supertrend step repeatedly).
Applying an EMA to the Supertrend line first produces a smoothed trend proxy that still reacts to genuine Supertrend flips, but rounds off the sharp step edges. Running your chosen Moving Average on top of that, rather than on top of price, means the crossover signal is comparing two related measures of trend, not fighting against Supertrend's inherent steppiness. This tends to produce fewer false flips in sideways conditions while still catching genuine trend changes, without adding a second unrelated indicator to the chart.
This source option is exposed directly in the settings (MA Source = "EMA of Supertrend"), with its own dedicated smoothing period, so it's a toggle away from the standard price-source approach for direct comparison on your own charts.

Caption: Chart example on GOLDPETAL, 15-min: long & short entry on the MA-Supertrend crossover.
How it works
Supertrend: calculated from your selected source (default HL2, the traditional Supertrend basis) with a configurable ATR Period and ATR Factor. Unlike TradingView's built-in Supertrend function (which is hard-coded to HL2), this version lets the basis price and the trend-flip check both use whichever source you select.
Moving Average: choose SMA, EMA, HMA (Hull), or WMA, computed on your selected source, including the "EMA of Supertrend" option described above.
Entry signal: long when the Moving Average crosses above the Supertrend line, short on the opposite cross.
Reverse Trading Mode: a single toggle that inverts the signal (useful for quickly testing whether the opposite side of a crossover performs better on a given instrument/timeframe, without rebuilding the logic).
Stop Loss / Take Profit: both optional and independently toggleable, with a shared basis switch between Percentage (of entry price) and Points, so the same settings panel works whether you're trading a low-priced or high-priced instrument.
Settings guide
(select this whole list after pasting and click the bullet-list button)
Supertrend Source - price series used for the Supertrend basis and trend-flip check
ATR Period / ATR Factor - standard Supertrend volatility inputs
MA Type - SMA / EMA / HMA / WMA
MA Source - price source, or "EMA of Supertrend"
EMA of Supertrend Period - smoothing period applied to the Supertrend line (only active when MA Source = EMA of Supertrend)
Reverse Trading Mode - inverts long/short signals
Use SL / Use TP, Basis, Values - optional exit management, Percentage or Points

Caption: Strategy Tester summary, GOLDPETAL futures, 15-min, [Jun 12, 2026 - Sep 11, 2026], default settings.
Disclaimer:
This script is a technical trading tool for educational and informational purposes. It does not constitute financial advice, and past performance in backtesting does not guarantee future results. Always test thoroughly on your own instruments and timeframes, and use appropriate risk management, before considering live use.
Overview
This strategy trades the crossover between a Moving Average and a Supertrend line - a classic trend-following combination - but with two design choices that set it apart from the standard version of this idea already published elsewhere:
1. The Supertrend and the Moving Average each take their own independently selectable price source (Open, High, Low, Close, HL2, HLC3, OHLC4, or HLCC4), rather than both being locked to Close.
2. A new Moving Average source option: "EMA of Supertrend." Instead of feeding the MA a raw price series, this applies an EMA directly to the Supertrend line itself, and then runs your chosen MA type (SMA/EMA/HMA/WMA) on top of that smoothed line. The result is a crossover between two different "views" of the same underlying trend structure, rather than a crossover between price and trend.
Why "EMA of Supertrend" matters
A standard Supertrend line is deliberately steppy - it holds a level and jumps, rather than moving smoothly, which is what makes it useful as a stop/trend marker but also means a plain price-vs-Supertrend crossover can be noisy on choppy days (price whipsaws across a flat Supertrend step repeatedly).
Applying an EMA to the Supertrend line first produces a smoothed trend proxy that still reacts to genuine Supertrend flips, but rounds off the sharp step edges. Running your chosen Moving Average on top of that, rather than on top of price, means the crossover signal is comparing two related measures of trend, not fighting against Supertrend's inherent steppiness. This tends to produce fewer false flips in sideways conditions while still catching genuine trend changes, without adding a second unrelated indicator to the chart.
This source option is exposed directly in the settings (MA Source = "EMA of Supertrend"), with its own dedicated smoothing period, so it's a toggle away from the standard price-source approach for direct comparison on your own charts.
Caption: Chart example on GOLDPETAL, 15-min: long & short entry on the MA-Supertrend crossover.
How it works
Supertrend: calculated from your selected source (default HL2, the traditional Supertrend basis) with a configurable ATR Period and ATR Factor. Unlike TradingView's built-in Supertrend function (which is hard-coded to HL2), this version lets the basis price and the trend-flip check both use whichever source you select.
Moving Average: choose SMA, EMA, HMA (Hull), or WMA, computed on your selected source, including the "EMA of Supertrend" option described above.
Entry signal: long when the Moving Average crosses above the Supertrend line, short on the opposite cross.
Reverse Trading Mode: a single toggle that inverts the signal (useful for quickly testing whether the opposite side of a crossover performs better on a given instrument/timeframe, without rebuilding the logic).
Stop Loss / Take Profit: both optional and independently toggleable, with a shared basis switch between Percentage (of entry price) and Points, so the same settings panel works whether you're trading a low-priced or high-priced instrument.
Settings guide
(select this whole list after pasting and click the bullet-list button)
Supertrend Source - price series used for the Supertrend basis and trend-flip check
ATR Period / ATR Factor - standard Supertrend volatility inputs
MA Type - SMA / EMA / HMA / WMA
MA Source - price source, or "EMA of Supertrend"
EMA of Supertrend Period - smoothing period applied to the Supertrend line (only active when MA Source = EMA of Supertrend)
Reverse Trading Mode - inverts long/short signals
Use SL / Use TP, Basis, Values - optional exit management, Percentage or Points
Caption: Strategy Tester summary, GOLDPETAL futures, 15-min, [Jun 12, 2026 - Sep 11, 2026], default settings.
Disclaimer:
This script is a technical trading tool for educational and informational purposes. It does not constitute financial advice, and past performance in backtesting does not guarantee future results. Always test thoroughly on your own instruments and timeframes, and use appropriate risk management, before considering live use.
สคริปต์แบบโอเพนซอร์ส
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์แบบโอเพนซอร์ส
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน