Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

thailh

A Pine Script v5 strategy built on ATR (14) and EMA (close, 34). It has 0 order rules and no entry of its own. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 8 settings; defaults include ATR Movement Required 1.0, High/Low Lookback 25 and Max Zone Size (Compared to ATR) 2.5.

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 thailh repaint?
No
No repainting patterns were found in the source. The live replay was not measured: the script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script.
How did thailh do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
What alerts does thailh have?
5
[DSI] Alert!; [DSI] Resistance Alert; [DSI] Support Alert; [DSI] Resistance Breakout; and more.
Does thailh run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L127:C84: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download.
Does thailh use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • R1
  • R2
  • S1
  • S2
  • PS1
  • PS2
  • PR1
  • PR2
  • Fast MA
  • Mid MA
  • Slow MA
  • 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 (8)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$1,000,000$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.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.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

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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
ATR Movement Required1.0floatline 65 line 74
High/Low Lookback25int · step 5line 34 line 45
Max Zone Size (Compared to ATR)2.5float · step 0.5line 37 line 48
Zone Update Count Before Reset25int · step 5line 101 line 109
Draw Previous StructuretrueboolPS1 PS2 PR1 PR2
Fast MA34intfastMA
Medium MA89intmidMA
Slow MA200intslowMA

What it calculates

  • ATR14atr · line 10
  • EMAclose, Fast MA (34)fastMA · line 156
  • EMAclose, Medium MA (89)midMA · line 157
  • EMAclose, Slow MA (200)slowMA · line 158

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 dataclosecloseprice datafastMALenFast MAsetting · 34midMALenMedium MAsetting · 89slowMALenSlow MAsetting · 200openopenprice datahighhighprice datalowlowprice dataatrATR→ atrfastMAEMA→ fastMAmidMAEMA→ midMAslowMAEMA→ slowMAhighestBody, lowestBodyhighestBody · lowestBody2 valuesres1res1valueres2res2valuesup1sup1valuesup2sup2valuepreviousRes1previousRes1valuepreviousRes2previousRes2valuepreviousSup1previousSup1valuepreviousSup2previousSup2valueatrSavedatrSavedvaluepotentialR1, potentialR2, potentialS1, potentialS2potentialR1 · potential…4 valuessupCountsupCountvalueresCountresCountvaluealertResistancealertResistanceconditionalertSupportalertSupportconditionalertResistanceBOalertResistanceBOconditionalertSupportBOalertSupportBOconditionplot:125R1plotplot:126R2plotfill:Resistance ZoneResistance Zonefillplot:129S1plotplot:130S2plotfill:Support ZoneSupport Zonefillplot:133PS1plotplot:134PS2plotfill:Previous Support ZonePrevious Support Zonefillplot:137PR1plotplot:138PR2plotfill:Previous Resistance ZonePrevious Resistance Zonefillalertcondition:146[DSI] Alert!alertconditionalertcondition:147[DSI] Resistance Alertalertconditionalertcondition:148[DSI] Support Alertalertconditionalertcondition:149[DSI] Resistance Breako…alertconditionalertcondition:150[DSI] Support Breakoutalertconditionplot:160Fast MAplotplot:161Mid MAplotplot:162Slow MAplot

Order rules

The script places no orders.

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
[DSI] Alert!alertconditionDSI alert for {{ticker}}146
[DSI] Resistance AlertalertconditionPrice has entered current potential resistance zone for {{ticker}}147
[DSI] Support AlertalertconditionPrice has entered current potential support zone for {{ticker}}148
[DSI] Resistance BreakoutalertconditionPrice has broken past potential resistance zone for {{ticker}}149
[DSI] Support BreakoutalertconditionPrice has broken past potential support zone for {{ticker}}150

Does it repaint?

No

No repainting patterns in the source.

