Strategy · Pine Script v5 · On the chart

Qullamaggie Breakout Fixed

by g-moe· code credited to goodgains

This strategy trades swing high breakouts on lower timeframes in alignment with higher-timeframe moving average trends.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code160
Settings14inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

160 lines of Pine Script v5 from Tradingview/qullamaggie-breakout-fixed.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

qullamaggie-breakout-fixed.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//ORIGINAL AUTHOR DIDNT REALLY KNOW HOW TO CODE AND JUST THREW SOME SLOP TOGETHER. The update really just focuses on the entries and stops and kept the same logic for pivots / mas. The original version sometimes the stops worked and stometimes they didnt.
//Also the old strategy could of been prone to repainting with the secondary period MAs


// 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=5
strategy('Qullamaggie Breakout Fixed', 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)

// @keywords: qullamaggie-breakout, swing-high-breakout, higher-timeframe-ma, trailing-stop, atr-filter, pivot-breakout, ma-filter, long-entry, stop-loss, daily-atr, consolidating-range, ema-sma-toggle, three-moving-averages, breakout-level, risk-reward, backtest-range, position-trail, ma-trail-exit, tight-stop, trend-filter

// === BACKTEST RANGE ===
Start = input.time(defval=timestamp('01 Jan 2019 06:00 +0000'), title='Backtest Start Date')
Finish = input.time(defval=timestamp('01 Jan 2100 00:00 +0000'), title='Backtest End Date')

