Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

ATR + STC + MA

A Pine Script v5 strategy built on EMA (BBB, 26), Lowest (BBBBBB, 12) and Highest (BBBBBB, 12). It has 6 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. 9 settings; defaults include Length 12, FastLength 26 and SlowLength 50.

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 ATR + STC + MA 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 ATR + STC + MA do on BTCUSDT 1D with default settings?
−1.18%
From 26 Jan 2024 to 21 Oct 2026, over 15 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does ATR + STC + MA 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: 15 before, 17 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 ATR + STC + MA use a stop loss?
Yes
strategy.exit sets a stop on line 66, 71.
Does ATR + STC + MA run in Zeal Terminal?
Yes
It compiles in 28 ms and runs 1,000 bars in 66 ms, in the browser.

BTCUSDT · 1D · default settings

  • ATR Stop
  • Moving Average
  • STC Long Signal
  • STC Short Signal
  • 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 (9)
50,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$988,227$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.
Net profit
−1.18%
−$11,773.20
Buy and hold
+102.5%
same period
Closed trades
15
7 won · 8 lost
Profitable
46.7%
of closed trades
Profit factor
0.80
gross profit ÷ gross loss
Max drawdown
3.27%
−$32,993.00

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

    1 setting does nothing

    “MA Length” is 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 nATRPeriod (line 39), nATRMultip (line 40) 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
STC
Length12intCCC CCCC DDDD DDDDD mAAAAA
FastLength26intfastMA BBBBBB mAAAAA
SlowLength50intslowMA BBBBBB mAAAAA
ATR Stops
N ATRPeriod (no label in the script)5intxATR
N ATRMultip (no label in the script)3.5floatnLoss
Moving Average
MA Length200intunused
Strategy
Take Profit ATR Multiplier2intexit Exit Long exit Exit Short
Stop Loss ATR Multiplier1intatr_stop
Close position when ATR changes colortrueboolclose Long close Short line 67 line 72

What it calculates

  • EMABBB, FastLength (26)fastMA · line 10
  • EMABBB, SlowLength (50)slowMA · line 11
  • LowestBBBBBB, Length (12)CCC · line 23
  • HighestBBBBBB, Length (12)CCCC · line 24
  • LowestDDD, Length (12)DDDD · line 27
  • HighestDDD, Length (12)DDDDD · line 28
  • ATRN ATRPeriod (5)xATR · line 41
  • SMAclose, 200ma · line 51

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.

BBBBFastLengthsetting · 26BBBBBSlowLengthsetting · 50EEEEEELengthsetting · 12high · low · closehigh · low · closeprice datanATRPeriodN ATRPeriodsetting · 5closecloseprice datanATRMultipN ATRMultipsetting · 3.5sl_multStop Loss ATR Multipliersetting · 1fastMAEMA→ fastMAslowMAEMA→ slowMACCCLowest→ CCCCCCCHighest→ CCCCDDDDLowest→ DDDDDDDDDHighest→ DDDDDxATRATR→ xATRmaSMA→ maAAAAAAAAvalueCCCCCCCCCCvalueDDDDDDvalueDDDDDDDDDDDDvalueEEEEEEEEEEvalueBBBBBBBBBBBBvaluemAAAAAmAAAAAvaluestcstcvaluestc_sigstc_sigvaluenLossnLossvaluexATRTrailingStopxATRTrailingStopvalueposposvalueatr_sigatr_sigvaluema_sigma_sigvaluelongConditionlongConditionconditionshortConditionshortConditionconditionstc_long, stc_shortstc_long · stc_short2 conditionsatr_stopatr_stopconditionatr_color, ma_color, stc_colorColouratr_color · ma_color +1entry:LongOpen Longstrategy.entryexit:Exit Longexit Exit Longstrategy.exitclose:LongClose Longstrategy.closeentry:ShortOpen Shortstrategy.entryexit:Exit Shortexit Exit Shortstrategy.exitclose:ShortClose Shortstrategy.closeplot:77ATR Stopplotplot:79Moving Averageplotplotshape:81STC Long Signalplotshapeplotshape:82STC Short Signalplotshape

Order rules