Not measuredAn engine gap, not the scriptThe script acts only when barstate.isconfirmed is true, which Zeal Terminal's engine never reports during a live replay (it does not run a bar's closing update in live mode), so the replay cannot test this script. The answer comes from the checks on the source alone.
  • 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 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

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

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
thailh this page—v5 strategy0.0%00.0%
Trend Reversal - Potential pressure by BardiaB2atr emav4 strategy+133,960.0%51,504.8%
Simple Ema_ATR Strategy HulkTrading by TheHulkTradingema atrv4 strategy+2.2%1415.6%
Keltner Breakout Strategy by Zeal Terminalema atrv5 strategy+3.5%212.3%
[EKIN] ATR Exit Strategy by ekinbasarkomurema atrv5 strategy+781.7%302,960.8%
DEMA-EMA & VOLATILITY (VAMS) by Qorbanjfema atrv4 strategy+2,833,450.0%1915,721.0%

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.

  • 5 settings use the untyped input() (line 4, 8, 152, 153, 154). 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

Not verified

Neither version placed a trade on any of the 8 markets, so there was nothing to compare.

  • Line 4: input() → input.float()
  • Line 8: input() → input.bool()
  • Line 152: input() → input.int()
  • Line 153: input() → input.int()
  • Line 154: input() → input.int()
⋯// Get user input-atrMovement = input(title='ATR Movement Required', defval=1.0)+atrMovement = input.float(title='ATR Movement Required', defval=1.0)lookback = input.int(title='High/Low Lookback', defval=25, step=5)⋯newStructureReset = input.int(title='Zone Update Count Before Reset', defval=25, step=5)-drawPreviousStructure = input(title='Draw Previous Structure', defval=true)+drawPreviousStructure = input.bool(title='Draw Previous Structure', defval=true)// Get current ATR value⋯// Input options-fastMALen = input(title='Fast MA', defval=34)+fastMALen = input.int(title='Fast MA', defval=34)-midMALen = input(title='Medium MA', defval=89)+midMALen = input.int(title='Medium MA', defval=89)-slowMALen = input(title='Slow MA', defval=200)+slowMALen = input.int(title='Slow MA', defval=200)// Calculate values⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L127:C84: 'fill' has no 'transp' parameter in Pine Script v6. Use color.new(color, transparency) instead. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

-//@version=5+//@version=6strategy(title='EMA 34, 89, 200 by thailh', overlay=true)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 51 msWith a workaround 1,000 bars in 78 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.

