This is a trend-following breakout strategy written in Pine Script v5. Let me break it down section by section so you can see the logic clearly:
? Strategy Setup
strategy(title="CRCL Trend-Following...", overlay=true,
initial_capital=100000, commission_type=strategy.commission.percent, commission_value=0.02,
pyramiding=0, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
-
Initial capital: $100,000
-
Commission: 0.02% per trade
-
Pyramiding: 0 (no adding to existing positions)
-
Position size: 10% of equity per trade
? Inputs
-
Moving Averages: MA50 (short) and MA200 (long)
-
Momentum filters: RSI (daily & weekly), MACD
-
Breakout filters: Must be within 15% of 52-week high, and break above N-day high (default 20 days)
-
Liquidity filters: Min price $5, min avg volume 500k, volume must exceed 20-day SMA × 1.2
-
Stops & Targets: ATR-based stop loss (default 2× ATR), or fixed % stop (7%) if ATR disabled
-
Profit target: 3× risk (R multiple)
-
Trailing stop: Optional ATR-based trailing stop (default 3× ATR)
-
Breakeven rule: Move stop to entry after 1R gain
Calculations
-
Trend check:
-
Price > MA50 > MA200
-
Both MAs sloping upward
-
-
Momentum check:
-
MACD line > 0 and above signal line
-
RSI > 50 (daily and optionally weekly)
-
-
No bottom-fishing: Must be within 15% of 52-week high
-
Breakout trigger: Close > yesterday’s N-day high
Entry Condition
entryCond = priceOK and liquidity and trendOK and momOK and wkOK and noBottom and breakout and volOK
All filters must pass: price, liquidity, trend, momentum, weekly RSI, near 52W high, breakout, and volume surge.
? Risk Management
-
Stop loss: ATR-based or % stop
-
Take profit: 3× stop distance
-
Trailing stop: Ratchets upward with ATR
-
Breakeven rule: Once price moves 1R in your favor, stop is moved to entry
Visuals
-
Plots MA50, MA200, 52-week high, stop loss, take profit, and trailing stop
-
Marks entry signals with a green triangle
Alerts
-
Entry alert when breakout condition is met
-
Stop hit alert if stop loss is triggered
-
Target hit alert if take profit is reached
Big Picture
This script enforces strict discipline:
-
Only trades uptrends near highs (no bottom-fishing)
-
Requires momentum confirmation (RSI, MACD, volume)
-
Uses strict risk control (ATR stops, breakeven, R-multiple targets)
It’s essentially a CAN SLIM–style breakout system with modern risk management.