Pine Script v4 · Strategy
Three (3)-Bar and Four (4)-Bar Plays Strategy
A Pine Script v4 strategy built on Highest (high, 30) and Lowest (low, 30). It has 6 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade commits 1.0% of equity and pays no commission. 14 settings; defaults include From Month 1, From day 1 and From Year 2021.
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 Three (3)-Bar and Four (4)-Bar Plays Strategy repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Three (3)-Bar and Four (4)-Bar Plays Strategy do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can Three (3)-Bar and Four (4)-Bar Plays Strategy be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- What alerts does Three (3)-Bar and Four (4)-Bar Plays Strategy have?
- 1
- Potential 3-bar or 4-bar Play.
- Does Three (3)-Bar and Four (4)-Bar Plays Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 81, 84.
BTCUSDT · 1D · default settings
- Resistance
- Support
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
One run with the author's default settings, $30,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 67, 70, 73, 76. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 29
transp = on line 29, 30, 54, 55, 56, 57. 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 highest → ta.highest, lowest → ta.lowest, abs → math.abs, atr → ta.atr, min → math.min, max → math.max.
- 4 strategy calls use the when = argument (line 67, 70, 73, 76). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 3: //@version=4 → //@version=5
- Line 11: input(type = input.float) → input.float()
- Line 12: input(type = input.float) → input.float()
- Line 13: input(type = input.float) → input.float()
- Line 14: input(type = input.float) → input.float()
- Line 16: input(type = input.bool) → input.bool()
14 more edits
- Line 19: highest → ta.highest
- Line 20: lowest → ta.lowest
- Line 29: transp = 0 → color.new(color.yellow, 0)
- Line 30: transp = 0 → color.new(color.orange, 0)
- Line 32: abs → math.abs
- Line 33: abs → math.abs
- Line 34: atr → ta.atr
- Line 53: input(type = input.bool) → input.bool()
- Line 54: transp = 0 → color.new(color.green, 0)
- Line 55: transp = 0 → color.new(color.red, 0)
- Line 56: transp = 0 → color.new(color.green, 0)
- Line 57: transp = 0 → color.new(color.red, 0)
- Line 74: min → math.min
- Line 77: max → math.max
⋯//Adopted from JRL_6 -- https://www.tradingview.com/script/2IhYFRpf-3-Bar-and-4-Bar-Plays/-//@version=4+//@version=5strategy(title="Three (3)-Bar and Four (4)-Bar Plays Strategy", shorttitle="Three (3)-Bar and Four (4)-Bar Plays Strategy", overlay=true, calc_on_every_tick=true, currency=currency.USD, default_qty_value=1.0,initial_capital=30000.00,default_qty_type=strategy.percent_of_equity)⋯toyear = input(defval = 2100, minval = 1900, maxval = 2100, title = "To Year")-garBarSetting1 = input(defval = 1.5, minval = 0.0, maxval = 100.0, title = "Gap Bar Size", type = input.float)+garBarSetting1 = input.float(defval = 1.5, minval = 0.0, maxval = 100.0, title = "Gap Bar Size")-garBarSetting2 = input(defval = 0.70, minval = 0.0, maxval = 100.0, title = "Gap Bar Body Size", type = input.float)+garBarSetting2 = input.float(defval = 0.70, minval = 0.0, maxval = 100.0, title = "Gap Bar Body Size")-TopSetting = input(defval = 0.10, minval = 0.0, maxval = 100.0, title = "Bull Top Bar Size", type = input.float)+TopSetting = input.float(defval = 0.10, minval = 0.0, maxval = 100.0, title = "Bull Top Bar Size")-profitMultiplier = input(defval = 2.0, minval = 1.0, maxval = 100.0, title = "Profit Multiplier", type = input.float)+profitMultiplier = input.float(defval = 2.0, minval = 1.0, maxval = 100.0, title = "Profit Multiplier")// Plot Donchian Channel-showDonchian = input(title="Show Donchian Channel?", type=input.bool, defval=true)+showDonchian = input.bool(title="Show Donchian Channel?", defval=true)lookbackLen = input(30, minval=1, title="No. of Bars to look back for breakout")donchianOffset = input(1, minval=1, title="Offset of Donchian Channel") // offsetting by at least 1 bar allows the price to break the channel-highestHighs = highest(high, lookbackLen)[donchianOffset]+highestHighs = ta.highest(high, lookbackLen)[donchianOffset]-lowestLows = lowest(low, lookbackLen)[donchianOffset] +lowestLows = ta.lowest(low, lookbackLen)[donchianOffset] plotHigh = if showDonchian⋯ na-plot(plotHigh, title="Resistance", color=color.yellow, linewidth=1, transp=0)+plot(plotHigh, title="Resistance", color=color.new(color.yellow, 0), linewidth=1)-plot(plotLow, title="Support", color=color.orange, linewidth=1, transp=0)+plot(plotLow, title="Support", color=color.new(color.orange, 0), linewidth=1)// ========== 3-Bar and 4-Bar Play Setup ==========-barSize = abs(high - low)+barSize = math.abs(high - low)-bodySize = abs(open - close)+bodySize = math.abs(open - close)-gapBar = (barSize > (atr(1000) * garBarSetting1)) and (bodySize >= (barSize * garBarSetting2)) // find a wide ranging bar that is more than 2.5x the size of the average bar size and body is at least 65% of bar size+gapBar = (barSize > (ta.atr(1000) * garBarSetting1)) and (bodySize >= (barSize * garBarSetting2)) // find a wide ranging bar that is more than 2.5x the size of the average bar size and body is at least 65% of bar sizebreakoutAbove = close > highestHighs // look for breakout above Resistance⋯fourBarSetupBear = gapBar[3] and breakoutBelow[3] and collectingBarBear[2] and collectingBarBear2[1] and triggerFourBarBear // find 4-bar Bear Setup-labels = input(title="Show Buy/Sell Labels?", type=input.bool, defval=true)+labels = input.bool(title="Show Buy/Sell Labels?", defval=true)-plotshape(threeBarSetupBull and labels, title="3-Bar Bull", text="3-Bar Play", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(threeBarSetupBull and labels, title="3-Bar Bull", text="3-Bar Play", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-plotshape(threeBarSetupBear and labels, text="3-Bar Bear", title="3-Bar Play", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(threeBarSetupBear and labels, text="3-Bar Bear", title="3-Bar Play", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)-plotshape(fourBarSetupBull and labels, title="4-Bar Bull", text="4-Bar Play", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(fourBarSetupBull and labels, title="4-Bar Bull", text="4-Bar Play", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-plotshape(fourBarSetupBear and labels, text="4-Bar Bear", title="4-Bar Play", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(fourBarSetupBear and labels, text="4-Bar Bear", title="4-Bar Play", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)alertcondition(threeBarSetupBull or threeBarSetupBear or fourBarSetupBull or fourBarSetupBear, title="Potential 3-bar or 4-bar Play", message="Potential 3-bar or 4-bar Play")⋯ strategy.entry("4 Bar Long", strategy.long, when=fourBarSetupBull)- sl :=min(low[1], low[2])+ sl :=math.min(low[1], low[2]) if fourBarSetupBear and strategy.position_size >=0 strategy.entry("4 Bar Short", strategy.short, when=fourBarSetupBear)- sl :=max(high[1], high[2])+ sl :=math.max(high[1], high[2])if sl !=0.0⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
6 more edits
- Line 17: input() → input.int()
- Line 18: input() → input.int()
- Line 67: when = threeBarSetupBull → if block
- Line 70: when = threeBarSetupBull → if block
- Line 73: when = fourBarSetupBull → if block
- Line 76: when = fourBarSetupBear → if block
⋯strategy(title="Three (3)-Bar and Four (4)-Bar Plays Strategy", shorttitle="Three (3)-Bar and Four (4)-Bar Plays Strategy", overlay=true, calc_on_every_tick=true, currency=currency.USD, default_qty_value=1.0,initial_capital=30000.00,default_qty_type=strategy.percent_of_equity)-frommonth = input(defval = 1, minval = 01, maxval = 12, title = "From Month")+frommonth = input.int(defval = 1, minval = 01, maxval = 12, title = "From Month")-fromday = input(defval = 1, minval = 01, maxval = 31, title = "From day")+fromday = input.int(defval = 1, minval = 01, maxval = 31, title = "From day")-fromyear = input(defval = 2021, minval = 1900, maxval = 2100, title = "From Year")+fromyear = input.int(defval = 2021, minval = 1900, maxval = 2100, title = "From Year")-tomonth = input(defval = 12, minval = 01, maxval = 12, title = "To Month")+tomonth = input.int(defval = 12, minval = 01, maxval = 12, title = "To Month")-today = input(defval = 31, minval = 01, maxval = 31, title = "To day")+today = input.int(defval = 31, minval = 01, maxval = 31, title = "To day")-toyear = input(defval = 2100, minval = 1900, maxval = 2100, title = "To Year")+toyear = input.int(defval = 2100, minval = 1900, maxval = 2100, title = "To Year")garBarSetting1 = input.float(defval = 1.5, minval = 0.0, maxval = 100.0, title = "Gap Bar Size")⋯showDonchian = input.bool(title="Show Donchian Channel?", defval=true)-lookbackLen = input(30, minval=1, title="No. of Bars to look back for breakout")+lookbackLen = input.int(30, minval=1, title="No. of Bars to look back for breakout")-donchianOffset = input(1, minval=1, title="Offset of Donchian Channel") // offsetting by at least 1 bar allows the price to break the channel+donchianOffset = input.int(1, minval=1, title="Offset of Donchian Channel") // offsetting by at least 1 bar allows the price to break the channelhighestHighs = ta.highest(high, lookbackLen)[donchianOffset]⋯ if threeBarSetupBull and strategy.position_size <=0- strategy.entry("3 Bar Long", strategy.long, when=threeBarSetupBull)+ if threeBarSetupBull+ strategy.entry("3 Bar Long", strategy.long) sl :=low[1] if threeBarSetupBear and strategy.position_size >=0- strategy.entry("3 Bar Short", strategy.short, when=threeBarSetupBull)+ if threeBarSetupBull+ strategy.entry("3 Bar Short", strategy.short) sl :=high[1] if fourBarSetupBull and strategy.position_size <=0- strategy.entry("4 Bar Long", strategy.long, when=fourBarSetupBull)+ if fourBarSetupBull+ strategy.entry("4 Bar Long", strategy.long) sl :=math.min(low[1], low[2]) if fourBarSetupBear and strategy.position_size >=0- strategy.entry("4 Bar Short", strategy.short, when=fourBarSetupBear)+ if fourBarSetupBear+ strategy.entry("4 Bar Short", strategy.short) sl :=math.max(high[1], high[2])⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯//Adopted from JRL_6 -- https://www.tradingview.com/script/2IhYFRpf-3-Bar-and-4-Bar-Plays/-//@version=5+//@version=6strategy(title="Three (3)-Bar and Four (4)-Bar Plays Strategy", shorttitle="Three (3)-Bar and Four (4)-Bar Plays Strategy", overlay=true, calc_on_every_tick=true, currency=currency.USD, default_qty_value=1.0,initial_capital=30000.00,default_qty_type=strategy.percent_of_equity)⋯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 |
|---|---|---|---|
| From Month | 1 | int · min 01 · max 12 | line 65 |
| From day | 1 | int · min 01 · max 31 | line 65 |
| From Year | 2021 | int · min 1900 · max 2100 | line 65 |
| To Month | 12 | int · min 01 · max 12 | line 65 |
| To day | 31 | int · min 01 · max 31 | line 65 |
| To Year | 2100 | int · min 1900 · max 2100 | line 65 |
| Gap Bar Size | 1.5 | float · min 0.0 · max 100.0 | gapBar |
| Gap Bar Body Size | 0.70 | float · min 0.0 · max 100.0 | gapBar |
| Bull Top Bar Size | 0.10 | float · min 0.0 · max 100.0 | bullTop bullTop2 bearTop bearTop2 |
| Profit Multiplier | 2.0 | float · min 1.0 · max 100.0 | tp |
| Show Donchian Channel? | true | bool | plotHigh plotLow |
| No. of Bars to look back for breakout | 30 | int · min 1 | highestHighs lowestLows |
| Offset of Donchian Channel | 1 | int · min 1 | highestHighs lowestLows |
| Show Buy/Sell Labels? | true | bool | 3-Bar Bull 3-Bar Play 4-Bar Bull 4-Bar Play |
What it calculates
- Highest (
highest,ta.highestin v5)high, No. of Bars to look back for breakout (30)highestHighs · line 19 - Lowest (
lowest,ta.lowestin v5)low, No. of Bars to look back for breakout (30)lowestLows · line 20
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 3 Bar Long long | threeBarSetupBullgapBar[2] and breakoutAbove[2] and collectingBarBull[1] and triggerThreeBarBull | On | 67 |
| Open 3 Bar Short short | threeBarSetupBullgapBar[2] and breakoutAbove[2] and collectingBarBull[1] and triggerThreeBarBull | On | 70 |
| Open 4 Bar Long long | fourBarSetupBullgapBar[3] and breakoutAbove[3] and collectingBarBull[2] and collectingBarBull2[1] and triggerFourBarBull | On | 73 |
| Open 4 Bar Short short | fourBarSetupBeargapBar[3] and breakoutBelow[3] and collectingBarBear[2] and collectingBarBear2[1] and triggerFourBarBear | On | 76 |
| Exit Exit stop and limit | strategy.position_size > 0 | On | 81 |
| Exit Exit stop and limit | strategy.position_size < 0 | On | 84 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Potential 3-bar or 4-bar Play | alertcondition | Potential 3-bar or 4-bar Play | 58 |
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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
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 |
|---|---|---|---|---|---|
| Three (3)-Bar and Four (4)-Bar Plays Strategy this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Alex Days HiLo Rajib by 14rajib | highest lowest | v4 strategy | No trades on this market | ||
| Donchian Strat EXMO by pskoroplas | highest lowest | v4 strategy | +12.1% | 22 | 68.0% |
| Average Highest High and Lowest Low Swinger Strategy by exlux99 | lowest highest | v4 strategy | +6.4% | 20 | 49.6% |
| Highest High and Lowest Low Channel Strategy by ceyhun | highest lowest | v5 strategy | −3.7% | 26 | 7.9% |
| Donchian Channels System [racer8] by racer8 | highest lowest | v4 strategy | −3.2% | 36 | 43.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 39 ms | Yes 1,000 bars in 92 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///Adopted from JRL_6 -- https://www.tradingview.com/script/2IhYFRpf-3-Bar-and-4-Bar-Plays///@version=4strategy(title="Three (3)-Bar and Four (4)-Bar Plays Strategy", shorttitle="Three (3)-Bar and Four (4)-Bar Plays Strategy", overlay=true, calc_on_every_tick=true, currency=currency.USD, default_qty_value=1.0,initial_capital=30000.00,default_qty_type=strategy.percent_of_equity)frommonth = input(defval = 1, minval = 01, maxval = 12, title = "From Month")fromday = input(defval = 1, minval = 01, maxval = 31, title = "From day")fromyear = input(defval = 2021, minval = 1900, maxval = 2100, title = "From Year")tomonth = input(defval = 12, minval = 01, maxval = 12, title = "To Month")today = input(defval = 31, minval = 01, maxval = 31, title = "To day")toyear = input(defval = 2100, minval = 1900, maxval = 2100, title = "To Year")garBarSetting1 = input(defval = 1.5, minval = 0.0, maxval = 100.0, title = "Gap Bar Size", type = input.float)garBarSetting2 = input(defval = 0.70, minval = 0.0, maxval = 100.0, title = "Gap Bar Body Size", type = input.float)TopSetting = input(defval = 0.10, minval = 0.0, maxval = 100.0, title = "Bull Top Bar Size", type = input.float)profitMultiplier = input(defval = 2.0, minval = 1.0, maxval = 100.0, title = "Profit Multiplier", type = input.float)// Plot Donchian ChannelshowDonchian = input(title="Show Donchian Channel?", type=input.bool, defval=true)lookbackLen = input(30, minval=1, title="No. of Bars to look back for breakout")donchianOffset = input(1, minval=1, title="Offset of Donchian Channel") // offsetting by at least 1 bar allows the price to break the channelhighestHighs = highest(high, lookbackLen)[donchianOffset]lowestLows = lowest(low, lookbackLen)[donchianOffset] plotHigh = if showDonchian highestHighselse naplotLow = if showDonchian lowestLowselse naplot(plotHigh, title="Resistance", color=color.yellow, linewidth=1, transp=0)plot(plotLow, title="Support", color=color.orange, linewidth=1, transp=0)// ========== 3-Bar and 4-Bar Play Setup ==========barSize = abs(high - low)bodySize = abs(open - close)gapBar = (barSize > (atr(1000) * garBarSetting1)) and (bodySize >= (barSize * garBarSetting2)) // find a wide ranging bar that is more than 2.5x the size of the average bar size and body is at least 65% of bar sizebreakoutAbove = close > highestHighs // look for breakout above ResistancebreakoutBelow = close < lowestLows // look for breakout below SupportbullTop = close > close[1] + barSize[1] * TopSetting ? false : true // check if top of bar is relatively equal to top of the gap bar (first collecting bull bar)bullTop2 = close > close[2] + barSize[2] * TopSetting ? false : true // check if top of bar is relatively equal to top of the gap bar (second collecting bull bar)bearTop = close < close[1] - barSize[1] * TopSetting ? false : true // check if top of bar is relatively equal to top of the gap bar (second collecting bear bar)bearTop2 = close < close[2] - barSize[2] * TopSetting ? false : true // check if top of bar is relatively equal to top of the gap bar (second collecting bear bar)collectingBarBull = barSize < barSize[1] / 2 and low > close[1] - barSize[1] / 2 and bullTop // find a collecting bull barcollectingBarBear = barSize < barSize[1] / 2 and high < close[1] + barSize[1] / 2 and bearTop // find a collecting bear barcollectingBarBull2 = barSize < barSize[2] / 2 and low > close[2] - barSize[2] / 2 and bullTop2 // find a second collecting bull barcollectingBarBear2 = barSize < barSize[2] / 2 and high < close[2] + barSize[2] / 2 and bearTop2 // find a second collecting bear bartriggerThreeBarBull = close > close[1] and close > close[2] and high > high[1] and high > high[2] // find a bull trigger bar in a 3 bar playtriggerThreeBarBear = close < close[1] and close < close[2] and high < high[1] and high < high[2] // find a bear trigger bar in a 3 bar playtriggerFourBarBull = close > close[1] and close > close[2] and close > close[3] and high > high[1] and high > high[2] and high > high[3] // find a bull trigger bar in a 4 bar playtriggerFourBarBear = close < close[1] and close < close[2] and close < close[3] and high < high[1] and high < high[2] and high < high[3] // find a bear trigger bar in a 4 bar playthreeBarSetupBull = gapBar[2] and breakoutAbove[2] and collectingBarBull[1] and triggerThreeBarBull // find 3-bar Bull SetupthreeBarSetupBear = gapBar[2] and breakoutBelow[2] and collectingBarBear[1] and triggerThreeBarBear // find 3-bar Bear SetupfourBarSetupBull = gapBar[3] and breakoutAbove[3] and collectingBarBull[2] and collectingBarBull2[1] and triggerFourBarBull // find 4-bar Bull SetupfourBarSetupBear = gapBar[3] and breakoutBelow[3] and collectingBarBear[2] and collectingBarBear2[1] and triggerFourBarBear // find 4-bar Bear Setuplabels = input(title="Show Buy/Sell Labels?", type=input.bool, defval=true)plotshape(threeBarSetupBull and labels, title="3-Bar Bull", text="3-Bar Play", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.green, textcolor=color.white, transp=0)plotshape(threeBarSetupBear and labels, text="3-Bar Bear", title="3-Bar Play", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white, transp=0)plotshape(fourBarSetupBull and labels, title="4-Bar Bull", text="4-Bar Play", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.green, textcolor=color.white, transp=0)plotshape(fourBarSetupBear and labels, text="4-Bar Bear", title="4-Bar Play", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.red, textcolor=color.white, transp=0)alertcondition(threeBarSetupBull or threeBarSetupBear or fourBarSetupBull or fourBarSetupBear, title="Potential 3-bar or 4-bar Play", message="Potential 3-bar or 4-bar Play")float sl = nafloat tp = nasl := nz(sl[1], 0.0)tp := nz(tp[1], 0.0)plot(sl==0.0?na:sl,title='SL', color = color.red)plot(tp==0.0?na:tp,title='TP', color = color.green)if (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 00, 00)) if threeBarSetupBull and strategy.position_size <=0 strategy.entry("3 Bar Long", strategy.long, when=threeBarSetupBull) sl :=low[1] if threeBarSetupBear and strategy.position_size >=0 strategy.entry("3 Bar Short", strategy.short, when=threeBarSetupBull) sl :=high[1] if fourBarSetupBull and strategy.position_size <=0 strategy.entry("4 Bar Long", strategy.long, when=fourBarSetupBull) sl :=min(low[1], low[2]) if fourBarSetupBear and strategy.position_size >=0 strategy.entry("4 Bar Short", strategy.short, when=fourBarSetupBear) sl :=max(high[1], high[2])if sl !=0.0 if strategy.position_size > 0 tp := strategy.position_avg_price + ((strategy.position_avg_price - sl) * profitMultiplier) strategy.exit(id="Exit", limit=tp, stop=sl) if strategy.position_size < 0 tp := strategy.position_avg_price - ((sl - strategy.position_avg_price) * profitMultiplier) strategy.exit(id="Exit", limit=tp, stop=sl)