OPEN-SOURCE SCRIPT

Bull Flag & Flat Top Breakout Detector

42
Bull Flag & Flat Top Detector - Quick Reference Guide
Pattern Overview
🚩 Bull Flag
╱╲
╱ ╲ ← Pullback (2-5 red candles)
╱ ╲
╱ ╲____
╱ ╲
│ │
│ THE POLE │ ← Strong upward move (3+ green candles)
│ │
└──────────────┘
What to look for:

Strong initial move (the "pole") - 3+ green candles, 3%+ move
Brief pullback - 2-5 candles, less than 50% retracement
Pullback should "drift" lower, not crash
Entry on first candle to make new high after pullback


📊 Flat Top Breakout
════════════════ ← Resistance (multiple touches)
↑ ↑ ↑
╱╲ ╱╲ ╱╲
╱ ╲╱ ╲╱ ╲ ← Consolidation
╱ ╲
╱ ╲
What to look for:

Multiple touches of same resistance level (2+)
Tight consolidation range
Each failed breakout builds pressure
Entry on convincing break above resistance with volume


Signal Types
SignalShapeColorMeaningBull Flag Breakout▲ TriangleLimeEntry signal - go longFlat Top Breakout◆ DiamondAquaEntry signal - go longBear Flag Breakout▼ TriangleRedShort entry (if enabled)Pattern Forming🚩 FlagFaded GreenBull flag developingPattern Forming■ SquareFaded BlueFlat top developing

Level Lines Explained
LineColorStyleMeaningEntryLimeSolidBreakout trigger priceStop LossRedDashedExit if price falls hereTarget 1AquaDottedFirst profit target (2R)Target 2YellowDottedSecond profit target (3R)

Info Table Reference
FieldWhat It ShowsBull FlagScanning / Forming 🚩 / Breakout ✓Flat TopScanning / Forming 📊 / Breakout ✓PullbackCandle count + retracement %Rel VolumeCurrent bar vs averageEMA 20Above ✓ or Below ✗VWAPAbove ✓ or Below ✗Green StreakConsecutive green candles (pole)ResistanceTouch count for flat top

Trading Checklist
Before Entry ✅

Pattern status shows "FORMING" or "BREAKOUT"
Price above EMA (table shows ✓)
Price above VWAP (table shows ✓)
Relative volume 1.5x+ (ideally 2x+)
Stock is in play (up 5%+ on day, has catalyst)
Market direction supportive (not fighting trend)

Entry Execution

Wait for breakout candle to form
Confirm volume spike on breakout
Enter as close to entry line as possible
Set stop loss at red dashed line
Know your target levels

Trade Management

If no immediate follow-through → consider exit ("breakout or bailout")
Take 50% off at Target 1
Move stop to breakeven
Let remainder run toward Target 2
Exit fully if price returns below entry


Bull Flag Quality Checklist
Pole Quality:
FactorIdealAcceptableAvoidGreen candles5+3-4Less than 3Move size10%+3-10%Less than 3%VolumeIncreasingSteadyDecliningCandle bodiesLargeMediumSmall/doji
Pullback Quality:
FactorIdealAcceptableAvoidCandle count2-34-56+RetracementUnder 38%38-50%Over 50%VolumeDecliningSteadyIncreasingCharacterOrderly driftChoppySharp drop

Flat Top Quality Checklist
FactorGood SetupWeak SetupTouches3+ at same levelOnly 2, widely spacedToleranceVery tight (0.2%)Loose (1%+)Duration5-15 barsToo short or too longVolumeDrying upErraticPrior trendUpSideways/down

Common Mistakes to Avoid
❌ Entering too early

Wait for actual breakout, not anticipation
"Forming" ≠ "Breakout"

❌ Ignoring volume

No volume = likely false breakout
Require 1.5x+ relative volume minimum

❌ Fighting the trend

Check EMA and VWAP status
Both should be ✓ for high probability

❌ Wide stops

Stop should be below pullback low
If stop is too wide, skip the trade

❌ Holding losers

"Breakout or bailout" - if it doesn't work, exit
Failed breakouts often reverse hard

❌ Chasing extended moves

If you missed entry, wait for next pattern
Don't chase 5+ candles after breakout


Risk Management Rules
Position Sizing
Risk Amount = Account × Risk % (typically 1-2%)
Position Size = Risk Amount ÷ (Entry - Stop)
Example:

Account: $25,000
Risk: 1% = $250
Entry: $5.00
Stop: $4.70
Risk per share: $0.30
Position Size: $250 ÷ $0.30 = 833 shares

Risk-Reward Targets
TargetR MultipleExample (risk $0.30)Target 12:1+$0.60 ($5.60)Target 23:1+$0.90 ($5.90)

Timeframe Guide
TimeframeProsConsBest For1-minMore patterns, precise entryNoisy, false signalsScalping5-minGood balance, cleaner patternsFewer signalsDay trading15-minHigh quality patternsMiss fast movesSwing entries

Settings Quick Reference
Default Settings (Balanced)
Pole: 3 candles, 3% move
Pullback: 2-5 candles, 50% max retrace
Volume: 1.5x required
Filters: EMA + VWAP ON
Aggressive Settings
Pole: 2 candles, 2% move
Pullback: 2-6 candles, 60% max retrace
Volume: 1.2x required
Filters: VWAP OFF
Conservative Settings
Pole: 4 candles, 5% move
Pullback: 2-4 candles, 40% max retrace
Volume: 2.0x required
Filters: Both ON

Alert Setup
Recommended Alerts

"Bull Flag Forming"

Get early warning as pattern develops
Prepare your position size and levels


"Bull Flag Breakout"

Primary entry alert
React quickly when triggered


"Any Bullish Breakout"

Catch both bull flags and flat tops
Good for watchlist scanning



Alert Setup Steps

Right-click chart → Add Alert
Condition: Select "Bull Flag & Flat Top Breakout Detector"
Choose alert type from dropdown
Set expiration and notification method


Troubleshooting
Q: Patterns not detecting?

Lower the Min Pole Move % setting
Reduce Min Pole Candles requirement
Check that price is in acceptable range

Q: Too many false signals?

Increase volume multiplier to 2.0x
Enable both EMA and VWAP filters
Increase Min Pole Move %

Q: Levels not showing?

Enable "Show Entry Line", "Show Stop Loss", "Show Targets"
Check "Max Patterns to Display" setting

Q: Info table not visible?

Enable "Show Info Table" in settings
Try different table position


Pattern Combinations
Best Setups (A+ Quality)

Bull flag on a gap day (Gap & Go → Bull Flag)
Flat top at pre-market high resistance
Pattern forming above VWAP with 5x+ volume

Avoid These

Bull flag below VWAP
Flat top in downtrending stock
Low volume patterns
Patterns late in the day (after 2pm)


Daily Routine
Pre-Market (7-9am)

Build watchlist of gappers (5%+, high volume)
Apply indicator to top 3-5 candidates
Note pre-market levels

Market Open (9:30-10:30am)

Watch for "FORMING" status on watchlist
Prepare entries as patterns develop
Execute on breakout signals
Manage trades according to plan

Midday (10:30am-2pm)

Look for second-wave patterns
Be more selective (less momentum)
Consider tighter stops

Close (2-4pm)

Generally avoid new patterns
Manage existing positions
Review day's trades

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.