// Inputs
lb = input.int(defval=3, title='Lookback Period for Swing High', minval=1, tooltip='Lookback period for defining the breakout level.')
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 (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.string(defval='SMA', options=['EMA', 'SMA'], title='Moving Average Type')
ma1Length = input.int(defval=10, title='1st Moving Average Length', minval=1)
ma2Length = input.int(defval=20, title='2nd 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, 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.')

// MA Calculations
ma(maType, src, length) =>
    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 = request.security(syminfo.tickerid, htf, ma(maType, close, ma1Length)[1], lookahead = barmerge.lookahead_on)
ma2 = request.security(syminfo.tickerid, htf, ma(maType, close, ma2Length)[1], lookahead = barmerge.lookahead_on)
ma3 = request.security(syminfo.tickerid, htf, ma(maType, close, ma3Length)[1], lookahead = barmerge.lookahead_on)

plot(ma1, color=color.new(color.orange, 60), style=plot.style_line, title='MA1', linewidth=2)
plot(ma2, color=color.new(color.yellow, 60), style=plot.style_line, title='MA2', linewidth=2)
plot(ma3, color=color.new(color.white, 60), style=plot.style_line, title='MA3', linewidth=2)

// === 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.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.  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.int(defval=100, title='% of Daily ATR Value', minval=1)
atrValue = request.security(syminfo.tickerid, 'D', ta.atr(14)) * atrPerc * .01

//STOPS
initial_stop_input = input.string(defval = 'Lookback Locked', options = ['OFF', 'Lookback Locked', 'Lookback Trailing'], title='Initial Stop')
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.')
trailing_ma_stop_input = input.string(defval='2nd Moving Average', options=['OFF','1st Moving Average', '2nd Moving Average'], title='Trailing MA Stop')


// === 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 calculations
pvtLenL = lb
pvtLenR = lb

// Get High and Low Pivot Points
pvthi_ = ta.pivothigh(high, pvtLenL, pvtLenR)
pvtlo_ = ta.pivotlow(low, pvtLenL, pvtLenR)

// bgcolor(pvtlo_ ? color.new(color.aqua,60) : pvthi_ ? color.new(color.fuchsia,60) : na )
// Force Pivot completion before plotting.
Shunt = 1  //Wait for close before printing pivot? 1 for true 0 for flase
maxLvlLen = 0  //Maximum Extension Length
pvthi = pvthi_[Shunt]
pvtlo = pvtlo_[Shunt]

// Count How many candles for current Pivot Level, If new reset.
counthi = ta.barssince(not na(pvthi))
countlo = ta.barssince(not na(pvtlo))

pvthis = fixnan(pvthi)
pvtlos = fixnan(pvtlo)
hipc = ta.change(pvthis) != 0 ? na : color.maroon
lopc = ta.change(pvtlos) != 0 ? na : color.green

// Display Pivot lines
plot(maxLvlLen == 0 or counthi < maxLvlLen ? pvthis : na, color=hipc, linewidth=1, offset=-pvtLenR - Shunt, title='Top Levels')
plot(maxLvlLen == 0 or counthi < maxLvlLen ? pvthis : na, color=hipc, linewidth=1, offset=0, title='Top Levels 2')
// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=-pvtLenR-Shunt, title="Bottom Levels")
// plot((maxLvlLen == 0 or countlo < maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=0, title="Bottom Levels 2")


var float buy_level = na
var bool buy_conditions = na
var float stop_level = na
var float trail_stop_level = na
var float position_final_stop_level = na
lookback_lows = ta.lowest(low, lbStop)[1]

//
//ENTRY
//
buy_level := ta.valuewhen(pvthi_, high[pvtLenR], 0)
plot(buy_level, style=plot.style_line, color=color.new(color.blue,50), title = "Current Breakout Level", show_last=1, linewidth=1, trackprice=true)
buy_conditions := (useMaFilter ? buy_level > ma3 : true) and (useAtrFilter ? (buy_level - lookback_lows) < atrValue : true) and time > Start and time < Finish

//STOPS
in_position = not na(strategy.position_avg_price)
new_position = in_position and not in_position[1]


use_initial_stop = initial_stop_input != 'OFF'
use_trailing_ma = trailing_ma_stop_input != 'OFF'

if in_position

    if use_initial_stop and use_trailing_ma
        if initial_stop_input == 'Lookback Locked'
            if new_position 
                stop_level := lookback_lows
            else 
                stop_level := stop_level[1]
        else if initial_stop_input == 'Lookback Trailing'
            stop_level := lookback_lows
            
        if trailing_ma_stop_input == '1st Moving Average'
            trail_stop_level := ma1
        else if trailing_ma_stop_input == '2nd Moving Average'
            trail_stop_level := ma2
        position_final_stop_level := math.max(stop_level, trail_stop_level)
    
    else if use_initial_stop and not use_trailing_ma
        if initial_stop_input == 'Lookback Locked'
            if new_position 
                position_final_stop_level := lookback_lows
            else 
                position_final_stop_level := position_final_stop_level[1]
        else if initial_stop_input == 'Lookback Trailing'
            position_final_stop_level := lookback_lows
            
    else if not use_initial_stop and use_trailing_ma
        if trailing_ma_stop_input == '1st Moving Average'
            position_final_stop_level := ma1
        else if trailing_ma_stop_input == '2nd Moving Average'
            position_final_stop_level := ma2
            
    position_final_stop_level 
    
else
    stop_level := na
    trail_stop_level := na
    position_final_stop_level := na

plot(position_final_stop_level, color = color.blue, linewidth = 5, style = plot.style_linebr, title = "Stop Level")

if buy_conditions
    strategy.entry('LE', strategy.long, stop=buy_level)
else
    strategy.cancel_all(when = not buy_conditions)

    
strategy.exit('LX', from_entry='LE', stop=position_final_stop_level)

// barcolor(buy_conditions ? color.green : na(buy_conditions) ? color.fuchsia : na)

Overview

Qullamaggie Breakout Fixed evaluates price highs using a configurable lookback period and applies higher-timeframe moving average filters along with an optional ATR volatility filter to identify consolidation setups. Position entries utilize an initial lookback stop loss and trail exits behind higher-timeframe moving averages as the trade progresses. All indicators and entry signals plot directly on the main price chart.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Breakout, Moving averages, Volatility & bands

Markets

Stocks, Crypto

Timeframes

M15-H1, H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Backtest Start Datetimetimestamp('01 Jan 2019 06:00 +0000')Start
Backtest End Datetimetimestamp('01 Jan 2100 00:00 +0000')Finish
Lookback Period for Swing Highint3lb
Timeframe of Moving AveragestimeframeDhtf
Moving Average TypestringSMAmaType
1st Moving Average Lengthint10ma1Length
2nd Moving Average Lengthint20ma2Length
3rd Moving Average Lengthint50ma3Length
Use 3rd Moving Average for Filtering?booltrueuseMaFilter
Use ATR for Filtering?boolfalseuseAtrFilter
% of Daily ATR Valueint100atrPerc
Initial StopstringLookback Lockedinitial_stop_input
Show all 14 settings
SettingTypeDefaultVariable
Lookback Bars for Stop Levelint3lbStop
Trailing MA Stopstring2nd Moving Averagetrailing_ma_stop_input
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

106 stars

This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side. Entries also need ATR above a filter, a pullback check, a minimum candle-body chang

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 9:22 5 MIN 15 MIN BANKNIFTY

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统
16 stars

This strategy plots Donchian channels, trailing stops, and profit targets directly on the price chart. It enters breakout trades using a 55-bar Donchian channel and sizes positions according to an ATR-based risk percentage per unit. The system adds units as pr

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 10: Profit Targets
4 stars

This strategy executes trend-following trades based on Bollinger Band breakouts confirmed by a long-term moving average filter. A long position opens when the price crosses above the upper Bollinger Band, provided the band spread meets a minimum threshold and

Strategy v5 Volatility & bandsTrend
Updated 2 years ago · None stated GitHub repository of Bollinger Trend - Strategy V1
4 stars

The Keltner Channel Strategy is a breakout system plotted directly on the main price chart. It calculates upper and lower channel bands around an exponential or simple moving average using ATR, True Range, or bar range multiplied by a specified factor. A long

Strategy v5 TrendVolatility & bands
Updated 5 months ago · None stated GitHub repository of Keltner Channel Strategy

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers