Pine Script v4 · Strategy
EMA Bounce Strategy
A Pine Script v4 strategy built on Lowest (10), Highest (10) and Valuewhen (bought, LL). It has 10 order rules, 8 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.04 commission. 10 settings; defaults include Strategy Direction 0, EMA Length 20 and Swing Point Loopback 10.
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 EMA Bounce Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 16 of 16 trades.
- How did EMA Bounce Strategy do on BTCUSDT 1D with default settings?
- −48.84%
- From 26 Jan 2024 to 21 Oct 2026, over 48 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can EMA Bounce 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 EMA Bounce Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 71, 72.
- Does EMA Bounce Strategy run in Zeal Terminal?
- Yes
- It compiles in 22 ms and runs 1,000 bars in 63 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- SL
- SSL
- TP
- STP
- Bullish Setup
- Bearish Setup
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −48.84%
- −$4,883.71
- Buy and hold
- +102.5%
- same period
- Closed trades
- 48
- 20 won · 28 lost
- Profitable
- 41.7%
- of closed trades
- Profit factor
- 0.59
- gross profit ÷ gross loss
- Max drawdown
- 56.60%
- −$5,923.85
One run with the author's default settings, $10,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
2 settings do nothing
“-----------------Strategy Inputs-------------------”, “-----------------General Inputs-------------------” are declared but never read.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
Uses an argument v6 removed
when = on line 55, 56, 58, 59, 62, 63, 65, 66, 71, 72. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 79
transp = on line 79, 81. v5 folds the transparency into the colour with color.new(c, transp).
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 lowest → ta.lowest, highest → ta.highest, valuewhen → ta.valuewhen, ema → ta.ema.
- 10 strategy calls use the when = argument (line 55, 56, 58, 59, 62, 63, 65, 66, 71, 72). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 48 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: //@version=4 → //@version=5
- Line 14: input(type = input.integer) → input.int()
- Line 30: lowest → ta.lowest
- Line 31: highest → ta.highest
- Line 32: valuewhen → ta.valuewhen
- Line 33: valuewhen → ta.valuewhen
3 more edits
- Line 39: ema → ta.ema
- Line 79: transp = 80 → color.new(color.green, 80)
- Line 81: transp = 80 → color.new(color.red, 80)
⋯// high above the EMA, then it's a Bear Bounce. This logic can be reverted.-//@version=4+//@version=5strategy("EMA Bounce", overlay=true, ⋯ slippage=0)-direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)+direction = input.int(0, title = "Strategy Direction", minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))⋯// Price Action Stop and Take Profit-LL=(lowest(i_SPL))*(1-i_PercIncrement)+LL=(ta.lowest(i_SPL))*(1-i_PercIncrement)-HH=(highest(i_SPL))*(1+i_PercIncrement)+HH=(ta.highest(i_SPL))*(1+i_PercIncrement)-LL_price = valuewhen(bought, LL, 0)+LL_price = ta.valuewhen(bought, LL, 0)-HH_price = valuewhen(bought, HH, 0)+HH_price = ta.valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na ⋯/////////////////////// STRATEGY LOGIC /////////////////////////////////////////-EMA=ema(close, i_EMA)+EMA=ta.ema(close, i_EMA)LowAboveEMA=low > EMA⋯plotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, - color=color.green, title="Bullish Setup", transp=80, size=size.auto)+ color=color.new(color.green, 80), title="Bullish Setup", size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, - color=color.red, title="Bearish Setup", transp=80, size=size.auto)+ color=color.new(color.red, 80), title="Bearish Setup", size=size.auto)Same 48 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 17: input() → input.bool()
- Line 18: input() → input.int()
- Line 20: input() → input.bool()
- Line 22: input() → input.bool()
- Line 23: input() → input.int()
- Line 24: input() → input.float()
13 more edits
- Line 25: input() → input.float()
- Line 50: input() → input.bool()
- Line 51: input() → input.bool()
- Line 55: when = SELL and strategy.position_size == 0 → if block
- Line 56: when = BUY and strategy.position_size == 0 → if block
- Line 58: when = SELL → if block
- Line 59: when = BUY → if block
- Line 62: when = BUY and strategy.position_size == 0 → if block
- Line 63: when = SELL and strategy.position_size == 0 → if block
- Line 65: when = BUY → if block
- Line 66: when = SELL → if block
- Line 71: when = i_SL → if block
- Line 72: when = i_SL → if block
⋯/////////////////////// STRATEGY INPUTS ////////////////////////////////////////-title1=input(true, "-----------------Strategy Inputs-------------------") +title1=input.bool(true, "-----------------Strategy Inputs-------------------") -i_EMA=input(20, title="EMA Length")+i_EMA=input.int(20, title="EMA Length")/////////////////////// BACKTESTER /////////////////////////////////////////////-title2=input(true, "-----------------General Inputs-------------------") +title2=input.bool(true, "-----------------General Inputs-------------------") // Backtester General Inputs-i_SL=input(true, title="Use Swing Stop Loss and Take Profit")+i_SL=input.bool(true, title="Use Swing Stop Loss and Take Profit")-i_SPL=input(defval=10, title="Swing Point Loopback")+i_SPL=input.int(defval=10, title="Swing Point Loopback")-i_PercIncrement=input(defval=.2, step=.1, title="Swing Point SL Perc Increment")*0.01+i_PercIncrement=input.float(defval=.2, step=.1, title="Swing Point SL Perc Increment")*0.01-i_TPRRR = input(1.2, step=.1, title="Take Profit Risk Reward Ratio")+i_TPRRR = input.float(1.2, step=.1, title="Take Profit Risk Reward Ratio")// Bought and Sold Boolean Signal⋯//Inputs-DPR=input(false, "Allow Direct Position Reverse")+DPR=input.bool(false, "Allow Direct Position Reverse")-reverse=input(false, "Reverse Trades")+reverse=input.bool(false, "Reverse Trades")// Entries⋯ if not DPR- strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)+ if SELL and strategy.position_size == 0+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)+ if BUY and strategy.position_size == 0+ strategy.entry("short", strategy.short) else - strategy.entry("long", strategy.long, when=SELL)+ if SELL+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=BUY)+ if BUY+ strategy.entry("short", strategy.short)else if not DPR - strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)+ if BUY and strategy.position_size == 0+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)+ if SELL and strategy.position_size == 0+ strategy.entry("short", strategy.short) else- strategy.entry("long", strategy.long, when=BUY)+ if BUY+ strategy.entry("long", strategy.long)- strategy.entry("short", strategy.short, when=SELL)+ if SELL+ strategy.entry("short", strategy.short)SL=entry_LL_price⋯STP=stp-strategy.exit("TP & SL", "long", limit=TP, stop=SL, when=i_SL)+if i_SL+ strategy.exit("TP & SL", "long", limit=TP, stop=SL)-strategy.exit("TP & SL", "short", limit=STP, stop=SSL, when=i_SL)+if i_SL+ strategy.exit("TP & SL", "short", limit=STP, stop=SSL)/////////////////////// PLOTS //////////////////////////////////////////////////⋯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: 48 before, 69 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.
⋯// high above the EMA, then it's a Bear Bounce. This logic can be reverted.-//@version=5+//@version=6strategy("EMA Bounce", 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 |
|---|---|---|---|
| Strategy Direction | 0 | int (written input.integer) · min -1 · max 1 | line 15 |
| -----------------Strategy Inputs------------------- | true | bool | unused |
| EMA Length | 20 | int | EMA |
| -----------------General Inputs------------------- | true | bool | unused |
| Use Swing Stop Loss and Take Profit | true | bool | exit TP & SL |
| Swing Point Loopback | 10 | int | LL HH |
| Swing Point SL Perc Increment | .2 | float · step .1 | LL HH |
| Take Profit Risk Reward Ratio | 1.2 | float · step .1 | tp stp |
| Allow Direct Position Reverse | false | bool | entry long entry short entry long entry short entry long entry short entry long entry short line 54 line 61 |
| Reverse Trades | false | bool | line 53 |
What it calculates
- Lowest (
lowest,ta.lowestin v5)Swing Point Loopback (10)LL · line 30 - Highest (
highest,ta.highestin v5)Swing Point Loopback (10)HH · line 31 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, LL, 0LL_price · line 32 - Valuewhen (
valuewhen,ta.valuewhenin v5)bought, HH, 0HH_price · line 33 - EMA (
ema,ta.emain v5)close, EMA Length (20)EMA · line 39
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 | SELL and strategy.position_size == 0 | On | 55 |
| Open short short | BUY and strategy.position_size == 0 | On | 56 |
| Open long long | SELL | On | 58 |
| Open short short | BUY | On | 59 |
| Open long long | BUY and strategy.position_size == 0 | On | 62 |
| Open short short | SELL and strategy.position_size == 0 | On | 63 |
| Open long long | BUY | On | 65 |
| Open short short | SELL | On | 66 |
| Exit TP & SL stop and limit | i_SL | On | 71 |
| Exit TP & SL stop and limit | i_SL | On | 72 |
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 | −48.8% | +102.5% | 48 | 42% | 0.59 | 56.6% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +4.1% | +5.5% | 34 | 41% | 1.11 | 11.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.8% | +9.8% | 31 | 48% | 1.01 | 51.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +14.7% | +8.4% | 38 | 53% | 1.28 | 23.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −15.9% | +16.7% | 34 | 47% | 0.91 | 52.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.1% | +21.5% | 37 | 41% | 1.00 | 24.6% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +37.6% | +148.3% | 40 | 60% | 1.19 | 31.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −11.2% | +17.1% | 38 | 39% | 0.72 | 20.8% | 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 | 14 | 36% | −$2,115.29 |
| Sideways market | 23 | 48% | −$1,363.55 |
| Falling market | 11 | 36% | −$1,404.86 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
64.7%
The 95th percentile of the worst drawdown when the same 48 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 48.8% to 64.7%; the tick is what actually happened, 56.3%. Order luck alone moves it this much.
All 48 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 17 Mar 2024 65,300.60 | 18 Mar 2024 68,393.50 | 1 | $465.25 |
| long | 10 Apr 2024 69,146.00 | 13 Apr 2024 64,364.10 | 3 | −$731.53 |
| short | 1 May 2024 60,672.00 | 17 May 2024 67,366.80 | 16 | −$1,081.84 |
| long | 31 May 2024 68,352.20 | 4 Jun 2024 70,959.30 | 4 | $322.83 |
| long | 8 Jun 2024 69,355.60 | 11 Jun 2024 66,536.70 | 3 | −$371.66 |
| short | 2 Jul 2024 62,900.00 | 3 Jul 2024 60,799.90 | 1 | $280.35 |
| short | 14 Jul 2024 59,204.00 | 15 Jul 2024 61,543.50 | 1 | −$358.14 |
| long | 26 Jul 2024 65,799.90 | 27 Jul 2024 69,025.50 | 1 | $410.76 |
| short | 12 Aug 2024 58,712.60 | 23 Aug 2024 62,870.60 | 11 | −$640.00 |
| short | 30 Aug 2024 59,359.00 | 26 Sep 2024 65,130.00 | 27 | −$813.19 |
| short | 5 Oct 2024 62,086.00 | 15 Oct 2024 66,631.00 | 10 | −$553.76 |
| long | 24 Oct 2024 66,668.60 | 28 Oct 2024 69,066.50 | 4 | $243.48 |
| long | 4 Nov 2024 68,776.00 | 6 Nov 2024 71,738.80 | 2 | $303.00 |
| long | 6 Dec 2024 96,945.60 | 15 Dec 2024 104,898.00 | 9 | $606.71 |
| short | 22 Dec 2024 97,292.00 | 20 Jan 2025 108,570.00 | 29 | −$943.33 |
| long | 28 Jan 2025 102,083.00 | 2 Feb 2025 97,582.20 | 5 | −$320.20 |
| short | 8 Feb 2025 96,506.80 | 26 Feb 2025 84,310.50 | 18 | $856.28 |
| short | 7 Mar 2025 89,931.90 | 9 Mar 2025 83,622.10 | 2 | $532.35 |
| long | 28 Mar 2025 87,232.00 | 29 Mar 2025 82,382.10 | 1 | −$462.51 |
| short | 5 Apr 2025 83,889.90 | 6 Apr 2025 78,145.30 | 1 | $524.15 |
| short | 10 Apr 2025 82,615.20 | 22 Apr 2025 88,677.00 | 12 | −$613.34 |
| long | 30 May 2025 105,590.00 | 31 May 2025 103,414.00 | 1 | −$163.76 |
| short | 21 Jun 2025 103,298.00 | 2 Jul 2025 109,170.00 | 11 | −$431.89 |
| long | 26 Jul 2025 117,614.00 | 1 Aug 2025 114,494.00 | 6 | −$192.81 |
| short | 7 Aug 2025 114,992.00 | 11 Aug 2025 119,512.00 | 4 | −$275.40 |
| long | 15 Aug 2025 118,295.00 | 19 Aug 2025 113,128.00 | 4 | −$292.94 |
| short | 4 Sep 2025 111,706.00 | 10 Sep 2025 113,713.00 | 6 | −$118.22 |
| short | 22 Oct 2025 108,298.00 | 27 Oct 2025 116,196.00 | 5 | −$455.69 |
| long | 29 Oct 2025 112,898.00 | 30 Oct 2025 106,453.00 | 1 | −$331.14 |
| short | 12 Nov 2025 103,059.00 | 16 Nov 2025 93,564.00 | 4 | $492.63 |
| short | 3 Dec 2025 91,277.90 | 9 Dec 2025 94,338.30 | 6 | −$202.07 |
| short | 18 Dec 2025 86,243.20 | 5 Jan 2026 94,778.20 | 18 | −$567.09 |
| long | 9 Jan 2026 91,100.00 | 13 Jan 2026 95,929.40 | 4 | $266.97 |
| long | 20 Jan 2026 92,631.00 | 21 Jan 2026 87,720.20 | 1 | −$289.52 |
| short | 29 Jan 2026 89,300.00 | 30 Jan 2026 84,650.20 | 1 | $261.21 |
| short | 26 Feb 2026 67,988.00 | 27 Feb 2026 65,419.10 | 1 | $198.09 |
| short | 10 Mar 2026 68,432.20 | 16 Mar 2026 74,198.10 | 6 | −$472.41 |
| long | 19 Mar 2026 71,246.60 | 22 Mar 2026 68,254.60 | 3 | −$217.29 |
| short | 2 Apr 2026 68,113.90 | 7 Apr 2026 72,170.10 | 5 | −$293.56 |
| long | 30 Apr 2026 75,780.00 | 1 May 2026 77,109.70 | 1 | $76.48 |
| long | 14 May 2026 79,313.60 | 15 May 2026 81,090.00 | 1 | $100.28 |
| short | 26 May 2026 77,322.00 | 27 May 2026 75,599.80 | 1 | $101.95 |
| short | 16 Jun 2026 66,328.70 | 17 Jun 2026 65,011.10 | 1 | $92.45 |
| short | 23 Jun 2026 64,020.00 | 24 Jun 2026 59,931.90 | 1 | $311.62 |
| short | 3 Jul 2026 61,560.00 | 4 Jul 2026 63,365.50 | 1 | −$158.29 |
| long | 7 Jul 2026 64,042.90 | 20 Aug 2026 71,672.90 | 44 | $602.49 |
| short | 18 Sep 2026 76,417.00 | 19 Sep 2026 81,562.80 | 1 | −$388.23 |
| short | 17 Oct 2026 81,615.90 | 21 Oct 2026 84,520.70 | 4 | −$193.22 |
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 |
|---|---|---|---|---|---|
| EMA Bounce Strategy this page | — | v4 strategy | −48.8% | 48 | 56.6% |
| Modulo Logic + EMA Strat by tweakerID | lowest highest valuewhen ema | v4 strategy | −50.8% | 16 | 54.7% |
| Swing Points Breakouts by tweakerID | lowest highest valuewhen | v4 strategy | +29.9% | 92 | 52.0% |
| CC Trend strategy 2- Downtrend Short by CheatCode1 | ema highest lowest | v5 strategy | No trades on this market | ||
| TrianglePoint strategy by mohanee | highest lowest ema | v4 strategy | +45.4% | 11 | 101.9% |
| Lagged Donchian Channel + EMA by Mysteriown | ema highest lowest | v4 strategy | −12.3% | 4 | 12.3% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 22 ms | Yes 1,000 bars in 63 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/// © tweakerID// Simple strategy that checks for price bounces over an Exponential Moving Average. If the CLOSE of the candle bounces// back from having it's LOW below the EMA, then it's a Bull Bounce. If the CLOSE of the candle bounces down from having it's// high above the EMA, then it's a Bear Bounce. This logic can be reverted.//@version=4strategy("EMA Bounce", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, commission_value=0.04, calc_on_every_tick=false, slippage=0)direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))/////////////////////// STRATEGY INPUTS ////////////////////////////////////////title1=input(true, "-----------------Strategy Inputs-------------------") i_EMA=input(20, title="EMA Length")/////////////////////// BACKTESTER /////////////////////////////////////////////title2=input(true, "-----------------General Inputs-------------------") // Backtester General Inputsi_SL=input(true, title="Use Swing Stop Loss and Take Profit")i_SPL=input(defval=10, title="Swing Point Loopback")i_PercIncrement=input(defval=.2, step=.1, title="Swing Point SL Perc Increment")*0.01i_TPRRR = input(1.2, step=.1, title="Take Profit Risk Reward Ratio")// Bought and Sold Boolean Signalbought = strategy.position_size > strategy.position_size[1] or strategy.position_size < strategy.position_size[1]// Price Action Stop and Take ProfitLL=(lowest(i_SPL))*(1-i_PercIncrement)HH=(highest(i_SPL))*(1+i_PercIncrement)LL_price = valuewhen(bought, LL, 0)HH_price = valuewhen(bought, HH, 0)entry_LL_price = strategy.position_size > 0 ? LL_price : na entry_HH_price = strategy.position_size < 0 ? HH_price : na tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRRstp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR/////////////////////// STRATEGY LOGIC /////////////////////////////////////////EMA=ema(close, i_EMA)LowAboveEMA=low > EMALowBelowEMA=low < EMAHighAboveEMA=high > EMAHighBelowEMA=high < EMABullBounce=LowAboveEMA[1] and LowBelowEMA and close > EMA //and close > openBearBounce=HighBelowEMA[1] and HighAboveEMA and close < EMA //and close < openplot(EMA)BUY=BullBounceSELL=BearBounce//InputsDPR=input(false, "Allow Direct Position Reverse")reverse=input(false, "Reverse Trades")// Entriesif reverse if not DPR strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0) strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0) else strategy.entry("long", strategy.long, when=SELL) strategy.entry("short", strategy.short, when=BUY)else if not DPR strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0) strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0) else strategy.entry("long", strategy.long, when=BUY) strategy.entry("short", strategy.short, when=SELL)SL=entry_LL_priceSSL=entry_HH_priceTP=tpSTP=stpstrategy.exit("TP & SL", "long", limit=TP, stop=SL, when=i_SL)strategy.exit("TP & SL", "short", limit=STP, stop=SSL, when=i_SL)/////////////////////// PLOTS //////////////////////////////////////////////////plot(strategy.position_size > 0 ? SL : na , title='SL', style=plot.style_cross, color=color.red)plot(strategy.position_size < 0 ? SSL : na , title='SSL', style=plot.style_cross, color=color.red)plot(strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)plot(strategy.position_size < 0 ? STP : na, title='STP', style=plot.style_cross, color=color.green)// Draw price action setup arrowsplotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar, color=color.green, title="Bullish Setup", transp=80, size=size.auto)plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar, color=color.red, title="Bearish Setup", transp=80, size=size.auto)