//@version=5strategy(title='EMA 34, 89, 200 by thailh', overlay=true)// Get user inputatrMovement = input(title='ATR Movement Required', defval=1.0)lookback = input.int(title='High/Low Lookback', defval=25, step=5)maxZoneSize = input.float(title='Max Zone Size (Compared to ATR)', defval=2.5, step=0.5)newStructureReset = input.int(title='Zone Update Count Before Reset', defval=25, step=5)drawPreviousStructure = input(title='Draw Previous Structure', defval=true)// Get current ATR valueatr = ta.atr(14)// Get highest body and lowest body for the current candlehighestBody = open > close ? open : closelowestBody = open > close ? close : open// Set up our persistent S&R variables (1 = the wick and 2 = the body)var res1 = 0.0var res2 = 0.0var sup1 = 0.0var sup2 = 0.0var lookForNewResistance = truevar lookForNewSupport = true// Set up our *previous* support & resistance variables (for drawing support-turned-resistance etc)var previousRes1 = 0.0var previousRes2 = 0.0var previousSup1 = 0.0var previousSup2 = 0.0// Set up our ATR variables (for identifying significant declines/rallies to validate S&R zones)var atrSaved = 0.0var potentialR1 = 0.0var potentialR2 = 0.0var potentialS1 = 0.0var potentialS2 = 0.0// Detect fractal swing highs for resistance// We're looking for this pattern: .|.if high[1] == ta.highest(high, lookback) and high < high[1] and lookForNewResistance    r1 = high[1]    r2 = highestBody[2] > highestBody[1] ? highestBody[2] : highestBody > highestBody[1] ? highestBody : highestBody[1]    if (r1 - r2) / atr <= maxZoneSize        lookForNewResistance := false        potentialR1 := r1        potentialR2 := r2        atrSaved := atr        atrSaved// Detect fractal swing lows for support// We're looking for this pattern: *|*if low[1] == ta.lowest(low, lookback) and low > low[1] and lookForNewSupport    s1 = low[1]    s2 = lowestBody[2] < lowestBody[1] ? lowestBody[2] : lowestBody < lowestBody[1] ? lowestBody : lowestBody[1]    if (s2 - s1) / atr <= maxZoneSize        lookForNewSupport := false        potentialS1 := s1        potentialS2 := s2        atrSaved := atr        atrSaved// Check if potential resistance zone has already been violated. If it has, reset our potential R1 & R2if close > potentialR1 and barstate.isconfirmed    potentialR1 := na    potentialR2 := na    potentialR2// Check if potential support zone has already been violated. If it has, reset our potential S1 & S2if close < potentialS1 and barstate.isconfirmed    potentialS1 := na    potentialS2 := na    potentialS2// Check if we've had a significant decline since detecting swing highif potentialR1 - low >= atrSaved * atrMovement    previousRes1 := na(previousRes1) ? potentialR1 : previousRes1  // Store previous resistance if we're not already drawing it    previousRes2 := na(previousRes2) ? potentialR2 : previousRes2    res1 := potentialR1    res2 := potentialR2    potentialR1 := na    potentialR2 := na    potentialR2// Check if we've had a significant rally since detecting swing lowif high - potentialS1 >= atrSaved * atrMovement    previousSup1 := na(previousSup1) ? potentialS1 : previousSup1  // Store previous support if we're not already drawing it    previousSup2 := na(previousSup2) ? potentialS2 : previousSup2    sup1 := potentialS1    sup2 := potentialS2    potentialS1 := na    potentialS2 := na    potentialS2// Declare support & resistance update counters // This is used for forcing a zone reset if a zone is not violated within a reasonable period of timevar supCount = 0var resCount = 0// If the previous resistance high has been violated then begin searching for a new resistance zoneif close >= res1 and barstate.isconfirmed    lookForNewResistance := true    lookForNewSupport := true    resCount := resCount + 1    resCount// If the previous support low has been violated then begin searching for a new support zoneif close <= sup1 and barstate.isconfirmed    lookForNewSupport := true    lookForNewResistance := true    supCount := supCount + 1    supCount// If our current resistance zone has been violated, store its values to draw new *potential* support zone// The idea being that once a major resistance zone is violated it often becomes future support// But we only save previous S&R if we don't already have one saved (or our zone update count exceeds newStructureReset)if close > res1 and na(previousRes1) and barstate.isconfirmed or previousRes1 == 0.0 or supCount >= newStructureReset    previousRes1 := res1    previousRes2 := res2    supCount := 0    supCount// If our current support zone has been violated, store its values to draw new *potential* resistance zone// The idea being that once a major support zone is violated it often becomes future resistance// But we only save previous S&R if we don't already have one saved (or our zone update count exceeds newStructureReset)if close < sup1 and na(previousSup1) and barstate.isconfirmed or previousSup1 == 0.0 or resCount >= newStructureReset    previousSup1 := sup1    previousSup2 := sup2    resCount := 0    resCount// If our resistance-turned-support zone has been violated, reset our saved resistance variablesif close < previousRes2 and barstate.isconfirmed    previousRes1 := na    previousRes2 := na    previousRes2// If our support-turned-resistance zone has been violated, reset our saved support variablesif close > previousSup2 and barstate.isconfirmed    previousSup1 := na    previousSup2 := na    previousSup2// Draw our current resistance zoner1 = plot(res1 == res1[1] ? res1 : na, color=close >= res1 ? color.green : color.red, style=plot.style_linebr, title='R1')r2 = plot(res1 == res1[1] ? res2 : na, color=close >= res1 ? color.green : color.red, style=plot.style_linebr, title='R2')fill(r1, r2, color=close > res1 ? color.green : color.red, title='Resistance Zone', transp=50)// Draw our current support zones1 = plot(sup1 == sup1[1] ? sup1 : na, color=close < sup1 ? color.red : color.green, style=plot.style_linebr, title='S1')s2 = plot(sup1 == sup1[1] ? sup2 : na, color=close < sup1 ? color.red : color.green, style=plot.style_linebr, title='S2')fill(s1, s2, color=close < sup1 ? color.red : color.green, title='Support Zone', transp=50)// Draw our previous support zone (turned potential resistance)ps1 = plot(previousSup1 == previousSup1[1] and previousSup1 != sup1 and drawPreviousStructure ? previousSup1 : na, color=color.new(color.red, 0), style=plot.style_linebr, title='PS1')ps2 = plot(previousSup1 == previousSup1[1] and previousSup1 != sup1 and drawPreviousStructure ? previousSup2 : na, color=color.new(color.red, 0), style=plot.style_linebr, title='PS2')fill(ps1, ps2, color=color.new(color.red, 10), title='Previous Support Zone')// Draw our previous resistance zone (turned potential support)pr1 = plot(previousRes1 == previousRes1[1] and previousRes1 != res1 and drawPreviousStructure ? previousRes1 : na, color=color.new(color.green, 0), style=plot.style_linebr, title='PR1')pr2 = plot(previousRes1 == previousRes1[1] and previousRes1 != res1 and drawPreviousStructure ? previousRes2 : na, color=color.new(color.green, 0), style=plot.style_linebr, title='PR2')fill(pr1, pr2, color=color.new(color.green, 10), title='Previous Resistance Zone')// Check alert conditionsalertResistance = high >= res2alertSupport = low <= sup2alertResistanceBO = close >= res1alertSupportBO = close <= sup1// Trigger alertsalertcondition(alertResistance or alertSupport or alertResistanceBO or alertSupportBO, title='[DSI] Alert!', message='DSI alert for {{ticker}}')alertcondition(alertResistance, title='[DSI] Resistance Alert', message='Price has entered current potential resistance zone for {{ticker}}')alertcondition(alertSupport, title='[DSI] Support Alert', message='Price has entered current potential support zone for {{ticker}}')alertcondition(alertResistanceBO, title='[DSI] Resistance Breakout', message='Price has broken past potential resistance zone for {{ticker}}')alertcondition(alertSupportBO, title='[DSI] Support Breakout', message='Price has broken past potential support zone for {{ticker}}')// Input optionsfastMALen = input(title='Fast MA', defval=34)midMALen = input(title='Medium MA', defval=89)slowMALen = input(title='Slow MA', defval=200)// Calculate valuesfastMA = ta.ema(close, fastMALen)midMA = ta.ema(close, midMALen)slowMA = ta.ema(close, slowMALen)// Plot valuesplot(series=fastMA, color=color.new(color.yellow, 0), title='Fast MA', linewidth=3, trackprice=false)plot(series=midMA, color=color.new(color.red, 0), title='Mid MA', linewidth=4, trackprice=false)plot(series=slowMA, color=color.new(color.white, 0), title='Slow MA', linewidth=5)// Highlight crossovers// longCondition = ta.crossover(ta.ema(close, 34), ta.ema(close, 200))// if longCondition//     strategy.entry('Long buy', strategy.long)// longCondition1 = ta.crossover(ta.ema(close, 34), ta.ema(close, 89))// if longCondition1//     strategy.entry('Short buy', strategy.long)// shortCondition = ta.crossunder(ta.ema(close, 34), ta.ema(close, 200))// if shortCondition//     strategy.entry('Long sell', strategy.short)// shortCondition1 = ta.crossunder(ta.ema(close, 34), ta.ema(close, 89))// if shortCondition1//     strategy.entry('Short sell', strategy.short)// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © ZenAndTheArtOfTrading / Pine Script Mastery Course// Dynamic Structure Indicator v2.0// Last Updated: 8th January, 2021