OrderFires whenBy defaultLine
Open Long long(longCondition)On65
Exit Exit Long stop and limit(longCondition)On66
Close Longatr_sig == false and early_stopOn68
Open Short short(shortCondition)On70
Exit Exit Short stop and limit(shortCondition)On71
Close Shortatr_sig == true and early_stopOn73

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 timingOrders fill at the next bar's open, after the signal bar has closed.

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−1.2%+102.5%1547%0.803.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1.3%+5.5%1225%0.241.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.1%+9.8%1145%0.680.2%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%1656%0.960.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%1145%0.980.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%1242%1.030.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%1963%1.080.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%2167%1.360.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market560%$1,518.57
Sideways market650%$5,012.66
Falling market425%−$18,304.40

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

4.4%

The 95th percentile of the worst drawdown when the same 15 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.0% to 4.4%; the tick is what actually happened, 3.1%. Order luck alone moves it this much.

0%5%
All 15 trades
SideEntryExitBarsP&L
long5 Jun 2024 70,537.8022 Jun 2024 64,143.6017−$6,394.27
short15 Aug 2024 58,683.406 Sep 2024 53,925.5022$4,757.93
long30 Oct 2024 72,736.4011 Nov 2024 82,239.6012$9,503.17
long30 Nov 2024 97,460.0031 Dec 2024 92,792.1031−$4,667.95
long21 Feb 2025 98,305.0025 Feb 2025 91,155.004−$7,150.01
short17 Mar 2025 82,574.5022 Apr 2025 91,459.3036−$8,884.75
long10 Jun 2025 110,263.0022 Jun 2025 100,213.0012−$10,049.90
long26 Jun 2025 107,341.0010 Jul 2025 113,015.0014$5,673.99
long24 Jul 2025 118,756.0014 Aug 2025 124,128.0021$5,371.74
short31 Oct 2025 108,323.004 Nov 2025 100,429.004$7,893.98
short13 Nov 2025 101,654.0016 Nov 2025 93,471.203$8,183.20
short16 Dec 2025 86,432.1014 Jan 2026 95,414.0029−$8,981.91
short25 Feb 2026 64,058.204 Mar 2026 72,679.107−$8,620.92
short19 Jun 2026 62,958.0022 Jul 2026 66,556.1033−$3,598.14
long19 Sep 2026 80,883.9021 Sep 2026 86,074.502$5,190.67

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
ATR + STC + MA this page—v5 strategy−1.2%153.3%
-NoSKi Hammer-Star -w angle of ema Backtester - by noski1atr ema sma highest lowestv5 strategydoes not run in Zeal Terminal
LONG SAZB $ by stevenz17ema sma atr lowest highestv4 strategyNo trades on this market
MACD Strategy by maxencetajetatr highest lowest ema smav5 strategy+5.8%56.9%
DC Breakout Strategy - This is simplicity at its finest. by Robrecht99sma highest lowest atrv5 strategy+10.8%578.3%
Richard's Strategy by Deepak8369highest lowest atr emav4 strategy+34.6%7026.3%

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.

  • 9 settings use the untyped input() (line 6, 7, 8, 39, 40, 50, 55, 56, 57). 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 15 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 6: input() → input.int()
  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 39: input() → input.int()
  • Line 40: input() → input.float()
  • Line 50: input() → input.int()
3 more edits
  • Line 55: input() → input.int()
  • Line 56: input() → input.int()
  • Line 57: input() → input.bool()
⋯// STC-EEEEEE=input(12,"Length",group="STC")+EEEEEE=input.int(12,"Length",group="STC")-BBBB=input(26,"FastLength",group="STC")+BBBB=input.int(26,"FastLength",group="STC")-BBBBB=input(50,"SlowLength",group="STC")+BBBBB=input.int(50,"SlowLength",group="STC")AAAA(BBB, BBBB, BBBBB) =>⋯// ATR stops-nATRPeriod = input(5,group="ATR Stops")+nATRPeriod = input.int(5,group="ATR Stops")-nATRMultip = input(3.5,group="ATR Stops")+nATRMultip = input.float(3.5,group="ATR Stops")xATR = ta.atr(nATRPeriod)⋯// ma-ma_len = input(200, title="MA Length", group="Moving Average")+ma_len = input.int(200, title="MA Length", group="Moving Average")ma = ta.sma(close, 200)⋯// strategy entries-tp_mult = input(2, title="Take Profit ATR Multiplier", group="Strategy")+tp_mult = input.int(2, title="Take Profit ATR Multiplier", group="Strategy")-sl_mult = input(1, title="Stop Loss ATR Multiplier", group="Strategy")+sl_mult = input.int(1, title="Stop Loss ATR Multiplier", group="Strategy")-early_stop = input(true, title="Close position when ATR changes color")+early_stop = input.bool(true, title="Close position when ATR changes color")atr_stop = if close < xATRTrailingStop⋯

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: 15 before, 17 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.

