Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Traffic Lights Strategy

A Pine Script v4 strategy built on EMA (close, 8), Crossunder (fema, mema) and Crossover (fema, mema). It has 14 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 commits 20% of equity and pays 0.1 commission. 26 settings; defaults include Fast EMA Length 8, Medium EMA Length 14 and Slow EMA Length 16.

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 Traffic Lights Strategy repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
How did Traffic Lights Strategy do on BTCUSDT 1D with default settings?
−4.58%
From 26 Jan 2024 to 21 Oct 2026, over 29 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Traffic Lights Strategy be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Traffic Lights Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 100, 103, 109, 112, 121, 124, 130, 133.
Does Traffic Lights Strategy run in Zeal Terminal?
Yes
It compiles in 34 ms and runs 1,000 bars in 96 ms, in the browser.

BTCUSDT · 1D · default settings

  • Fast EMA
  • Medi EMA
  • Slow EMA
  • EMA Filter
  • TP Level
  • TS Level
  • TP Level
  • TS Level
  • 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 (26)
50,000100,000150,000AprJulOct2025AprJulOct2026AprJulOct$954$2,025Equity from $1,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. Zeal Terminal's engine currently reads an order side written as long = strategy.long, long = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 94, 116) so the engine trades the way the script says.
Net profit
−4.58%
−$45.79
Buy and hold
+102.5%
same period
Closed trades
29
8 won · 21 lost
Profitable
27.6%
of closed trades
Profit factor
0.76
gross profit ÷ gross loss
Max drawdown
9.70%
−$97.44

One run with the author's default settings, $1,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

    4 settings do nothing

    “============ System Conditions ============”, “============ Indicator Parameters ============”, “============LONG Profit-Loss Parameters============”, “============SHORT Profit-Loss Parameters============” are declared but never read.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses an argument v6 removed

    when = on line 96. The upgraded version below moves each call inside an if block.

  • Note

    Uses long =, which v5 renamed line 94

    long = on line 94, 116. v5 writes it as direction = strategy.long or strategy.short.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames ema → ta.ema, security → request.security, crossover → ta.crossover, crossunder → ta.crossunder, atr → ta.atr, max → math.max, min → math.min.
  • 1 strategy call uses the when = argument (line 96). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 29 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 11: //@version=4 → //@version=5
  • Line 22: input(type = input.time) → input.time()
  • Line 23: input(type = input.bool) → input.bool()
  • Line 26: input(type = input.bool) → input.bool()
  • Line 27: input(type = input.integer) → input.int()
  • Line 28: input(type = input.integer) → input.int()
32 more edits
  • Line 29: input(type = input.integer) → input.int()
  • Line 30: input(type = input.integer) → input.int()
  • Line 31: input(type = input.resolution) → input.timeframe()
  • Line 32: input(type = input.bool) → input.bool()
  • Line 36: input(type = input.float) → input.float()
  • Line 37: input(type = input.float) → input.float()
  • Line 38: input(type = input.float) → input.float()
  • Line 39: input(type = input.integer) → input.int()
  • Line 40: input(type = input.bool) → input.bool()
  • Line 44: input(type = input.float) → input.float()
  • Line 45: input(type = input.float) → input.float()
  • Line 46: input(type = input.float) → input.float()
  • Line 47: input(type = input.integer) → input.int()
  • Line 49: ema → ta.ema
  • Line 50: ema → ta.ema
  • Line 51: ema → ta.ema
  • Line 52: security → request.security
  • Line 52: ema → ta.ema
  • Line 63: crossover → ta.crossover
  • Line 63: crossover → ta.crossover
  • Line 63: crossover → ta.crossover
  • Line 64: crossunder → ta.crossunder
  • Line 64: crossunder → ta.crossunder
  • Line 64: crossunder → ta.crossunder
  • Line 65: crossunder → ta.crossunder
  • Line 66: crossover → ta.crossover
  • Line 72: atr → ta.atr
  • Line 77: max → math.max
  • Line 84: atr → ta.atr
  • Line 89: min → math.min
  • Line 94: long = strategy.long → direction = strategy.long
  • Line 116: long = strategy.short → direction = strategy.short
