Pine Script v4 · Strategy
Trend Reversal - Potential pressure
A Pine Script v4 strategy built on ATR (7) and EMA (close, 500). 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. It has no settings.
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 Trend Reversal - Potential pressure repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Trend Reversal - Potential pressure do on BTCUSDT 1D with default settings?
- +133,960.00%
- From 26 Jan 2024 to 21 Oct 2026, over 5 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Trend Reversal - Potential pressure 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 Trend Reversal - Potential pressure use a stop loss?
- Yes
- strategy.exit sets a stop on line 14, 17.
- Does Trend Reversal - Potential pressure run in Zeal Terminal?
- Yes
- It compiles in 19 ms and runs 1,000 bars in 24 ms, in the browser.
BTCUSDT · 1D · default settings
- ATR
- EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +133,960.00%
- $133,960,000.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 5
- 4 won · 1 lost
- Profitable
- 80.0%
- of closed trades
- Profit factor
- 3.23
- gross profit ÷ gross loss
- Max drawdown
- 1,504.80%
- −$77,192,900.00
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.
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 atr → ta.atr, ema → ta.ema.
Same 5 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 5: atr → ta.atr
- Line 6: ema → ta.ema
⋯// © BardiaB2-//@version=4+//@version=5strategy("TR", calc_on_every_tick=true)-ATR=atr(7) * 1+ATR=ta.atr(7) * 1-trendMA = ema(close, 500)+trendMA = ta.ema(close, 500)is_trend_up = close>trendMA⋯Clean v5
VerifiedNothing to change.
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: 5 before, 0 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.
⋯// © BardiaB2-//@version=5+//@version=6strategy("TR", calc_on_every_tick=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
The script declares no settings.
What it calculates
- ATR (
atr,ta.atrin v5)7ATR · line 5 - EMA (
ema,ta.emain v5)close, 500trendMA · line 6
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 LE long | is_hammer(1) and is_red(2) and is_green(0) and close>close[1] and open[1]>open and low>low[1] and is_trend_up | On | 13 |
| Exit TP/SL LE stop and limit | is_hammer(1) and is_red(2) and is_green(0) and close>close[1] and open[1]>open and low>low[1] and is_trend_up | On | 14 |
| Open SE short | is_stick(1) and is_green(2) and is_red(0) and close<close[1] and open[1]<open and high<high[1] and (not is_trend_up) | On | 16 |
| Exit TP/SL SE stop and limit | is_stick(1) and is_green(2) and is_red(0) and close<close[1] and open[1]<open and high<high[1] and (not is_trend_up) | On | 17 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- 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 | +133,960.0% | +102.5% | 5 | 80% | 3.23 | 1,504.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +32,755.3% | +5.5% | 2 | 100% | — | 5,861.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +8,133.5% | +9.8% | 3 | 100% | — | 5.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −893.2% | +8.4% | 6 | 33% | 0.60 | 2,124.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −409.2% | +16.7% | 4 | 0% | 0.00 | 409.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −31.2% | +21.5% | 4 | 50% | 0.57 | 51.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +1,344.6% | +148.3% | 3 | 67% | 5.24 | 439.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +179.6% | +17.1% | 8 | 63% | 1.42 | 117.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 67% | $56,554,700.00 |
| Sideways market | 1 | 100% | $31,598,200.00 |
| Falling market | 1 | 100% | $45,807,200.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
57.2%
The 95th percentile of the worst drawdown when the same 5 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 57.2% to 57.2%; the tick is what actually happened, 57.2%. Order luck alone moves it this much.
All 5 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 3 Jul 2024 62,135.50 | 4 Jul 2024 58,975.60 | 1 | $31,598,200.00 |
| short | 19 Dec 2024 100,204.00 | 20 Dec 2024 92,894.00 | 1 | $73,100,400.00 |
| long | 27 Jul 2025 117,920.00 | 3 Aug 2025 111,922.00 | 7 | −$59,976,100.00 |
| short | 30 Jan 2026 84,650.20 | 31 Jan 2026 80,069.40 | 1 | $45,807,200.00 |
| long | 4 Sep 2026 81,270.40 | 21 Sep 2026 85,613.40 | 17 | $43,430,400.00 |
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 |
|---|---|---|---|---|---|
| Trend Reversal - Potential pressure this page | — | 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% |
| 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 19 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/// © BardiaB2//@version=4strategy("TR", calc_on_every_tick=true)ATR=atr(7) * 1trendMA = ema(close, 500)is_trend_up = close>trendMAis_red(i) => (close[i] < open[i]) ? 1 : 0is_green(i) => is_red(i) ? 0 : 1is_hammer(i) => is_red(i) ? ((high[i]-close[i]) < (high[i]-low[i])/3 ) : ((high[i]-open[i]) < (high[i]-low[i])/3 ) is_stick(i) => is_red(i) ? ((open[i]-low[i]) < (high[i]-low[i])/3 ) : ((close[i]-low[i]) < (high[i]-low[i])/3 ) if is_hammer(1) and is_red(2) and is_green(0) and close>close[1] and open[1]>open and low>low[1] and is_trend_up strategy.entry("LE", strategy.long, 10000) strategy.exit("TP/SL LE", "LE", stop = low[1]-ATR, limit=close+(high[1]-low[1])+ATR)if is_stick(1) and is_green(2) and is_red(0) and close<close[1] and open[1]<open and high<high[1] and (not is_trend_up) strategy.entry("SE", strategy.short, 10000) strategy.exit("TP/SL SE", "SE", stop = high[1]+ATR, limit=close-(high[1]-low[1])-ATR)