Pine Script v5 · Strategy
stoch supertrd atr 200ma
A Pine Script v5 strategy built on Supertrend (3.0, 10), EMA (close, 200) and SMA or Stoch (close, high, low, b, 3). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 18 settings; defaults include ATR Length 10, Factor 3.0 and ema period 200.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does stoch supertrd atr 200ma repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 3 of 3 trades.
- How did stoch supertrd atr 200ma do on BTCUSDT 1D with default settings?
- +0.68%
- From 26 Jan 2024 to 21 Oct 2026, over 9 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does stoch supertrd atr 200ma run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 9 before, 14 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does stoch supertrd atr 200ma use a stop loss?
- Yes
- strategy.exit sets a stop on line 66, 68.
- Does stoch supertrd atr 200ma run in Zeal Terminal?
- Yes
- It compiles in 29 ms and runs 1,000 bars in 84 ms, in the browser.
BTCUSDT · 1D · default settings
- ATR Short Stop Loss
- ATR Long Stop Loss
- takeprofit line
- stoploss line
- stoploss line breakeven
- takeprofit line
- stoploss line
- stoploss line breakeven
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.68%
- $6,798.61
- Buy and hold
- +102.5%
- same period
- Closed trades
- 9
- 3 won · 5 lost
- Profitable
- 33.3%
- of closed trades
- Profit factor
- 1.26
- gross profit ÷ gross loss
- Max drawdown
- 1.37%
- −$13,658.70
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
6 settings do nothing
“Show Price Lines”, “ATR Text Color”, “Low Text Color”, “High Text Color”, “Low Line Color”, “High Line Color” are declared but never read.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog src1 (line 25), src2 (line 26) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| ema needed?You can choose whether to include the Ema in the buy and sell conditions | true | bool | shortCondition longCondition |
| ATR Length | 10 | int | supertrend direction |
| Factor | 3.0 | float · step 0.01 | supertrend direction |
| ema period | 200 | int | ema |
| length k% | 14 | int | smooth_k |
| smoothing k% | 3 | int | smooth_k |
| smoothing d% | 3 | int | smooth_d |
| Length | 12 | int · min 1 | a x x2 line 35 line 38 line 41 line 43 |
| Smoothing | SMA | string · options ["RMA", "SMA", "EMA", "WMA"] | line 34 line 37 line 40 |
| Multiplier | 1.5 | float | a x x2 |
| Src1 (no label in the script) | high | source | x |
| Src2 (no label in the script) | low | source | x2 |
| Show Price Lines | true | bool | unused |
| ATR Text Color | color.blue | value | unused |
| Low Text Color | color.teal | value | unused |
| High Text Color | color.red | value | unused |
| Low Line Color | color.teal | value | unused |
| High Line Color | color.red | value | unused |
What it calculates
- SupertrendFactor (3.0), ATR Length (10)
supertrend · line 9 - SupertrendFactor (3.0), ATR Length (10)
direction · line 9 - EMAclose, ema period (200)
ema · line 14 - SMA / Stochta.stoch(close, high, low, b), smoothing k% (3)
smooth_k · line 19 - SMAsmooth_k, smoothing d% (3)
smooth_d · line 20 - TRtrue
a · line 45 - TRtrue
x · line 46 - TRtrue
x2 · line 47 - Highesthigh, strategy.position_size == 0 ? nz(strategy.opentrades.entry_bar_index(0), 1):bar_index - strategy.opentrades.entry_bar_index(0)
sl_breakeven_price_activated · line 62 - Lowesthigh, strategy.position_size == 0 ? nz(strategy.opentrades.entry_bar_index(0), 1):bar_index - strategy.opentrades.entry_bar_index(0)
sl_breakeven_price_activated1 · line 64
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open sell short | (shortCondition) and strategy.position_size == 0 | On | 53 |
| Open buy long | (longCondition) and strategy.position_size == 0 | On | 56 |
| Exit buy exit stop and limit | strategy.position_size > 0 | On | 66 |
| Exit sell exit stop and limit | strategy.position_size < 0 | On | 68 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +0.7% | +102.5% | 9 | 33% | 1.26 | 1.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.2% | +5.5% | 7 | 14% | 0.67 | 0.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.2% | +9.8% | 9 | 44% | 4.46 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 10 | 20% | 0.50 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 7 | 29% | 0.62 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 10 | 10% | 0.24 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 4 | 0% | 0.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 12 | 42% | 1.33 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (ATR Length 5, Factor 5.1) made +2.9% before 26 Dec 2025 and −0.1% after it, worse than the defaults' +0.0% after. Tuning on the past did not carry forward. 69% of the 64 combinations made money in-sample and 59% out-of-sample.
| Factor ↓ · ATR Length → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 1.5 | 0% | 0% | 0% | 0% | 0% | 0% | 0% | 0% |
| 1.8 | −1% | −1% | 0% | 0% | 0% | 0% | 0% | 0% |
| 2.1 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | −1% |
| 2.55 | +1% | +1% | +0% | +0% | +0% | +0% | +0% | +0% |
| 3 | +2% | +2% | +1% | +1% | +1% | −0% | −0% | −0% |
| 3.6 | +2% | +2% | +2% | +2% | +2% | +2% | +2% | +2% |
| 4.2 | +2% | +2% | +2% | +2% | +2% | +2% | +2% | +2% |
| 5.1 | +3% | +3% | +3% | +3% | +3% | +3% | +3% | +3% |
| Factor ↓ · ATR Length → | 5 | 6 | 7 | 9 | 10 | 12 | 14 | 17 |
|---|---|---|---|---|---|---|---|---|
| 1.5 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +1% |
| 1.8 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +1% |
| 2.1 | +1% | +1% | +1% | +1% | +1% | +1% | +1% | +0% |
| 2.55 | +0% | +0% | +0% | +0% | +0% | +0% | +0% | +0% |
| 3 | +0% | +0% | +0% | +0% | +0% | −0% | −0% | −0% |
| 3.6 | +1% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 4.2 | −0% | −0% | −0% | −0% | −0% | −0% | −0% | −0% |
| 5.1 | −0% | −0% | −0% | −1% | −1% | −1% | −1% | −1% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 67% | $18,575.30 |
| Sideways market | 3 | 0% | −$14,665.50 |
| Falling market | 3 | 33% | $2,888.79 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
2.6%
The 95th percentile of the worst drawdown when the same 9 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.0% to 2.6%; the tick is what actually happened, 1.1%. Order luck alone moves it this much.
All 9 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 14 Sep 2024 59,993.00 | 23 Sep 2024 64,147.90 | 9 | −$4,154.91 |
| short | 18 Apr 2025 84,474.70 | 22 Apr 2025 90,894.30 | 4 | −$6,419.57 |
| long | 5 Jun 2025 101,509.00 | 21 Jun 2025 101,509.00 | 16 | $0.00 |
| long | 2 Aug 2025 112,546.00 | 11 Aug 2025 121,780.00 | 9 | $9,233.57 |
| long | 20 Aug 2025 114,271.00 | 29 Aug 2025 107,800.00 | 9 | −$6,471.37 |
| short | 4 Dec 2025 92,078.10 | 31 Jan 2026 77,903.60 | 58 | $14,174.50 |
| short | 9 Apr 2026 71,788.00 | 17 Apr 2026 76,654.10 | 8 | −$4,866.12 |
| short | 7 Jul 2026 63,364.00 | 19 Aug 2026 67,403.20 | 43 | −$4,039.25 |
| long | 11 Sep 2026 77,225.70 | 21 Sep 2026 86,567.50 | 10 | $9,341.78 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| stoch supertrd atr 200ma this page | — | v5 strategy | +0.7% | 9 | 1.4% |
| WOMBO COMBO- EMA & VWAP & MACD & BB & STC by MakeMoneyCoESTB2020 | ema sma stoch highest lowest | v4 strategy | −0.5% | 6 | 2.2% |
| AlignedMA and Cumulative HighLow Strategy by Trendoscope | sma supertrend highest lowest | v4 strategy | +32.4% | 22 | 34.1% |
| Forex bot full strategy with risk management by exlux99 | lowest highest ema sma | v4 strategy | −26.4% | 11 | 38.9% |
| Bear & Bull Zone Signal Strategy by Solutions1978 | ema highest lowest stoch sma | v4 strategy | No trades on this market | ||
| [fpemehd] SSL Baseline Strategy by DuDu95 | ema sma highest lowest tr | v5 strategy | +2.3% | 71 | 3.7% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 10 settings use the untyped input() (line 7, 24, 25, 26, 27, 28, 29, 30, 31, 32). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 9 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.int()
- Line 24: input() → input.float()
- Line 25: input() → input.source()
- Line 26: input() → input.source()
- Line 27: input() → input.bool()
- Line 28: input() → input.color()
4 more edits
- Line 29: input() → input.color()
- Line 30: input() → input.color()
- Line 31: input() → input.color()
- Line 32: input() → input.color()
⋯ema_condition = input.bool(defval=true, title="ema needed?", tooltip="You can choose whether to include the Ema in the buy and sell conditions") -atrPeriod = input(10, "ATR Length")+atrPeriod = input.int(10, "ATR Length")factor = input.float(3.0, "Factor", step = 0.01)⋯smoothing = input.string(title="Smoothing", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])-m = input(1.5, "Multiplier")+m = input.float(1.5, "Multiplier")-src1 = input(high)+src1 = input.source(high)-src2 = input(low)+src2 = input.source(low)-pline = input(true, "Show Price Lines")+pline = input.bool(true, "Show Price Lines")-col1 = input(color.blue, "ATR Text Color")+col1 = input.color(color.blue, "ATR Text Color")-col2 = input(color.teal, "Low Text Color",inline ="1")+col2 = input.color(color.teal, "Low Text Color",inline ="1")-col3 = input(color.red, "High Text Color",inline ="2")+col3 = input.color(color.red, "High Text Color",inline ="2")-collong = input(color.teal, "Low Line Color",inline ="1")+collong = input.color(color.teal, "Low Line Color",inline ="1")-colshort = input(color.red, "High Line Color",inline ="2")+colshort = input.color(color.red, "High Line Color",inline ="2")ma_function(source, length) =>⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 9 before, 14 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © araamas-//@version=5+//@version=6strategy("stoch supertrd atr 200ma", overlay=true, shorttitle="STOCH SUPTR ATR MA", process_orders_on_close=true, max_bars_back=5000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 29 ms | With a workaround 1,000 bars in 84 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © araamas//@version=5strategy("stoch supertrd atr 200ma", overlay=true, shorttitle="STOCH SUPTR ATR MA", process_orders_on_close=true, max_bars_back=5000) ema_condition = input.bool(defval=true, title="ema needed?", tooltip="You can choose whether to include the Ema in the buy and sell conditions") atrPeriod = input(10, "ATR Length")factor = input.float(3.0, "Factor", step = 0.01)[supertrend, direction] = ta.supertrend(factor, atrPeriod)// bodyMiddle = plot((open + close) / 2, display=display.none)// upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color = color.green, style=plot.style_linebr)// downTrend = plot(direction < 0? na : supertrend, "Down Trend", color = color.red, style=plot.style_linebr)period = input.int(defval=200, title="ema period")ema = ta.ema(close, period)// plot(ema, title="200 ema", color=color.yellow)b = input.int(defval=14, title="length k%")d = input.int(defval=3, title="smoothing k%")s = input.int(defval=3, title="smoothing d%")smooth_k = ta.sma(ta.stoch(close, high, low, b), d)smooth_d = ta.sma(smooth_k, s)////////////////////////////////////////////////////////////////////////////////length = input.int(title="Length", defval=12, minval=1)smoothing = input.string(title="Smoothing", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])m = input(1.5, "Multiplier")src1 = input(high)src2 = input(low)pline = input(true, "Show Price Lines")col1 = input(color.blue, "ATR Text Color")col2 = input(color.teal, "Low Text Color",inline ="1")col3 = input(color.red, "High Text Color",inline ="2")collong = input(color.teal, "Low Line Color",inline ="1")colshort = input(color.red, "High Line Color",inline ="2")ma_function(source, length) => if smoothing == "RMA" ta.rma(source, length) else if smoothing == "SMA" ta.sma(source, length) else if smoothing == "EMA" ta.ema(source, length) else ta.wma(source, length) a = ma_function(ta.tr(true), length) * mx = ma_function(ta.tr(true), length) * m + src1x2 = src2 - ma_function(ta.tr(true), length) * mp1 = plot(x, title = "ATR Short Stop Loss", color=color.blue)p2 = plot(x2, title = "ATR Long Stop Loss", color= color.blue)///////////////////////////////////////////////////////////////////////////////////////////////shortCondition = high < ema and direction == 1 and smooth_k > 80 or (ema_condition == false and direction == 1 and smooth_k > 80)if (shortCondition) and strategy.position_size == 0 strategy.entry("sell", strategy.short)longCondition = low > ema and direction == -1 and smooth_k < 20 or (ema_condition == false and direction == -1 and smooth_k < 20)if (longCondition) and strategy.position_size == 0 strategy.entry("buy", strategy.long)x2_val = x2[bar_index - strategy.opentrades.entry_bar_index(0)]g = (strategy.opentrades.entry_price(0) - x2_val) * 2 // tp for buyx_val = x[bar_index - strategy.opentrades.entry_bar_index(0)]k = (x_val - strategy.opentrades.entry_price(0)) * 2 //tp for sellactivate_breakeven_sl_price = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) - x2_val) //price to activate sl for buysl_breakeven_price_activated = ta.highest(high, strategy.position_size == 0 ? nz(strategy.opentrades.entry_bar_index(0), 1):bar_index - strategy.opentrades.entry_bar_index(0)) > activate_breakeven_sl_price ? true:false //checks if 1:1 ratio has been reachedactivate_breakeven_sl_price1 = strategy.opentrades.entry_price(0) - (x_val - strategy.opentrades.entry_price(0)) //price to activate sl for buysl_breakeven_price_activated1 = ta.lowest(high, strategy.position_size == 0 ? nz(strategy.opentrades.entry_bar_index(0), 1):bar_index - strategy.opentrades.entry_bar_index(0)) < activate_breakeven_sl_price1 ? true:false //checks if 1:1 ratio has been reachedif strategy.position_size > 0 strategy.exit(id="buy exit", from_entry="buy",limit=strategy.opentrades.entry_price(0) + g, stop=sl_breakeven_price_activated ? strategy.opentrades.entry_price(0):x2_val) if strategy.position_size < 0 strategy.exit(id="sell exit", from_entry="sell",limit=strategy.opentrades.entry_price(0) - k, stop=sl_breakeven_price_activated1 ? strategy.opentrades.entry_price(0):x_val) plot(strategy.position_size > 0 ? strategy.opentrades.entry_price(0) + g:na, color=color.green, style=plot.style_linebr, title="takeprofit line") //to plot tp line for buyplot(strategy.position_size > 0 and sl_breakeven_price_activated == false ? x2_val:na, color=color.red, style=plot.style_linebr, title="stoploss line") //to plot sl line for buyplot(sl_breakeven_price_activated and strategy.position_size > 0 ? strategy.opentrades.entry_price(0):na, color=color.maroon, style=plot.style_linebr, linewidth=2, title="stoploss line breakeven") //to plot breakeven sl for buyplot(strategy.position_size < 0 ? strategy.opentrades.entry_price(0) - k:na, color=color.green, style=plot.style_linebr, title="takeprofit line") //to plot tp line for sellplot(strategy.position_size < 0 and sl_breakeven_price_activated1 == false ? x_val:na, color=color.red, style=plot.style_linebr, title="stoploss line") //to plot sl line for sellplot(sl_breakeven_price_activated1 and strategy.position_size < 0 ? strategy.opentrades.entry_price(0):na, color=color.maroon, style=plot.style_linebr, linewidth=2, title="stoploss line breakeven") //to plot breakeven sl for sell