Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (18)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,006,800$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. 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.
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.

SettingDefaultType and rangeFeeds
ema needed?You can choose whether to include the Ema in the buy and sell conditionstrueboolshortCondition longCondition
ATR Length10intsupertrend direction
Factor3.0float · step 0.01supertrend direction
ema period200intema
length k%14intsmooth_k
smoothing k%3intsmooth_k
smoothing d%3intsmooth_d
Length12int · min 1a x x2 line 35 line 38 line 41 line 43
SmoothingSMAstring · options ["RMA", "SMA", "EMA", "WMA"]line 34 line 37 line 40
Multiplier1.5floata x x2
Src1 (no label in the script)highsourcex
Src2 (no label in the script)lowsourcex2
Show Price Linestrueboolunused
ATR Text Colorcolor.bluevalueunused
Low Text Colorcolor.tealvalueunused
High Text Colorcolor.redvalueunused
Low Line Colorcolor.tealvalueunused
High Line Colorcolor.redvalueunused

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
  • TRtruea · line 45
  • TRtruex · line 46
  • TRtruex2 · 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.

high · low · closehigh · low · closeprice datafactorFactorsetting · 3.0atrPeriodATR Lengthsetting · 10closecloseprice dataperiodema periodsetting · 200lowlowprice datahighhighprice datablength k%setting · 14dsmoothing k%setting · 3ssmoothing d%setting · 3lengthLengthsetting · 12mMultipliersetting · 1.5supertrendSupertrend→ supertrenddirectionSupertrend→ directionemaEMA→ emasmooth_kSMA / Stoch→ smooth_ksmooth_dSMA→ smooth_daTR→ axTR→ xx2TR→ x2sl_breakeven_price_activatedHighest→ sl_breakeven_price_activatedsl_breakeven_price_activated1Lowest→ sl_breakeven_price_activate…x2_valx2_valvalueg, activate_breakeven_sl_priceg · activate_breakeven_…2 valuesx_valx_valvaluek, activate_breakeven_sl_price1k · activate_breakeven_…2 valuesshortConditionshortConditionconditionlongConditionlongConditionconditionentry:sellOpen sellstrategy.entryentry:buyOpen buystrategy.entryexit:buy exitexit buy exitstrategy.exitexit:sell exitexit sell exitstrategy.exitplot:48ATR Short Stop Lossplotplot:49ATR Long Stop Lossplotplot:69takeprofit lineplotplot:70stoploss lineplotplot:71stoploss line breakevenplotplot:72takeprofit lineplotplot:73stoploss lineplotplot:74stoploss line breakevenplot

Order rules

OrderFires whenBy defaultLine
Open sell short(shortCondition) and strategy.position_size == 0On53
Open buy long(longCondition) and strategy.position_size == 0On56
Exit buy exit stop and limitstrategy.position_size > 0On66
Exit sell exit stop and limitstrategy.position_size < 0On68

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.

3/3trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+0.7%+102.5%933%1.261.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.2%+5.5%714%0.670.7%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.2%+9.8%944%4.460.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%1020%0.500.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%729%0.620.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%1010%0.240.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%40%0.000.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%1242%1.330.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.

Before 26 Dec 2025 · in-sample
Factor ↓ · ATR Length →567910121417
1.50%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%
From 26 Dec 2025 · out-of-sample
Factor ↓ · ATR Length →567910121417
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 barsTradesWonP&L
Rising market367%$18,575.30
Sideways market30%−$14,665.50
Falling market333%$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.

0%3%
All 9 trades
SideEntryExitBarsP&L
short14 Sep 2024 59,993.0023 Sep 2024 64,147.909−$4,154.91
short18 Apr 2025 84,474.7022 Apr 2025 90,894.304−$6,419.57
long5 Jun 2025 101,509.0021 Jun 2025 101,509.0016$0.00
long2 Aug 2025 112,546.0011 Aug 2025 121,780.009$9,233.57
long20 Aug 2025 114,271.0029 Aug 2025 107,800.009−$6,471.37
short4 Dec 2025 92,078.1031 Jan 2026 77,903.6058$14,174.50
short9 Apr 2026 71,788.0017 Apr 2026 76,654.108−$4,866.12
short7 Jul 2026 63,364.0019 Aug 2026 67,403.2043−$4,039.25
long11 Sep 2026 77,225.7021 Sep 2026 86,567.5010$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.

ScriptSharesTypeNetTradesMax drawdown
stoch supertrd atr 200ma this page—v5 strategy+0.7%91.4%
WOMBO COMBO- EMA & VWAP & MACD & BB & STC by MakeMoneyCoESTB2020ema sma stoch highest lowestv4 strategy−0.5%62.2%
AlignedMA and Cumulative HighLow Strategy by Trendoscopesma supertrend highest lowestv4 strategy+32.4%2234.1%
Forex bot full strategy with risk management by exlux99lowest highest ema smav4 strategy−26.4%1138.9%
Bear & Bull Zone Signal Strategy by Solutions1978ema highest lowest stoch smav4 strategyNo trades on this market
[fpemehd] SSL Baseline Strategy by DuDu95ema sma highest lowest trv5 strategy+2.3%713.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 29 msWith a workaround 1,000 bars in 84 msNot measured
PineTSNot testedNot testedNot 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