⋯// green < yellow < red (As the color of inverse Traffic Lights) and they are below white ema (Used as a filter for short positions)-//@version=4+//@version=5strategy(title="Trafic Lights Strategy",⋯// User Inputs-i_time         = input(defval = timestamp("28 May 2017 13:30 +0000"), title = "Start Time", type = input.time) //Starting time for Backtesting+i_time         = input.time(defval = timestamp("28 May 2017 13:30 +0000"), title = "Start Time") //Starting time for Backtesting-sep1           = input(title="============ System Conditions ============", type=input.bool, defval=false)+sep1           = input.bool(title="============ System Conditions ============", defval=false)enable_Long    = input(true, title="Enable Long Positions")   // Enable long  Positionsenable_Short   = input(true, title="Enable Short Positions") // Enable short Positions-sep2           = input(title="============ Indicator Parameters ============", type=input.bool, defval=false)+sep2           = input.bool(title="============ Indicator Parameters ============", defval=false)-f_length       = input(title="Fast EMA Length",   type=input.integer, defval=8,   minval=1) +f_length       = input.int(title="Fast EMA Length", defval=8,   minval=1) -m_length       = input(title="Medium EMA Length", type=input.integer, defval=14,   minval=1) +m_length       = input.int(title="Medium EMA Length", defval=14,   minval=1) -s_length       = input(title="Slow EMA Length",   type=input.integer, defval=16,  minval=1) +s_length       = input.int(title="Slow EMA Length", defval=16,  minval=1) -filter_L       = input(title="EMA Filter",        type=input.integer, defval=100, minval=1) +filter_L       = input.int(title="EMA Filter", defval=100, minval=1) -filterRes      = input(title="Filter Resolution", type=input.resolution, defval="D")        // ema Filter Time Frame+filterRes      = input.timeframe(title="Filter Resolution", defval="D")        // ema Filter Time Frame-sep3           = input(title="============LONG Profit-Loss Parameters============", type=input.bool, defval=false)+sep3           = input.bool(title="============LONG Profit-Loss Parameters============", defval=false)e_Long_TP      = input(true, title="Enable a Profit Level?")⋯e_Long_TS      = input(true, title="Enable a Trailing Stop?")           -long_TP_Input  = input(40.0,   title='Take Profit %',   type=input.float,   minval=0)/100+long_TP_Input  = input.float(40.0,   title='Take Profit %',   minval=0)/100-long_SL_Input  = input(1.0,   title='Stop Loss %',     type=input.float,   minval=0)/100 +long_SL_Input  = input.float(1.0,   title='Stop Loss %',   minval=0)/100 -atrLongMultip  = input(2.0,   title='ATR Multiplier',  type=input.float,   minval=0.1)   // Parameters to calculate Trailing Stop Loss+atrLongMultip  = input.float(2.0,   title='ATR Multiplier',   minval=0.1)   // Parameters to calculate Trailing Stop Loss-atrLongLength  = input(14,    title='ATR Length',      type=input.integer, minval=1)+atrLongLength  = input.int(14,    title='ATR Length', minval=1)-sep4           = input(title="============SHORT Profit-Loss Parameters============", type=input.bool, defval=false)+sep4           = input.bool(title="============SHORT Profit-Loss Parameters============", defval=false)e_Short_TP     = input(true, title="Enable a Profit Level?")⋯e_Short_TS     = input(true, title="Enable a Trailing Stop?")-short_TP_Input = input(30.0,   title='Take Profit %',   type=input.float,   minval=0)/100+short_TP_Input = input.float(30.0,   title='Take Profit %',   minval=0)/100-short_SL_Input = input(1.0,   title='Stop Loss %',     type=input.float,   minval=0)/100+short_SL_Input = input.float(1.0,   title='Stop Loss %',   minval=0)/100-atrShortMultip = input(2.0,   title='ATR Multiplier',  type=input.float,   minval=0.1)+atrShortMultip = input.float(2.0,   title='ATR Multiplier',   minval=0.1)-atrShortLength = input(14,    title='ATR Length',      type=input.integer, minval=1)+atrShortLength = input.int(14,    title='ATR Length', minval=1)// Indicators-fema   = ema(close, f_length)+fema   = ta.ema(close, f_length)-mema   = ema(close, m_length)+mema   = ta.ema(close, m_length)-sema   = ema(close, s_length)+sema   = ta.ema(close, s_length)-filter = security(syminfo.tickerid, filterRes, ema(close, filter_L))+filter = request.security(syminfo.tickerid, filterRes, ta.ema(close, filter_L))plot(fema,   title="Fast EMA",   color=color.new(color.green,  0))⋯priceEntry = strategy.position_avg_price-goLong  = fema > mema and mema > sema and fema > filter and time > i_time and enable_Long  and (crossover (fema, mema) or crossover (mema, sema) or crossover (sema, filter))+goLong  = fema > mema and mema > sema and fema > filter and time > i_time and enable_Long  and (ta.crossover (fema, mema) or ta.crossover (mema, sema) or ta.crossover (sema, filter))-goShort = fema < mema and mema < sema and fema < filter and time > i_time and enable_Short and (crossunder (fema, mema) or crossunder (mema, sema) or crossunder (sema, filter))+goShort = fema < mema and mema < sema and fema < filter and time > i_time and enable_Short and (ta.crossunder (fema, mema) or ta.crossunder (mema, sema) or ta.crossunder (sema, filter))-close_L = crossunder(fema, mema)+close_L = ta.crossunder(fema, mema)-close_S = crossover (fema, mema)+close_S = ta.crossover (fema, mema)// Profit and Loss conditions⋯long_SL = priceEntry * (1 - long_SL_Input)  // Long Position Stop Loss Calculation-atrLong = atr(atrLongLength)                // Long Position ATR Calculation+atrLong = ta.atr(atrLongLength)                // Long Position ATR Calculationlong_TS = low - atrLong * atrLongMultip⋯    longStop = long_TS-    max(long_T_stop[1], longStop)+    math.max(long_T_stop[1], longStop)else ⋯short_SL = priceEntry * (1 + short_SL_Input) // Short Position Stop Loss Calculation-atrShort = atr(atrShortLength)               // Short Position ATR Calculation+atrShort = ta.atr(atrShortLength)               // Short Position ATR Calculationshort_TS = high + atrShort * atrShortMultip⋯    shortStop  = short_TS-    min(short_T_stop[1], shortStop)+    math.min(short_T_stop[1], shortStop)else ⋯if goLong and notInTrade -    strategy.entry("Go Long", long=strategy.long, comment="Go Long", alert_message="Open Long Position")+    strategy.entry("Go Long", direction = strategy.long, comment="Go Long", alert_message="Open Long Position")if longTrade and close_L⋯if goShort and notInTrade -    strategy.entry("Go Short", long=strategy.short, comment="Go Short", alert_message="Open Short Position")+    strategy.entry("Go Short", direction = strategy.short, comment="Go Short", alert_message="Open Short Position")if shortTrade and close_S⋯

