Pine Script v4 · Strategy
Simple Ema_ATR Strategy HulkTrading
A Pine Script v4 strategy built on EMA (close, 21) and ATR (14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 1 setting; defaults include ATR Multiplier 2.
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 Simple Ema_ATR Strategy HulkTrading repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did Simple Ema_ATR Strategy HulkTrading do on BTCUSDT 1D with default settings?
- +2.20%
- From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Simple Ema_ATR Strategy HulkTrading 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 Simple Ema_ATR Strategy HulkTrading use a stop loss?
- Yes
- strategy.exit sets a stop on line 24, 26.
- Does Simple Ema_ATR Strategy HulkTrading run in Zeal Terminal?
- Yes
- It compiles in 10 ms and runs 1,000 bars in 24 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- ATR
- ATR
- ATR
- ATR
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2.20%
- $2,199.84
- Buy and hold
- +102.5%
- same period
- Closed trades
- 14
- 7 won · 7 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 1.06
- gross profit ÷ gross loss
- Max drawdown
- 15.55%
- −$15,913.80
One run with the author's default settings, $100,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 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.
-
Note
Uses an argument v6 removed
when = on line 23, 25. The upgraded version below moves each call inside an if block.
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, abs → math.abs, atr → ta.atr.
- 2 strategy calls use the when = argument (line 23, 25). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 14 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 7: ema → ta.ema
- Line 8: ema → ta.ema
- Line 14: abs → math.abs
- Line 14: atr → ta.atr
- Line 16: abs → math.abs
5 more edits
- Line 16: atr → ta.atr
- Line 18: atr → ta.atr
- Line 19: atr → ta.atr
- Line 20: atr → ta.atr
- Line 21: atr → ta.atr
⋯// Simple EMA strategy, based on ema55+ema21 and ATR(Average True Range) and it enters a deal from ema55 when the other entry conditions are met-//@version=4+//@version=5strategy("Simple Ema_ATR Strategy HulkTrading", overlay=true)atr_multiplier = input(2, minval=1, title="ATR Multiplier") // ATR Multiplier. Recommended values between 1..4-emaFast=ema(close,21)+emaFast=ta.ema(close,21)-emaSlow=ema(close,55)+emaSlow=ta.ema(close,55)//Basically long and short conditions⋯// 3) Difference between emaFast and emaSlow must be greater than ATR(14) - for excluding flat-longCond = close < open and emaFast > emaSlow and abs(emaSlow-emaFast) > atr(14) +longCond = close < open and emaFast > emaSlow and math.abs(emaSlow-emaFast) > ta.atr(14) //For short conditions are opposite-shortCond = close > open and emaFast < emaSlow and abs(emaSlow-emaFast) > atr(14) +shortCond = close > open and emaFast < emaSlow and math.abs(emaSlow-emaFast) > ta.atr(14) //Stop levels and take profits, based on ATR multiplier-stop_level_long = strategy.position_avg_price - atr_multiplier*atr(14)+stop_level_long = strategy.position_avg_price - atr_multiplier*ta.atr(14)-take_level_long = strategy.position_avg_price + atr_multiplier*atr(14)+take_level_long = strategy.position_avg_price + atr_multiplier*ta.atr(14)-stop_level_short = strategy.position_avg_price + atr_multiplier*atr(14)+stop_level_short = strategy.position_avg_price + atr_multiplier*ta.atr(14)-take_level_short = strategy.position_avg_price - atr_multiplier*atr(14)+take_level_short = strategy.position_avg_price - atr_multiplier*ta.atr(14)//Entries and exits ⋯Same 14 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 23: when = longCond → if block
- Line 25: when = shortCond → if block
⋯strategy("Simple Ema_ATR Strategy HulkTrading", overlay=true)-atr_multiplier = input(2, minval=1, title="ATR Multiplier") // ATR Multiplier. Recommended values between 1..4+atr_multiplier = input.int(2, minval=1, title="ATR Multiplier") // ATR Multiplier. Recommended values between 1..4emaFast=ta.ema(close,21)⋯//Entries and exits -strategy.entry("Long", strategy.long, when=longCond, limit = emaSlow)+if longCond+ strategy.entry("Long", strategy.long, limit = emaSlow)strategy.exit("Stop Loss/TP","Long", stop=stop_level_long, limit = take_level_long)-strategy.entry("Short", strategy.short, when=shortCond, limit = emaSlow)+if shortCond+ strategy.entry("Short", strategy.short, limit = emaSlow)strategy.exit("Stop Loss/TP","Short", stop=stop_level_short, limit = take_level_short)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: 14 before, 16 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.
⋯// Simple EMA strategy, based on ema55+ema21 and ATR(Average True Range) and it enters a deal from ema55 when the other entry conditions are met-//@version=5+//@version=6strategy("Simple Ema_ATR Strategy HulkTrading", overlay=true)⋯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 |
|---|---|---|---|
| ATR Multiplier | 2 | int · min 1 | stop_level_long take_level_long stop_level_short take_level_short |
What it calculates
- EMA (
ema,ta.emain v5)close, 21emaFast · line 7 - EMA (
ema,ta.emain v5)close, 55emaSlow · line 8 - ATR (
atr,ta.atrin v5)14stop_level_long · line 18 - ATR (
atr,ta.atrin v5)14take_level_long · line 19 - ATR (
atr,ta.atrin v5)14stop_level_short · line 20 - ATR (
atr,ta.atrin v5)14take_level_short · line 21
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | longCondclose < open and emaFast > emaSlow and abs(emaSlow-emaFast) > atr(14) | On | 23 |
| Exit Stop Loss/TP stop and limit | every bar | On | 24 |
| Open Short short | shortCondclose > open and emaFast < emaSlow and abs(emaSlow-emaFast) > atr(14) | On | 25 |
| Exit Stop Loss/TP stop and limit | every bar | On | 26 |
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 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +2.2% | +102.5% | 14 | 50% | 1.06 | 15.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.7% | +5.5% | 13 | 38% | 0.83 | 5.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.4% | +9.8% | 12 | 42% | 0.81 | 1.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.4% | +8.4% | 13 | 77% | 3.21 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 12 | 58% | 1.17 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 10 | 80% | 5.15 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 9 | 33% | 0.90 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 11 | 55% | 0.85 | 0.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 | 5 | 80% | $15,557.30 |
| Sideways market | 6 | 33% | −$9,149.10 |
| Falling market | 3 | 33% | −$4,208.32 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
23.6%
The 95th percentile of the worst drawdown when the same 14 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 10.4% to 23.6%; the tick is what actually happened, 14.7%. Order luck alone moves it this much.
All 14 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 13 Apr 2024 62,931.10 | 1 May 2024 56,697.10 | 18 | −$6,234.03 |
| long | 11 Jun 2024 66,578.50 | 24 Jun 2024 62,960.80 | 13 | −$3,617.77 |
| short | 15 Jul 2024 62,479.50 | 19 Jul 2024 67,374.50 | 4 | −$4,895.03 |
| long | 30 Dec 2024 92,333.80 | 6 Jan 2025 99,116.60 | 7 | $6,782.79 |
| short | 2 Apr 2025 88,358.30 | 3 Apr 2025 81,420.20 | 1 | $6,938.04 |
| long | 20 Jun 2025 102,617.00 | 29 Jun 2025 108,143.00 | 9 | $5,526.21 |
| long | 2 Aug 2025 112,265.00 | 7 Aug 2025 117,588.00 | 5 | $5,323.41 |
| long | 19 Aug 2025 114,296.00 | 29 Aug 2025 107,967.00 | 10 | −$6,329.32 |
| short | 5 Jan 2026 92,163.30 | 14 Jan 2026 97,233.80 | 9 | −$5,070.44 |
| short | 13 Mar 2026 73,729.70 | 22 Mar 2026 67,860.70 | 9 | $5,869.08 |
| short | 7 Apr 2026 70,964.10 | 17 Apr 2026 75,971.00 | 10 | −$5,006.96 |
| long | 18 May 2026 76,522.10 | 29 May 2026 72,545.40 | 11 | −$3,976.69 |
| short | 15 Jul 2026 65,556.70 | 14 Aug 2026 62,825.00 | 30 | $2,731.67 |
| long | 15 Oct 2026 79,802.20 | 21 Oct 2026 83,961.10 | 6 | $4,158.88 |
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 |
|---|---|---|---|---|---|
| Simple Ema_ATR Strategy HulkTrading this page | — | v4 strategy | +2.2% | 14 | 15.6% |
| Trend Reversal - Potential pressure by BardiaB2 | atr ema | v4 strategy | +133,960.0% | 5 | 1,504.8% |
| 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% |
| Super Z strategy - Thanks to Rafael Zioni by 03.freeman | ema atr | v4 strategy | −404,823.0% | 56 | 2,951,790.0% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 10 ms | Yes 1,000 bars in 24 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not 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. 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/// © TheHulkTrading// Simple EMA strategy, based on ema55+ema21 and ATR(Average True Range) and it enters a deal from ema55 when the other entry conditions are met//@version=4strategy("Simple Ema_ATR Strategy HulkTrading", overlay=true)atr_multiplier = input(2, minval=1, title="ATR Multiplier") // ATR Multiplier. Recommended values between 1..4emaFast=ema(close,21)emaSlow=ema(close,55)//Basically long and short conditions//If long: // 1) close must be less than open (because we are searching for a pullback)// 2) emaFast(21) must be bigger than emaSlow(55) - for a trend detection// 3) Difference between emaFast and emaSlow must be greater than ATR(14) - for excluding flatlongCond = close < open and emaFast > emaSlow and abs(emaSlow-emaFast) > atr(14) //For short conditions are oppositeshortCond = close > open and emaFast < emaSlow and abs(emaSlow-emaFast) > atr(14) //Stop levels and take profits, based on ATR multiplierstop_level_long = strategy.position_avg_price - atr_multiplier*atr(14)take_level_long = strategy.position_avg_price + atr_multiplier*atr(14)stop_level_short = strategy.position_avg_price + atr_multiplier*atr(14)take_level_short = strategy.position_avg_price - atr_multiplier*atr(14)//Entries and exits strategy.entry("Long", strategy.long, when=longCond, limit = emaSlow)strategy.exit("Stop Loss/TP","Long", stop=stop_level_long, limit = take_level_long)strategy.entry("Short", strategy.short, when=shortCond, limit = emaSlow)strategy.exit("Stop Loss/TP","Short", stop=stop_level_short, limit = take_level_short)