⋯// © Romedius-//@version=5+//@version=6strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 28 msYes 1,000 bars in 66 msNot measured
PineTSNot testedNot testedNot measured

“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/// © Romedius//@version=5strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)// STCEEEEEE=input(12,"Length",group="STC")BBBB=input(26,"FastLength",group="STC")BBBBB=input(50,"SlowLength",group="STC")AAAA(BBB, BBBB, BBBBB) =>    fastMA = ta.ema(BBB, BBBB)    slowMA = ta.ema(BBB, BBBBB)    AAAA = fastMA - slowMA    AAAA    AAAAA(EEEEEE, BBBB, BBBBB) =>     //AAA=input(0.5)    var AAA = 0.5    var CCCCC = 0.0    var DDD = 0.0    var DDDDDD = 0.0    var EEEEE = 0.0    BBBBBB = AAAA(close,BBBB,BBBBB)         CCC = ta.lowest(BBBBBB, EEEEEE)    CCCC = ta.highest(BBBBBB, EEEEEE) - CCC        CCCCC := (CCCC > 0 ? ((BBBBBB - CCC) / CCCC) * 100 : nz(CCCCC[1]))     DDD := (na(DDD[1]) ? CCCCC : DDD[1] + (AAA * (CCCCC - DDD[1])))     DDDD = ta.lowest(DDD, EEEEEE)     DDDDD = ta.highest(DDD, EEEEEE) - DDDD         DDDDDD := (DDDDD > 0 ? ((DDD - DDDD) / DDDDD) * 100 : nz(DDDDDD[1]))     EEEEE := (na(EEEEE[1]) ? DDDDDD : EEEEE[1] + (AAA * (DDDDDD - EEEEE[1])))    EEEEEmAAAAA = AAAAA(EEEEEE,BBBB,BBBBB)stc = mAAAAA > mAAAAA[1] ? true : falsestc_sig = stc == true and stc[1] == false ? 1 : stc == false and stc[1] == true ? -1 : 0stc_long = stc_sig == 1stc_short = stc_sig == -1// STC end// ATR stopsnATRPeriod = input(5,group="ATR Stops")nATRMultip = input(3.5,group="ATR Stops")xATR = ta.atr(nATRPeriod)nLoss = nATRMultip * xATRxATRTrailingStop = 0.0xATRTrailingStop := close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) : close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) : close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLosspos = 0pos := close[1] < nz(xATRTrailingStop[1], 0) and close > nz(xATRTrailingStop[1], 0) ? 1 : close[1] > nz(xATRTrailingStop[1], 0) and close < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)atr_sig = pos == -1 ? false : true// ATR stops end// mama_len = input(200, title="MA Length", group="Moving Average")ma = ta.sma(close, 200)ma_sig = close < ma ? false : true// ma end// strategy entriestp_mult = input(2, title="Take Profit ATR Multiplier", group="Strategy")sl_mult = input(1, title="Stop Loss ATR Multiplier", group="Strategy")early_stop = input(true, title="Close position when ATR changes color")atr_stop = if close < xATRTrailingStop    close - (close - xATRTrailingStop) * sl_multelse    close + (xATRTrailingStop - close) * sl_multlongCondition = atr_sig == true and stc_sig == 1 and ma_sig == trueshortCondition = atr_sig == false and stc_sig == -1 and ma_sig == falseif (longCondition)    strategy.entry("Long", strategy.long)    strategy.exit("Exit Long", "Long", limit=close + xATR * tp_mult, stop=atr_stop)else if atr_sig == false and early_stop    strategy.close("Long")if (shortCondition)    strategy.entry("Short", strategy.short)    strategy.exit("Exit Short", "Short", limit=close - xATR * tp_mult, stop=atr_stop)else if atr_sig == true and early_stop    strategy.close("Short")    // plot stuffatr_color = pos == -1 ? color.red: pos == 1 ? color.green : color.blueplot(atr_stop, title="ATR Stop", color=atr_color)ma_color = ma_sig ? color.green : color.redplot(ma, title="Moving Average", color=ma_color)stc_color = stc_long ? color.green : color.redplotshape(stc_long, style=shape.triangleup, color=stc_color, title="STC Long Signal", size=size.tiny)plotshape(stc_short, style=shape.triangledown, color=stc_color, title="STC Short Signal", size=size.tiny)// plot stuff end