Clean v5

VerifiedDownload the v5 script

Same 29 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 24: input() → input.bool()
  • Line 25: input() → input.bool()
  • Line 33: input() → input.bool()
  • Line 34: input() → input.bool()
  • Line 35: input() → input.bool()
  • Line 41: input() → input.bool()
3 more edits
  • Line 42: input() → input.bool()
  • Line 43: input() → input.bool()
  • Line 96: when = close_L → if block
⋯sep1           = input.bool(title="============ System Conditions ============", defval=false)-enable_Long    = input(true, title="Enable Long Positions")   // Enable long  Positions+enable_Long    = input.bool(true, title="Enable Long Positions")   // Enable long  Positions-enable_Short   = input(true, title="Enable Short Positions") // Enable short Positions+enable_Short   = input.bool(true, title="Enable Short Positions") // Enable short Positionssep2           = input.bool(title="============ Indicator Parameters ============", defval=false)⋯sep3           = input.bool(title="============LONG Profit-Loss Parameters============", defval=false)-e_Long_TP      = input(true, title="Enable a Profit Level?")+e_Long_TP      = input.bool(true, title="Enable a Profit Level?")-e_Long_SL      = input(false, title="Enable a S.Loss Level?")+e_Long_SL      = input.bool(false, title="Enable a S.Loss Level?")-e_Long_TS      = input(true, title="Enable a Trailing Stop?")           +e_Long_TS      = input.bool(true, title="Enable a Trailing Stop?")           long_TP_Input  = input.float(40.0,   title='Take Profit %',   minval=0)/100⋯sep4           = input.bool(title="============SHORT Profit-Loss Parameters============", defval=false)-e_Short_TP     = input(true, title="Enable a Profit Level?")+e_Short_TP     = input.bool(true, title="Enable a Profit Level?")-e_Short_SL     = input(false, title="Enable a S.Loss Level?")+e_Short_SL     = input.bool(false, title="Enable a S.Loss Level?")-e_Short_TS     = input(true, title="Enable a Trailing Stop?")+e_Short_TS     = input.bool(true, title="Enable a Trailing Stop?")short_TP_Input = input.float(30.0,   title='Take Profit %',   minval=0)/100⋯if longTrade and close_L-    strategy.close("Go Long", when=close_L, comment="Close Long", alert_message="Close Long Position")+    if close_L+        strategy.close("Go Long", comment="Close Long", alert_message="Close Long Position")    ⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L138:C34: cannot use 'float' as a condition — Pine Script v6 does not cast 'int' or 'float' to 'bool' implicitly. Wrap it in bool(). The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// green < yellow < red (As the color of inverse Traffic Lights) and they are below white ema (Used as a filter for short positions)-//@version=5+//@version=6strategy(title="Trafic Lights Strategy",⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Start Timetimestamp("28 May 2017 13:30 +0000")timegoLong goShort
============ System Conditions ============falseboolunused
Enable Long PositionstrueboolgoLong
Enable Short PositionstrueboolgoShort
============ Indicator Parameters ============falseboolunused
Fast EMA Length8int (written input.integer) · min 1fema
Medium EMA Length14int (written input.integer) · min 1mema
Slow EMA Length16int (written input.integer) · min 1sema
EMA Filter100int (written input.integer) · min 1filter
Filter ResolutionDtimeframe (written input.resolution)filter
============LONG Profit-Loss Parameters============falseboolunused
Enable a Profit Level?trueboolline 98 line 107 TP Level
Enable a S.Loss Level?falseboolexit Long TP & TS exit Long TP & TS exit Long TP & TS exit Long TP & TS exit Long TP & TS line 99 line 102 line 108 line 111 SL Level TS Level
Enable a Trailing Stop?trueboolexit Long TP & TS exit Long TP & TS exit Long TP & TS exit Long TP & TS exit Long TP & TS line 99 line 102 line 108 line 111 SL Level TS Level
Take Profit %40.0float · min 0long_TP
Stop Loss %1.0float · min 0long_SL
ATR Multiplier2.0float · min 0.1long_TS
ATR Length14int (written input.integer) · min 1atrLong
============SHORT Profit-Loss Parameters============falseboolunused
Enable a Profit Level?trueboolline 119 line 128 TP Level
Enable a S.Loss Level?falseboolexit Short TP & TS exit Short TP & SL exit Short TP & TS exit Short TS exit Short SL line 120 line 123 line 129 line 132 SL Level TS Level
Enable a Trailing Stop?trueboolexit Short TP & TS exit Short TP & SL exit Short TP & TS exit Short TS exit Short SL line 120 line 123 line 129 line 132 SL Level TS Level
Take Profit %30.0float · min 0short_TP
Stop Loss %1.0float · min 0short_SL
ATR Multiplier2.0float · min 0.1short_TS
ATR Length14int (written input.integer) · min 1atrShort

