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
- 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
VerifiedSame 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⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Start Time | timestamp("28 May 2017 13:30 +0000") | time | goLong goShort |
| ============ System Conditions ============ | false | bool | unused |
| Enable Long Positions | true | bool | goLong |
| Enable Short Positions | true | bool | goShort |
| ============ Indicator Parameters ============ | false | bool | unused |
| Fast EMA Length | 8 | int (written input.integer) · min 1 | fema |
| Medium EMA Length | 14 | int (written input.integer) · min 1 | mema |
| Slow EMA Length | 16 | int (written input.integer) · min 1 | sema |
| EMA Filter | 100 | int (written input.integer) · min 1 | filter |
| Filter Resolution | D | timeframe (written input.resolution) | filter |
| ============LONG Profit-Loss Parameters============ | false | bool | unused |
| Enable a Profit Level? | true | bool | line 98 line 107 TP Level |
| Enable a S.Loss Level? | false | bool | exit 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? | true | bool | exit 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.0 | float · min 0 | long_TP |
| Stop Loss % | 1.0 | float · min 0 | long_SL |
| ATR Multiplier | 2.0 | float · min 0.1 | long_TS |
| ATR Length | 14 | int (written input.integer) · min 1 | atrLong |
| ============SHORT Profit-Loss Parameters============ | false | bool | unused |
| Enable a Profit Level? | true | bool | line 119 line 128 TP Level |
| Enable a S.Loss Level? | false | bool | exit 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? | true | bool | exit 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.0 | float · min 0 | short_TP |
| Stop Loss % | 1.0 | float · min 0 | short_SL |
| ATR Multiplier | 2.0 | float · min 0.1 | short_TS |
| ATR Length | 14 | int (written input.integer) · min 1 | atrShort |
What it calculates
- EMA (
ema,ta.emain v5)close, Fast EMA Length (8)fema · line 49 - EMA (
ema,ta.emain v5)close, Medium EMA Length (14)mema · line 50 - EMA (
ema,ta.emain v5)close, Slow EMA Length (16)sema · line 51 - EMA (
ema,ta.emain v5)close, EMA Filter (100)filter · line 52 - Crossunder (
crossunder,ta.crossunderin v5)fema, memaclose_L · line 65 - Crossover (
crossover,ta.crossoverin v5)fema, memaclose_S · line 66 - ATR (
atr,ta.atrin v5)ATR Length (14)atrLong · line 72 - ATR (
atr,ta.atrin 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Go Long long | goLong and notInTrade | On | 94 |
| Close Go Long | close_L | On | 96 |
| Exit Long TP & TS stop and limit | (e_Long_TS and not e_Long_SL) | On | 100 |
| Exit Long TP & TS stop and limit | (e_Long_SL and not e_Long_TS) | On | 103 |
| Exit Long TP & TS limit | (e_Long_SL and not e_Long_TS) | On | 105 |
| Exit Long TP & TS stop | (e_Long_TS and not e_Long_SL) | On | 109 |
| Exit Long TP & TS stop | (e_Long_SL and not e_Long_TS) | On | 112 |
| Open Go Short short | goShort and notInTrade | On | 116 |
| Close Go Short | shortTrade and close_S | On | 118 |
| Exit Short TP & TS stop and limit | (e_Short_TS and not e_Short_SL) | On | 121 |
| Exit Short TP & SL stop and limit | (e_Short_SL and not e_Short_TS) | On | 124 |
| Exit Short TP & TS limit | (e_Short_SL and not e_Short_TS) | On | 126 |
| Exit Short TS stop | (e_Short_TS and not e_Short_SL) | On | 130 |
| Exit Short SL stop | (e_Short_SL and not e_Short_TS) | On | 133 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | −4.6% | +102.5% | 29 | 28% | 0.76 | 9.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.6% | +5.5% | 25 | 24% | 1.08 | 2.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +20.6% | +9.8% | 22 | 36% | 1.88 | 6.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −3.0% | +8.4% | 31 | 19% | 0.75 | 6.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +4.1% | +16.7% | 30 | 33% | 1.13 | 13.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.5% | +21.5% | 24 | 29% | 1.07 | 3.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +2.0% | +148.3% | 34 | 29% | 1.09 | 12.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +1.5% | +17.1% | 26 | 35% | 1.31 | 2.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 6 | 33% | −$19.24 |
| Sideways market | 17 | 24% | −$37.75 |
| Falling market | 6 | 33% | $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.
All 29 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 May 2024 65,235.20 | 14 Jun 2024 66,773.00 | 28 | $4.31 |
| short | 28 Jun 2024 61,706.50 | 15 Jul 2024 62,001.70 | 17 | −$1.36 |
| long | 22 Jul 2024 68,165.40 | 1 Aug 2024 62,330.90 | 10 | −$17.54 |
| short | 5 Aug 2024 58,161.00 | 23 Aug 2024 63,348.30 | 18 | −$17.97 |
| short | 30 Aug 2024 59,359.00 | 13 Sep 2024 59,986.50 | 14 | −$2.43 |
| long | 25 Sep 2024 64,262.70 | 1 Oct 2024 61,451.30 | 6 | −$8.81 |
| long | 14 Oct 2024 62,870.00 | 4 Nov 2024 67,264.60 | 21 | $12.96 |
| long | 7 Jan 2025 102,236.00 | 10 Jan 2025 92,552.50 | 3 | −$18.71 |
| long | 17 Jan 2025 99,987.30 | 3 Feb 2025 97,700.60 | 17 | −$4.72 |
| short | 28 Feb 2025 84,708.60 | 2 Mar 2025 93,024.90 | 2 | −$18.95 |
| short | 30 Mar 2025 82,648.50 | 15 Apr 2025 84,591.60 | 16 | −$4.73 |
| long | 26 Apr 2025 94,638.70 | 31 May 2025 103,154.00 | 35 | $16.19 |
| long | 10 Jun 2025 110,263.00 | 18 Jun 2025 104,551.00 | 8 | −$10.08 |
| long | 28 Jun 2025 107,048.00 | 1 Aug 2025 113,273.00 | 34 | $10.40 |
| long | 11 Aug 2025 119,294.00 | 19 Aug 2025 113,284.00 | 8 | −$9.81 |
| long | 13 Sep 2025 116,029.00 | 24 Sep 2025 111,999.00 | 11 | −$6.81 |
| long | 2 Oct 2025 118,595.00 | 10 Oct 2025 117,696.00 | 8 | −$1.76 |
| short | 20 Oct 2025 108,643.00 | 28 Oct 2025 114,108.00 | 8 | −$9.62 |
| short | 30 Oct 2025 110,021.00 | 9 Dec 2025 94,413.60 | 40 | $25.47 |
| short | 14 Dec 2025 90,240.00 | 3 Jan 2026 89,995.10 | 20 | $0.13 |
| short | 24 Jan 2026 89,600.30 | 5 Feb 2026 62,720.20 | 12 | $55.80 |
| short | 9 Mar 2026 65,971.20 | 11 Mar 2026 69,948.60 | 2 | −$12.36 |
| short | 28 Mar 2026 66,407.30 | 7 Apr 2026 72,451.40 | 10 | −$18.22 |
| long | 27 Apr 2026 78,657.60 | 18 May 2026 77,457.70 | 21 | −$3.31 |
| short | 30 May 2026 73,460.80 | 15 Jun 2026 66,519.10 | 16 | $17.72 |
| short | 2 Aug 2026 62,823.70 | 8 Aug 2026 64,923.20 | 6 | −$6.91 |
| short | 13 Aug 2026 63,480.00 | 19 Aug 2026 65,725.20 | 6 | −$7.24 |
| long | 22 Aug 2026 78,338.00 | 16 Sep 2026 75,644.50 | 25 | −$6.98 |
| long | 19 Sep 2026 80,883.90 | 8 Oct 2026 80,857.60 | 19 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Traffic Lights Strategy this page | — | v4 strategy | −4.6% | 29 | 9.7% |
| Trend Reversal - Potential pressure by BardiaB2 | atr ema | v4 strategy | +133,960.0% | 5 | 1,504.8% |
| Simple Ema_ATR Strategy HulkTrading by TheHulkTrading | ema atr | v4 strategy | +2.2% | 14 | 15.6% |
| Keltner Breakout Strategy by Zeal Terminal | ema atr | v5 strategy | +3.5% | 21 | 2.3% |
| [EKIN] ATR Exit Strategy by ekinbasarkomur | ema atr | v5 strategy | +781.7% | 30 | 2,960.8% |
| DEMA-EMA & VOLATILITY (VAMS) by Qorbanjf | ema atr | v4 strategy | +2,833,450.0% | 19 | 15,721.0% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 34 ms | With a workaround 1,000 bars in 96 ms | Not measured |
| PineTS | No 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)