Pine Script v4 · Strategy
Qullamaggie Breakout
A Pine Script v4 strategy built on ATR (14), Pivothigh (high, pvtLenL) and Pivotlow (low, pvtLenL). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 0.1% commission. 13 settings; defaults include Lookback Period for Swing High 3, Lookback Bars for Stop Level 3 and Timeframe of Moving Averages D.
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 Qullamaggie Breakout repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 7 of 7 trades.
- How did Qullamaggie Breakout do on BTCUSDT 1D with default settings?
- +61.35%
- From 26 Jan 2024 to 21 Oct 2026, over 25 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Qullamaggie Breakout 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 Qullamaggie Breakout use a stop loss?
- Yes
- strategy.exit sets a stop on line 101.
- Does Qullamaggie Breakout run in Zeal Terminal?
- Yes
- It compiles in 24 ms and runs 1,000 bars in 95 ms, in the browser.
BTCUSDT · 1D · default settings
- MA1
- MA2
- MA3
- Top Levels
- Top Levels 2
- Current Breakout Level
- Current Stop Level
- Historical Stop Levels
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +61.35%
- $6,134.91
- Buy and hold
- +102.5%
- same period
- Closed trades
- 25
- 9 won · 16 lost
- Profitable
- 36.0%
- of closed trades
- Profit factor
- 1.93
- gross profit ÷ gross loss
- Max drawdown
- 20.24%
- −$3,068.60
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. 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
Every trade uses all the equity
default_qty_value is 100% of equity.
-
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 100, 103. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 37
transp = on line 37, 38, 39, 69, 71, 76, 96, 97. 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 ema → ta.ema, sma → ta.sma, security → request.security, atr → ta.atr, pivothigh → ta.pivothigh, pivotlow → ta.pivotlow, barssince → ta.barssince, change → ta.change, valuewhen → ta.valuewhen, crossover → ta.crossover, crossunder → ta.crossunder, lowest → ta.lowest.
- 2 strategy calls use the when = argument (line 100, 103). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 8: //@version=4 → //@version=5
- Line 13: input(type = input.time) → input.time()
- Line 14: input(type = input.time) → input.time()
- Line 20: input(type = input.resolution) → input.timeframe()
- Line 27: input(type = input.bool) → input.bool()
- Line 33: ema → ta.ema
26 more edits
- Line 33: sma → ta.sma
- Line 34: security → request.security
- Line 35: security → request.security
- Line 36: security → request.security
- Line 37: transp = 60 → color.new(color.purple, 60)
- Line 38: transp = 60 → color.new(color.yellow, 60)
- Line 39: transp = 60 → color.new(color.white, 60)
- Line 43: input(type = input.bool) → input.bool()
- Line 47: security → request.security
- Line 47: atr → ta.atr
- Line 53: pivothigh → ta.pivothigh
- Line 54: pivotlow → ta.pivotlow
- Line 61: barssince → ta.barssince
- Line 62: barssince → ta.barssince
- Line 66: change → ta.change
- Line 67: change → ta.change
- Line 69: transp = 0 → color.new(hipc, 0)
- Line 71: transp = 0 → color.new(hipc, 0)
- Line 74: valuewhen → ta.valuewhen
- Line 75: valuewhen → ta.valuewhen
- Line 76: transp = 50 → color.new(color.blue, 50)
- Line 84: crossover → ta.crossover
- Line 86: crossunder → ta.crossunder
- Line 91: lowest → ta.lowest
- Line 96: transp = 50 → color.new(color.orange, 50)
- Line 97: transp = 50 → color.new(color.orange, 50)
⋯// (If the difference between the breakout point and your stop level is below a certain % of ATR, it could possibly find those consolidating periods.)-//@version=4+//@version=5strategy("Qullamaggie Breakout", overlay=true, initial_capital=10000, currency='USD', ⋯// === BACKTEST RANGE ===-Start = input(defval = timestamp("01 Jan 2019 06:00 +0000"), title = "Backtest Start Date", type = input.time)+Start = input.time(defval = timestamp("01 Jan 2019 06:00 +0000"), title = "Backtest Start Date")-Finish = input(defval = timestamp("01 Jan 2100 00:00 +0000"), title = "Backtest End Date", type = input.time)+Finish = input.time(defval = timestamp("01 Jan 2100 00:00 +0000"), title = "Backtest End Date")// Inputs⋯ tooltip = "Initial stop placement is the lowest low this many bars back. Allows for tighter stop placement than referencing swing lows.") -htf = input(defval="D", title="Timeframe of Moving Averages", type=input.resolution,+htf = input.timeframe(defval="D", title="Timeframe of Moving Averages", tooltip = "Allows you to set a different time frame for the moving averages. The default behavior is to identify good tightening setups on a larger timeframe⋯ma3Length = input(defval = 50, title = "3rd Moving Average Length", minval = 1)-useMaFilter = input(title = "Use 3rd Moving Average for Filtering?", type = input.bool, defval = true,+useMaFilter = input.bool(title = "Use 3rd Moving Average for Filtering?", defval = true, tooltip = "Signals will be ignored when price is under this slowest moving average. The intent is to keep you out of bear periods and only⋯ma(maType, src, length) =>- maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)+ maType == "EMA" ? ta.ema(src, length) : ta.sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)-ma1 = security(syminfo.tickerid, htf, ma(maType, close, ma1Length))+ma1 = request.security(syminfo.tickerid, htf, ma(maType, close, ma1Length))-ma2 = security(syminfo.tickerid, htf, ma(maType, close, ma2Length))+ma2 = request.security(syminfo.tickerid, htf, ma(maType, close, ma2Length))-ma3 = security(syminfo.tickerid, htf, ma(maType, close, ma3Length))+ma3 = request.security(syminfo.tickerid, htf, ma(maType, close, ma3Length))-plot(ma1, color=color.purple, style=plot.style_line, title="MA1", linewidth=2, transp = 60)+plot(ma1, color=color.new(color.purple, 60), style=plot.style_line, title="MA1", linewidth=2)-plot(ma2, color=color.yellow, style=plot.style_line, title="MA2", linewidth=2, transp = 60)+plot(ma2, color=color.new(color.yellow, 60), style=plot.style_line, title="MA2", linewidth=2)-plot(ma3, color=color.white, style=plot.style_line, title="MA3", linewidth=2, transp = 60)+plot(ma3, color=color.new(color.white, 60), style=plot.style_line, title="MA3", linewidth=2)// === USE ATR FOR FILTERING ===⋯// support/resistance vs.the ATR and make sure you aren't buying at a point that is too extended from normal.-useAtrFilter = input(title = "Use ATR for Filtering?", type = input.bool, defval = false,+useAtrFilter = input.bool(title = "Use ATR for Filtering?", defval = false, tooltip = "Signals will be ignored if the distance between support and resistance is larger than a user-defined percentage of Daily ATR. ⋯atrPerc = input(defval = 100, title = "% of Daily ATR Value", minval = 1)-atrValue = security(syminfo.tickerid, "D", atr(14))*atrPerc*.01+atrValue = request.security(syminfo.tickerid, "D", ta.atr(14))*atrPerc*.01// === PLOT SWING HIGH/LOW AND MOST RECENT LOW TO USE AS STOP LOSS EXIT POINT ===⋯// Get High and Low Pivot Points-pvthi_ = pivothigh(high, pvtLenL, pvtLenR)+pvthi_ = ta.pivothigh(high, pvtLenL, pvtLenR)-pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)+pvtlo_ = ta.pivotlow(low, pvtLenL, pvtLenR)// Force Pivot completion before plotting.⋯// Count How many candles for current Pivot Level, If new reset.-counthi = barssince(not na(pvthi))+counthi = ta.barssince(not na(pvthi))-countlo = barssince(not na(pvtlo))+countlo = ta.barssince(not na(pvtlo)) ⋯pvtlos = fixnan(pvtlo)-hipc = change(pvthis) != 0 ? na : color.maroon+hipc = ta.change(pvthis) != 0 ? na : color.maroon-lopc = change(pvtlos) != 0 ? na : color.green+lopc = ta.change(pvtlos) != 0 ? na : color.green// Display Pivot lines-plot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=-pvtLenR-Shunt, title="Top Levels")+plot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=color.new(hipc, 0), linewidth=1, offset=-pvtLenR-Shunt, title="Top Levels")// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=-pvtLenR-Shunt, title="Bottom Levels")-plot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=0, title="Top Levels 2")+plot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=color.new(hipc, 0), linewidth=1, offset=0, title="Top Levels 2")// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=0, title="Bottom Levels 2")// BUY CONDITIONS-stopLevelCalc = valuewhen(pvtlo_, low[pvtLenR], 0) //Stop Level at Swing Low+stopLevelCalc = ta.valuewhen(pvtlo_, low[pvtLenR], 0) //Stop Level at Swing Low-buyLevel = valuewhen(pvthi_, high[pvtLenR], 0) //Buy level at Swing High+buyLevel = ta.valuewhen(pvthi_, high[pvtLenR], 0) //Buy level at Swing High-plot(buyLevel, style=plot.style_line, color=color.blue, title = "Current Breakout Level", show_last=1, linewidth=1, transp=50, trackprice=true)+plot(buyLevel, style=plot.style_line, color=color.new(color.blue, 50), title = "Current Breakout Level", show_last=1, linewidth=1, trackprice=true)// Conditions for entry and exit⋯// buySignal = high > buyLevel and buyConditions-buySignal = crossover(high, buyLevel) and buyConditions+buySignal = ta.crossover(high, buyLevel) and buyConditionstrailMa = trailMaInput == "1st Moving Average" ? ma1 : ma2-sellSignal = crossunder(close, trailMa)+sellSignal = ta.crossunder(close, trailMa)// sellSignal = security(syminfo.tickerid, htf, close < trailMa) and security(syminfo.tickerid, htf, close[1] < trailMa)⋯inPosition := buySignal[1] ? true : sellSignal[1] ? false : low <= stopLevel[1] ? false : inPosition[1]-lowDefine = lowest(low, lbStop)+lowDefine = ta.lowest(low, lbStop)stopLevel := inPosition ? stopLevel[1] : lowDefine⋯buyPrice := inPosition ? buyPrice[1] : buyLevel-plot(stopLevel, style=plot.style_line, color=color.orange, title = "Current Stop Level", show_last=1, linewidth=1, transp=50, trackprice=true)+plot(stopLevel, style=plot.style_line, color=color.new(color.orange, 50), title = "Current Stop Level", show_last=1, linewidth=1, trackprice=true)-plot(inPosition ? stopLevel : na, style=plot.style_circles, color=color.orange, title = "Historical Stop Levels", transp=50, trackprice=false)+plot(inPosition ? stopLevel : na, style=plot.style_circles, color=color.new(color.orange, 50), title = "Historical Stop Levels", trackprice=false)// plot(buyPrice, style=plot.style_line, color=color.blue, linewidth=1, transp=50, trackprice=true)⋯Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 16: input() → input.int()
- Line 18: input() → input.int()
- Line 23: input() → input.string()
- Line 24: input() → input.int()
- Line 25: input() → input.int()
- Line 26: input() → input.int()
4 more edits
- Line 30: input() → input.string()
- Line 46: input() → input.int()
- Line 100: when = buyConditions → if block
- Line 103: when = sellSignal → if block
⋯// Inputs-lb = input(defval = 3, title = "Lookback Period for Swing High", minval = 1,+lb = input.int(defval = 3, title = "Lookback Period for Swing High", minval = 1, tooltip = "Lookback period for defining the breakout level.")-lbStop = input(defval = 3, title = "Lookback Bars for Stop Level", minval = 1,+lbStop = input.int(defval = 3, title = "Lookback Bars for Stop Level", minval = 1, tooltip = "Initial stop placement is the lowest low this many bars back. Allows for tighter stop placement than referencing swing lows.") ⋯ (like daily) and enter the trade on a breakout occuring on a smaller timeframe, using the moving averages of the larger timeframe to trail your stop.")-maType = input(defval="SMA", options=["EMA", "SMA"], title = "Moving Average Type")+maType = input.string(defval="SMA", options=["EMA", "SMA"], title = "Moving Average Type")-ma1Length = input(defval = 10, title = "1st Moving Average Length", minval = 1)+ma1Length = input.int(defval = 10, title = "1st Moving Average Length", minval = 1)-ma2Length = input(defval = 20, title = "2nd Moving Average Length", minval = 1)+ma2Length = input.int(defval = 20, title = "2nd Moving Average Length", minval = 1)-ma3Length = input(defval = 50, title = "3rd Moving Average Length", minval = 1)+ma3Length = input.int(defval = 50, title = "3rd Moving Average Length", minval = 1)useMaFilter = input.bool(title = "Use 3rd Moving Average for Filtering?", defval = true,⋯ buying when price is showing strength or trading with the longer term trend.")-trailMaInput = input(defval="2nd Moving Average", options=["1st Moving Average", "2nd Moving Average"], title = "Trailing Stop")+trailMaInput = input.string(defval="2nd Moving Average", options=["1st Moving Average", "2nd Moving Average"], title = "Trailing Stop")// MA Calculations⋯ This allows the user to ensure they are not buying something that is too extended and instead focus on names that are consolidating more.")-atrPerc = input(defval = 100, title = "% of Daily ATR Value", minval = 1)+atrPerc = input.int(defval = 100, title = "% of Daily ATR Value", minval = 1)atrValue = request.security(syminfo.tickerid, "D", ta.atr(14))*atrPerc*.01⋯// (STRATEGY ONLY) Comment out for Study-strategy.entry("Long", strategy.long, stop = buyLevel, when = buyConditions)+if buyConditions+ strategy.entry("Long", strategy.long, stop = buyLevel)strategy.exit("Exit Long", from_entry = "Long", stop=stopLevel[1])if (low[1] > trailMa)- strategy.close("Long", when = sellSignal)+ if sellSignal+ strategy.close("Long")// if (low[1] > trailMa)⋯Does it run in Pine Script v6?
Yes
Same 25 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// (If the difference between the breakout point and your stop level is below a certain % of ATR, it could possibly find those consolidating periods.)-//@version=5+//@version=6strategy("Qullamaggie Breakout", overlay=true, initial_capital=10000, currency='USD', ⋯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 |
|---|---|---|---|
| Backtest Start Date | timestamp("01 Jan 2019 06:00 +0000") | time | buyConditions |
| Backtest End Date | timestamp("01 Jan 2100 00:00 +0000") | time | buyConditions |
| Lookback Period for Swing HighLookback period for defining the breakout level. | 3 | int · min 1 | pvtLenL pvtLenR |
| Lookback Bars for Stop LevelInitial stop placement is the lowest low this many bars back. Allows for tighter stop placement than referencing swing lows. | 3 | int · min 1 | lowDefine |
| Timeframe of Moving AveragesAllows you to set a different time frame for the moving averages. The default behavior is to identify good tightening setups on a larger timeframe (like daily) and enter the trade on a breakout occuring on a smaller timeframe, using the moving averages of the larger timeframe to trail your stop. | D | timeframe (written input.resolution) | ma1 ma2 ma3 |
| Moving Average Type | SMA | string · options ["EMA", "SMA"] | ma1 ma2 ma3 line 33 |
| 1st Moving Average Length | 10 | int · min 1 | ma1 |
| 2nd Moving Average Length | 20 | int · min 1 | ma2 |
| 3rd Moving Average Length | 50 | int · min 1 | ma3 |
| Use 3rd Moving Average for Filtering?Signals will be ignored when price is under this slowest moving average. The intent is to keep you out of bear periods and only buying when price is showing strength or trading with the longer term trend. | true | bool | buyConditions |
| Trailing Stop | 2nd Moving Average | string · options ["1st Moving Average", "2nd Moving Average"] | trailMa |
| Use ATR for Filtering?Signals will be ignored if the distance between support and resistance is larger than a user-defined percentage of Daily ATR. This allows the user to ensure they are not buying something that is too extended and instead focus on names that are consolidating more. | false | bool | buyConditions |
| % of Daily ATR Value | 100 | int · min 1 | atrValue |
What it calculates
- ATR (
atr,ta.atrin v5)14atrValue · line 47 - Pivothigh (
pivothigh,ta.pivothighin v5)high, pvtLenL, pvtLenRpvthi_ · line 53 - Pivotlow (
pivotlow,ta.pivotlowin v5)low, pvtLenL, pvtLenRpvtlo_ · line 54 - Valuewhen (
valuewhen,ta.valuewhenin v5)pvtlo_, low[pvtLenR], 0stopLevelCalc · line 74 - Valuewhen (
valuewhen,ta.valuewhenin v5)pvthi_, high[pvtLenR], 0buyLevel · line 75 - Crossunder (
crossunder,ta.crossunderin v5)close, trailMasellSignal · line 86 - Lowest (
lowest,ta.lowestin v5)low, Lookback Bars for Stop Level (3)lowDefine · line 91
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 | buyConditions | On | 100 |
| Exit Exit Long stop | every bar | On | 101 |
| Close Long | sellSignal | On | 103 |
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 data4 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 | +61.3% | +102.5% | 25 | 36% | 1.93 | 20.2% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.8% | +5.5% | 19 | 16% | 0.96 | 17.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +98.8% | +9.8% | 19 | 42% | 1.99 | 20.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +6.5% | +8.4% | 15 | 20% | 1.36 | 13.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −19.1% | +16.7% | 24 | 38% | 0.78 | 41.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +26.0% | +21.5% | 12 | 33% | 2.44 | 9.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −57.3% | +148.3% | 31 | 23% | 0.31 | 65.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +15.3% | +17.1% | 8 | 25% | 2.71 | 8.2% | 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 | 9 | 33% | −$443.74 |
| Sideways market | 12 | 33% | $3,355.80 |
| Falling market | 4 | 50% | $3,238.99 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
31.4%
The 95th percentile of the worst drawdown when the same 25 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 14.2% to 31.4%; the tick is what actually happened, 18.3%. Order luck alone moves it this much.
All 25 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Mar 2024 69,499.80 | 16 Mar 2024 68,555.00 | 0 | −$155.66 |
| long | 17 Mar 2024 65,300.60 | 17 Mar 2024 65,300.60 | 0 | −$19.67 |
| long | 8 Apr 2024 71,769.50 | 12 Apr 2024 67,447.80 | 4 | −$610.05 |
| long | 15 May 2024 65,500.00 | 12 Jun 2024 67,314.20 | 28 | $236.31 |
| long | 19 Jul 2024 63,987.90 | 24 Jul 2024 65,777.00 | 5 | $244.83 |
| long | 25 Jul 2024 65,376.00 | 25 Jul 2024 65,376.00 | 0 | −$19.37 |
| long | 27 Jul 2024 68,474.60 | 1 Aug 2024 64,628.00 | 5 | −$561.82 |
| long | 23 Aug 2024 62,745.10 | 27 Aug 2024 58,783.50 | 4 | −$592.55 |
| long | 17 Sep 2024 60,625.00 | 2 Oct 2024 60,804.90 | 15 | $8.21 |
| long | 14 Oct 2024 64,478.20 | 19 Dec 2024 99,205.00 | 66 | $4,568.01 |
| long | 6 Jan 2025 99,963.70 | 8 Jan 2025 96,954.60 | 2 | −$419.67 |
| long | 17 Jan 2025 102,724.00 | 2 Feb 2025 96,500.00 | 16 | −$792.03 |
| long | 21 Apr 2025 86,496.40 | 30 May 2025 105,590.00 | 39 | $2,594.86 |
| long | 9 Jun 2025 106,795.00 | 13 Jun 2025 105,672.00 | 4 | −$180.90 |
| long | 2 Jul 2025 108,952.00 | 1 Aug 2025 115,764.00 | 30 | $863.71 |
| long | 11 Aug 2025 119,800.00 | 18 Aug 2025 116,299.00 | 7 | −$472.55 |
| long | 18 Sep 2025 117,429.00 | 22 Sep 2025 115,100.00 | 4 | −$320.16 |
| long | 1 Oct 2025 117,900.00 | 10 Oct 2025 111,561.00 | 9 | −$799.91 |
| long | 2 Jan 2026 90,406.10 | 25 Jan 2026 87,263.50 | 23 | −$497.93 |
| long | 16 Mar 2026 74,050.00 | 19 Mar 2026 70,317.00 | 3 | −$683.87 |
| long | 6 Apr 2026 69,310.00 | 18 May 2026 77,457.70 | 42 | $1,428.81 |
| long | 14 Jul 2026 64,692.80 | 25 Jul 2026 64,140.00 | 11 | −$145.46 |
| long | 9 Aug 2026 65,409.60 | 10 Aug 2026 64,166.00 | 1 | −$286.75 |
| long | 19 Aug 2026 65,474.50 | 15 Sep 2026 76,046.60 | 27 | $2,130.43 |
| long | 18 Sep 2026 79,890.00 | 8 Oct 2026 83,321.80 | 20 | $634.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 |
|---|---|---|---|---|---|
| Qullamaggie Breakout this page | — | v4 strategy | +61.3% | 25 | 20.2% |
| Trendlines Strategy by tweakerID | lowest valuewhen atr pivothigh pivotlow | v4 strategy | +69.0% | 4 | 16.7% |
| The Only EURUSD Trading Strategy You Need - Kaspricci by Kaspricci | atr pivothigh pivotlow | v5 strategy | No trades on this market | ||
| Alert(), alertcondition() or strategy alerts- by Peter_O | pivothigh pivotlow valuewhen | v4 strategy | +7,640,000.0% | 191 | 919.9% |
| Quantitative Trend Strategy- Uptrend long by CheatCode1 | pivothigh pivotlow valuewhen | v5 strategy | +5.9% | 28 | 32.8% |
| Moving Stop-Loss mechanism + alerts to MT4-MT5 by Peter_O | pivothigh pivotlow valuewhen | v5 strategy | −9,857,600.0% | 191 | 4,436.8% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 24 ms | With a workaround 1,000 bars in 95 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © millerrh// The intent of this strategy is to buy breakouts with a tight stop on smaller timeframes in the direction of the longer term trend.// Then use a trailing stop of a close below either the 10 MA or 20 MA (user choice) on that larger timeframe as the position // moves in your favor (i.e. whenever position price rises above the MA).// Option of using daily ATR as a measure of finding contracting ranges and ensuring a decent risk/reward.// (If the difference between the breakout point and your stop level is below a certain % of ATR, it could possibly find those consolidating periods.)//@version=4strategy("Qullamaggie Breakout", overlay=true, initial_capital=10000, currency='USD', default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1) // === BACKTEST RANGE ===Start = input(defval = timestamp("01 Jan 2019 06:00 +0000"), title = "Backtest Start Date", type = input.time)Finish = input(defval = timestamp("01 Jan 2100 00:00 +0000"), title = "Backtest End Date", type = input.time)// Inputslb = input(defval = 3, title = "Lookback Period for Swing High", minval = 1, tooltip = "Lookback period for defining the breakout level.")lbStop = input(defval = 3, title = "Lookback Bars for Stop Level", minval = 1, tooltip = "Initial stop placement is the lowest low this many bars back. Allows for tighter stop placement than referencing swing lows.") htf = input(defval="D", title="Timeframe of Moving Averages", type=input.resolution, tooltip = "Allows you to set a different time frame for the moving averages. The default behavior is to identify good tightening setups on a larger timeframe (like daily) and enter the trade on a breakout occuring on a smaller timeframe, using the moving averages of the larger timeframe to trail your stop.")maType = input(defval="SMA", options=["EMA", "SMA"], title = "Moving Average Type")ma1Length = input(defval = 10, title = "1st Moving Average Length", minval = 1)ma2Length = input(defval = 20, title = "2nd Moving Average Length", minval = 1)ma3Length = input(defval = 50, title = "3rd Moving Average Length", minval = 1)useMaFilter = input(title = "Use 3rd Moving Average for Filtering?", type = input.bool, defval = true, tooltip = "Signals will be ignored when price is under this slowest moving average. The intent is to keep you out of bear periods and only buying when price is showing strength or trading with the longer term trend.")trailMaInput = input(defval="2nd Moving Average", options=["1st Moving Average", "2nd Moving Average"], title = "Trailing Stop")// MA Calculationsma(maType, src, length) => maType == "EMA" ? ema(src, length) : sma(src, length) //Ternary Operator (if maType equals EMA, then do ema calc, else do sma calc)ma1 = security(syminfo.tickerid, htf, ma(maType, close, ma1Length))ma2 = security(syminfo.tickerid, htf, ma(maType, close, ma2Length))ma3 = security(syminfo.tickerid, htf, ma(maType, close, ma3Length))plot(ma1, color=color.purple, style=plot.style_line, title="MA1", linewidth=2, transp = 60)plot(ma2, color=color.yellow, style=plot.style_line, title="MA2", linewidth=2, transp = 60)plot(ma3, color=color.white, style=plot.style_line, title="MA3", linewidth=2, transp = 60)// === USE ATR FOR FILTERING ===// The idea here is that you want to buy in a consolodating range for best risk/reward. So here you can compare the current distance between // support/resistance vs.the ATR and make sure you aren't buying at a point that is too extended from normal.useAtrFilter = input(title = "Use ATR for Filtering?", type = input.bool, defval = false, tooltip = "Signals will be ignored if the distance between support and resistance is larger than a user-defined percentage of Daily ATR. This allows the user to ensure they are not buying something that is too extended and instead focus on names that are consolidating more.")atrPerc = input(defval = 100, title = "% of Daily ATR Value", minval = 1)atrValue = security(syminfo.tickerid, "D", atr(14))*atrPerc*.01// === PLOT SWING HIGH/LOW AND MOST RECENT LOW TO USE AS STOP LOSS EXIT POINT ===// Change these values to adjust the look back and look forward periods for your swing high/low calculationspvtLenL = lbpvtLenR = lb// Get High and Low Pivot Pointspvthi_ = pivothigh(high, pvtLenL, pvtLenR)pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)// Force Pivot completion before plotting.Shunt = 1 //Wait for close before printing pivot? 1 for true 0 for flasemaxLvlLen = 0 //Maximum Extension Lengthpvthi = pvthi_[Shunt]pvtlo = pvtlo_[Shunt]// Count How many candles for current Pivot Level, If new reset.counthi = barssince(not na(pvthi))countlo = barssince(not na(pvtlo)) pvthis = fixnan(pvthi)pvtlos = fixnan(pvtlo)hipc = change(pvthis) != 0 ? na : color.maroonlopc = change(pvtlos) != 0 ? na : color.green// Display Pivot linesplot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=-pvtLenR-Shunt, title="Top Levels")// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=-pvtLenR-Shunt, title="Bottom Levels")plot((maxLvlLen == 0 or counthi < maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=0, title="Top Levels 2")// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=0, title="Bottom Levels 2")// BUY CONDITIONSstopLevelCalc = valuewhen(pvtlo_, low[pvtLenR], 0) //Stop Level at Swing LowbuyLevel = valuewhen(pvthi_, high[pvtLenR], 0) //Buy level at Swing Highplot(buyLevel, style=plot.style_line, color=color.blue, title = "Current Breakout Level", show_last=1, linewidth=1, transp=50, trackprice=true)// Conditions for entry and exitstopLevel = float(na) // Define stop level here as "na" so that I can reference it in the inPosition // variable and the ATR calculation before the stopLevel is actually defined.buyConditions = (useMaFilter ? buyLevel > ma3 : true) and (useAtrFilter ? (buyLevel - stopLevel[1]) < atrValue : true) and time > Start and time < Finish// buySignal = high > buyLevel and buyConditionsbuySignal = crossover(high, buyLevel) and buyConditionstrailMa = trailMaInput == "1st Moving Average" ? ma1 : ma2sellSignal = crossunder(close, trailMa)// sellSignal = security(syminfo.tickerid, htf, close < trailMa) and security(syminfo.tickerid, htf, close[1] < trailMa)// STOP AND PRICE LEVELSinPosition = bool(na)inPosition := buySignal[1] ? true : sellSignal[1] ? false : low <= stopLevel[1] ? false : inPosition[1]lowDefine = lowest(low, lbStop)stopLevel := inPosition ? stopLevel[1] : lowDefine// plot(stopLevel)buyPrice = buyLevelbuyPrice := inPosition ? buyPrice[1] : buyLevelplot(stopLevel, style=plot.style_line, color=color.orange, title = "Current Stop Level", show_last=1, linewidth=1, transp=50, trackprice=true)plot(inPosition ? stopLevel : na, style=plot.style_circles, color=color.orange, title = "Historical Stop Levels", transp=50, trackprice=false)// plot(buyPrice, style=plot.style_line, color=color.blue, linewidth=1, transp=50, trackprice=true)// (STRATEGY ONLY) Comment out for Studystrategy.entry("Long", strategy.long, stop = buyLevel, when = buyConditions)strategy.exit("Exit Long", from_entry = "Long", stop=stopLevel[1])if (low[1] > trailMa) strategy.close("Long", when = sellSignal)// if (low[1] > trailMa)// strategy.exit("Exit Long", from_entry = "Long", stop=trailMa) //to get this to work right, I need to reference highest highs instead of swing highs //because it can have me buy right back in after selling if the stop level is above the last registered swing high point.