What it calculates

  • EMA (ema, ta.ema in v5)close, Fast EMA Length (8)fema · line 49
  • EMA (ema, ta.ema in v5)close, Medium EMA Length (14)mema · line 50
  • EMA (ema, ta.ema in v5)close, Slow EMA Length (16)sema · line 51
  • EMA (ema, ta.ema in v5)close, EMA Filter (100)filter · line 52
  • Crossunder (crossunder, ta.crossunder in v5)fema, memaclose_L · line 65
  • Crossover (crossover, ta.crossover in v5)fema, memaclose_S · line 66
  • ATR (atr, ta.atr in v5)ATR Length (14)atrLong · line 72
  • ATR (atr, ta.atr in v5)ATR Length (14)atrShort · line 84

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.

The script has 63 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Go Long longgoLong and notInTradeOn94
Close Go Longclose_LOn96
Exit Long TP & TS stop and limit(e_Long_TS and not e_Long_SL)On100
Exit Long TP & TS stop and limit(e_Long_SL and not e_Long_TS)On103
Exit Long TP & TS limit(e_Long_SL and not e_Long_TS)On105
Exit Long TP & TS stop(e_Long_TS and not e_Long_SL)On109
Exit Long TP & TS stop(e_Long_SL and not e_Long_TS)On112
Open Go Short shortgoShort and notInTradeOn116
Close Go ShortshortTrade and close_SOn118
Exit Short TP & TS stop and limit(e_Short_TS and not e_Short_SL)On121
Exit Short TP & SL stop and limit(e_Short_SL and not e_Short_TS)On124
Exit Short TP & TS limit(e_Short_SL and not e_Short_TS)On126
Exit Short TS stop(e_Short_TS and not e_Short_SL)On130
Exit Short SL stop(e_Short_SL and not e_Short_TS)On133

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.

9/9trades 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 data1 security call(s), none with lookahead on.
  • 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−4.6%+102.5%2928%0.769.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.6%+5.5%2524%1.082.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+20.6%+9.8%2236%1.886.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−3.0%+8.4%3119%0.756.4%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+4.1%+16.7%3033%1.1313.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.5%+21.5%2429%1.073.6%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+2.0%+148.3%3429%1.0912.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+1.5%+17.1%2635%1.312.1%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 market633%−$19.24
Sideways market1724%−$37.75
Falling market633%$11.20

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

How bad could the drawdown be?

13.6%

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

0%16%
All 29 trades
SideEntryExitBarsP&L
long17 May 2024 65,235.2014 Jun 2024 66,773.0028$4.31
short28 Jun 2024 61,706.5015 Jul 2024 62,001.7017−$1.36
long22 Jul 2024 68,165.401 Aug 2024 62,330.9010−$17.54
short5 Aug 2024 58,161.0023 Aug 2024 63,348.3018−$17.97
short30 Aug 2024 59,359.0013 Sep 2024 59,986.5014−$2.43
long25 Sep 2024 64,262.701 Oct 2024 61,451.306−$8.81
long14 Oct 2024 62,870.004 Nov 2024 67,264.6021$12.96
long7 Jan 2025 102,236.0010 Jan 2025 92,552.503−$18.71
long17 Jan 2025 99,987.303 Feb 2025 97,700.6017−$4.72
short28 Feb 2025 84,708.602 Mar 2025 93,024.902−$18.95
short30 Mar 2025 82,648.5015 Apr 2025 84,591.6016−$4.73
long26 Apr 2025 94,638.7031 May 2025 103,154.0035$16.19
long10 Jun 2025 110,263.0018 Jun 2025 104,551.008−$10.08
long28 Jun 2025 107,048.001 Aug 2025 113,273.0034$10.40
long11 Aug 2025 119,294.0019 Aug 2025 113,284.008−$9.81
long13 Sep 2025 116,029.0024 Sep 2025 111,999.0011−$6.81
long2 Oct 2025 118,595.0010 Oct 2025 117,696.008−$1.76
short20 Oct 2025 108,643.0028 Oct 2025 114,108.008−$9.62
short30 Oct 2025 110,021.009 Dec 2025 94,413.6040$25.47
short14 Dec 2025 90,240.003 Jan 2026 89,995.1020$0.13
short24 Jan 2026 89,600.305 Feb 2026 62,720.2012$55.80
short9 Mar 2026 65,971.2011 Mar 2026 69,948.602−$12.36
short28 Mar 2026 66,407.307 Apr 2026 72,451.4010−$18.22
long27 Apr 2026 78,657.6018 May 2026 77,457.7021−$3.31
short30 May 2026 73,460.8015 Jun 2026 66,519.1016$17.72
short2 Aug 2026 62,823.708 Aug 2026 64,923.206−$6.91
short13 Aug 2026 63,480.0019 Aug 2026 65,725.206−$7.24
long22 Aug 2026 78,338.0016 Sep 2026 75,644.5025−$6.98
long19 Sep 2026 80,883.908 Oct 2026 80,857.6019−$0.44

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
Traffic Lights Strategy this page—v4 strategy−4.6%299.7%
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%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 34 msWith a workaround 1,000 bars in 96 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = strategy.long, long = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 94, 116) so the engine trades the way the script says.

“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. PineTS runs Pine Script v5 and v6 only.

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/// © maxits// 4HS Crypto Market Strategy// This strategy uses 4 ema to get Long or Short Signals// Length are: 8, 14, 16, 100// We take long positions when the order of the emas is the following:// green > yellow > red (As the color of Traffic Lights) and they are above white ema (Used as a filter for long positions)  // We take short positions when the order of the emas is the following:// green < yellow < red (As the color of inverse Traffic Lights) and they are below white ema (Used as a filter for short positions)//@version=4strategy(title="Trafic Lights Strategy",         shorttitle="TLS",         overlay=true,         initial_capital=1000,         default_qty_value=20,         default_qty_type=strategy.percent_of_equity,         commission_value=0.1,         pyramiding=0         )// User Inputsi_time         = input(defval = timestamp("28 May 2017 13:30 +0000"), title = "Start Time", type = input.time) //Starting time for Backtestingsep1           = input(title="============ System Conditions ============", type=input.bool, defval=false)enable_Long    = input(true, title="Enable Long Positions")   // Enable long  Positionsenable_Short   = input(true, title="Enable Short Positions") // Enable short Positionssep2           = input(title="============ Indicator Parameters ============", type=input.bool, defval=false)f_length       = input(title="Fast EMA Length",   type=input.integer, defval=8,   minval=1) m_length       = input(title="Medium EMA Length", type=input.integer, defval=14,   minval=1) s_length       = input(title="Slow EMA Length",   type=input.integer, defval=16,  minval=1) filter_L       = input(title="EMA Filter",        type=input.integer, defval=100, minval=1) filterRes      = input(title="Filter Resolution", type=input.resolution, defval="D")        // ema Filter Time Framesep3           = input(title="============LONG Profit-Loss Parameters============", type=input.bool, defval=false)e_Long_TP      = input(true, title="Enable a Profit Level?")e_Long_SL      = input(false, title="Enable a S.Loss Level?")e_Long_TS      = input(true, title="Enable a Trailing Stop?")           long_TP_Input  = input(40.0,   title='Take Profit %',   type=input.float,   minval=0)/100long_SL_Input  = input(1.0,   title='Stop Loss %',     type=input.float,   minval=0)/100 atrLongMultip  = input(2.0,   title='ATR Multiplier',  type=input.float,   minval=0.1)   // Parameters to calculate Trailing Stop LossatrLongLength  = input(14,    title='ATR Length',      type=input.integer, minval=1)sep4           = input(title="============SHORT Profit-Loss Parameters============", type=input.bool, defval=false)e_Short_TP     = input(true, title="Enable a Profit Level?")e_Short_SL     = input(false, title="Enable a S.Loss Level?")e_Short_TS     = input(true, title="Enable a Trailing Stop?")short_TP_Input = input(30.0,   title='Take Profit %',   type=input.float,   minval=0)/100short_SL_Input = input(1.0,   title='Stop Loss %',     type=input.float,   minval=0)/100atrShortMultip = input(2.0,   title='ATR Multiplier',  type=input.float,   minval=0.1)atrShortLength = input(14,    title='ATR Length',      type=input.integer, minval=1)// Indicatorsfema   = ema(close, f_length)mema   = ema(close, m_length)sema   = ema(close, s_length)filter = security(syminfo.tickerid, filterRes, ema(close, filter_L))plot(fema,   title="Fast EMA",   color=color.new(color.green,  0))plot(mema,   title="Medi EMA",   color=color.new(color.yellow, 0))plot(sema,   title="Slow EMA",   color=color.new(color.red,    0))plot(filter, title="EMA Filter", color=color.new(color.white,  0))// Entry ConditionslongTrade  = strategy.position_size >  0shortTrade = strategy.position_size <  0notInTrade = strategy.position_size == 0inTrade    = strategy.position_size != 0priceEntry = strategy.position_avg_pricegoLong  = fema > mema and mema > sema and fema > filter and time > i_time and enable_Long  and (crossover (fema, mema) or crossover (mema, sema) or crossover (sema, filter))goShort = fema < mema and mema < sema and fema < filter and time > i_time and enable_Short and (crossunder (fema, mema) or crossunder (mema, sema) or crossunder (sema, filter))close_L = crossunder(fema, mema)close_S = crossover (fema, mema)// Profit and Loss conditions// Long long_TP = priceEntry * (1 + long_TP_Input)  // Long Position Take Profit Calculationlong_SL = priceEntry * (1 - long_SL_Input)  // Long Position Stop Loss CalculationatrLong = atr(atrLongLength)                // Long Position ATR Calculationlong_TS = low - atrLong * atrLongMultiplong_T_stop  = 0.0                          // Code for calculating Long Positions Trailing Stop Loss/long_T_stop := if (longTrade)    longStop = long_TS    max(long_T_stop[1], longStop)else     0    //Shortshort_TP = priceEntry * (1 - short_TP_Input) // Long  Position Take Profit Calculationshort_SL = priceEntry * (1 + short_SL_Input) // Short Position Stop Loss CalculationatrShort = atr(atrShortLength)               // Short Position ATR Calculationshort_TS = high + atrShort * atrShortMultipshort_T_stop   = 0.0                // Code for calculating Short Positions Trailing Stop Loss/short_T_stop  := if shortTrade    shortStop  = short_TS    min(short_T_stop[1], shortStop)else     9999999// Strategy Long Entryif goLong and notInTrade     strategy.entry("Go Long", long=strategy.long, comment="Go Long", alert_message="Open Long Position")if longTrade and close_L    strategy.close("Go Long", when=close_L, comment="Close Long", alert_message="Close Long Position")    if e_Long_TP    // Algorithm for Enabled Long Position Profit Loss Parameters    if (e_Long_TS and not e_Long_SL)        strategy.exit("Long TP & TS", "Go Long", limit = long_TP, stop = long_T_stop)    else        if (e_Long_SL and not e_Long_TS)            strategy.exit("Long TP & TS", "Go Long",limit = long_TP, stop = long_SL)        else             strategy.exit("Long TP & TS", "Go Long",limit = long_TP)else    if not e_Long_TP         if (e_Long_TS and not e_Long_SL)            strategy.exit("Long TP & TS", "Go Long", stop = long_T_stop)        else            if (e_Long_SL and not e_Long_TS)                strategy.exit("Long TP & TS", "Go Long",stop = long_SL)    // Strategy Short Entryif goShort and notInTrade     strategy.entry("Go Short", long=strategy.short, comment="Go Short", alert_message="Open Short Position")if shortTrade and close_S    strategy.close("Go Short", comment="Close Short", alert_message="Close Short Position")if e_Short_TP   // Algorithm for Enabled Short Position Profit Loss Parameters    if (e_Short_TS and not e_Short_SL)        strategy.exit("Short TP & TS", "Go Short", limit = short_TP, stop = short_T_stop)    else        if (e_Short_SL and not e_Short_TS)            strategy.exit("Short TP & SL", "Go Short",limit = short_TP, stop = short_SL)        else             strategy.exit("Short TP & TS", "Go Short",limit = short_TP)else    if not e_Short_TP         if (e_Short_TS and not e_Short_SL)            strategy.exit("Short TS", "Go Short", stop = short_T_stop)        else            if (e_Short_SL and not e_Short_TS)                strategy.exit("Short SL", "Go Short",stop = short_SL)// Long  Position Profit and Loss Plottingplot(longTrade and e_Long_TP  and long_TP                          ? long_TP      : na, title="TP Level", color=color.green, style=plot.style_linebr, linewidth=2)plot(longTrade and e_Long_SL  and long_SL and not e_Long_TS        ? long_SL      : na, title="SL Level", color=color.red,   style=plot.style_linebr, linewidth=2)plot(longTrade and e_Long_TS  and long_T_stop and not e_Long_SL    ? long_T_stop  : na, title="TS Level", color=color.red,   style=plot.style_linebr, linewidth=2)// Short Position Profit and Loss Plottingplot(shortTrade and e_Short_TP and short_TP                        ? short_TP     : na, title="TP Level", color=color.green, style=plot.style_linebr, linewidth=2)plot(shortTrade and e_Short_SL and short_SL and not e_Short_TS     ? short_SL     : na, title="SL Level", color=color.red,   style=plot.style_linebr, linewidth=2)plot(shortTrade and e_Short_TS and short_T_stop and not e_Short_SL ? short_T_stop : na, title="TS Level", color=color.red,   style=plot.style_linebr, linewidth=2)