OPEN-SOURCE SCRIPT
[COG] Nautilus

Overview
This indicator combines multiple technical analysis tools to identify high-probability entry points in trending markets. It uses moving average crossovers for trend direction, Bollinger Bands for mean reversion opportunities, and optional filters to reduce false signals and avoid choppy market conditions.
What Makes This Indicator Unique
Heiken Ashi Toggle:
All calculations can be performed on either regular or Heiken Ashi candles with a single click
Multi-Layer Filtering System: Four independent filters work together to improve signal quality
First Entry Detection: Automatically identifies and labels the first signal after a trend change
Anti-Overtrading Protection: Built-in cooldown mechanism prevents signal spam
Core Components
1. Trend Detection (EMA/SMA Crossover)
The indicator uses a 15-period EMA and 50-period SMA to determine market direction. Buy signals only occur when EMA > SMA, and sell signals only when EMA < SMA.
Pine Script®
2. Bollinger Bands Mean Reversion
Entry signals trigger when price touches or penetrates the Bollinger Bands, indicating potential reversal or pullback opportunities within the established trend.
Pine Script®
3. Candle Confirmation
Signals require a bullish candle close (close > open) for buy signals and bearish candle close (close < open) for sell signals, ensuring momentum alignment.
Pine Script®
Optional Filters (All Toggleable)
Filter 1: StochRSI Momentum
Ensures entries occur during oversold/overbought conditions. Buy signals require StochRSI < 20, sell signals require StochRSI > 80.
Pine Script®
Filter 2: MA Separation (Anti-Chop)
Blocks signals when moving averages are too close together, indicating sideways/choppy market conditions. Default threshold is 1% separation.
Pine Script®
Why this matters: When the 15 EMA and 50 SMA are very close (< 1% apart), the market is typically consolidating. Signals in these conditions have lower win rates.
Filter 3: Cooldown Period
Prevents over-trading by blocking new signals for a specified number of bars (default: 10) after a signal occurs. Buy and sell cooldowns are tracked separately.
Pine Script®
Advanced Features
Heiken Ashi Mode
Toggle between regular candles and Heiken Ashi candles for all calculations. Heiken Ashi candles smooth price action and can reduce false signals in volatile markets.
Pine Script®
First Entry Detection
Automatically identifies and labels the first signal after a trend change with "1. Trend Cycle Entry" text. This helps traders distinguish between fresh trend entries and continuation signals.
Pine Script®
How Signals Are Generated
The indicator uses a layered approach where each condition must be satisfied:
Pine Script®
Buy Signal Requirements:
✅ 15 EMA above 50 SMA (bullish trend)
✅ Candle low touches or goes below lower Bollinger Band
✅ Candle closes bullish (green)
✅ (Optional) StochRSI < 20
✅ (Optional) MA separation > threshold %
✅ (Optional) Cooldown period expired
Sell Signal Requirements:
✅ 15 EMA below 50 SMA (bearish trend)
✅ Candle high touches or goes above upper Bollinger Band
✅ Candle closes bearish (red)
✅ (Optional) StochRSI > 80
✅ (Optional) MA separation > threshold %
✅ (Optional) Cooldown period expired
Customization Options
Moving Averages:
Adjustable EMA length (default: 15)
Adjustable SMA length (default: 50)
Source selection (Close, Open, High, Low, HL2, HLC3, OHLC4)
Bollinger Bands:
Adjustable length (default: 20)
MA type selection (SMA, EMA, SMMA, WMA, VWMA)
Adjustable standard deviation multiplier (default: 2.0)
StochRSI Filter:
Adjustable RSI length (default: 14)
Adjustable Stochastic length (default: 14)
Customizable oversold/overbought levels (default: 20/80)
MA Separation Filter:
Adjustable minimum separation percentage (default: 1.0%)
Cooldown Filter:
Adjustable cooldown period in bars (default: 10)
Visual Settings:
Customizable colors for all elements
Adjustable line widths
Toggle first entry labels on/off
How to Use
Basic Setup: Apply the indicator to your chart. By default, it shows moving averages, Bollinger Bands, and entry signals.
Choose Your Mode: Enable Heiken Ashi mode if you prefer smoother signals and are willing to accept some lag.
Enable Filters: Start with all filters disabled to see raw signals. Then enable filters one by one:
Start with MA Separation filter to avoid choppy markets
Add StochRSI filter to catch better momentum conditions
Add Cooldown filter to prevent over-trading
Adjust Parameters: Tune the parameters based on your timeframe and trading style:
Lower timeframes: Consider shorter cooldown periods
Higher timeframes: May want tighter MA separation requirements
Watch for First Entry Labels: The "1. Trend Cycle Entry" label highlights the highest-probability signals occurring right after trend changes.
Important Notes
⚠️ This indicator does not repaint. All signals appear on closed candles only.
⚠️ Past performance is not indicative of future results. This indicator should be used as part of a complete trading strategy with proper risk management.
⚠️ Filters reduce signal frequency: Enabling multiple filters will significantly reduce the number of signals. This is intentional to improve quality over quantity.
⚠️ Heiken Ashi mode considerations: While HA mode smooths signals, it can also introduce lag. Test both modes on your preferred timeframe.
Best Practices
Always backtest on your preferred timeframe before live trading
Start conservative with tighter filters, then loosen if needed
Pay special attention to "First Entry" signals for highest probability setups
Use appropriate position sizing and stop losses
Consider market conditions: trending vs ranging
Disclaimer
This indicator is for educational purposes only and should not be considered financial advice. Trading involves substantial risk of loss. Always do your own research and consider your risk tolerance before trading.
This indicator combines multiple technical analysis tools to identify high-probability entry points in trending markets. It uses moving average crossovers for trend direction, Bollinger Bands for mean reversion opportunities, and optional filters to reduce false signals and avoid choppy market conditions.
What Makes This Indicator Unique
Heiken Ashi Toggle:
All calculations can be performed on either regular or Heiken Ashi candles with a single click
Multi-Layer Filtering System: Four independent filters work together to improve signal quality
First Entry Detection: Automatically identifies and labels the first signal after a trend change
Anti-Overtrading Protection: Built-in cooldown mechanism prevents signal spam
Core Components
1. Trend Detection (EMA/SMA Crossover)
The indicator uses a 15-period EMA and 50-period SMA to determine market direction. Buy signals only occur when EMA > SMA, and sell signals only when EMA < SMA.
// Trend Detection
bullishTrend = ema15 > sma50
bearishTrend = ema15 < sma50
2. Bollinger Bands Mean Reversion
Entry signals trigger when price touches or penetrates the Bollinger Bands, indicating potential reversal or pullback opportunities within the established trend.
//Bollinger Band Touch Detection
lowerBandTouch = selectedLow <= bbLower
upperBandTouch = selectedHigh >= bbUpper
// Base Entry Conditions
baseBuySignal = bullishTrend and lowerBandTouch and bullishClose
baseSellSignal = bearishTrend and upperBandTouch and bearishClose
3. Candle Confirmation
Signals require a bullish candle close (close > open) for buy signals and bearish candle close (close < open) for sell signals, ensuring momentum alignment.
// Candle Close Type
bullishClose = selectedClose > selectedOpen
bearishClose = selectedClose < selectedOpen
Optional Filters (All Toggleable)
Filter 1: StochRSI Momentum
Ensures entries occur during oversold/overbought conditions. Buy signals require StochRSI < 20, sell signals require StochRSI > 80.
// StochRSI Calculation
rsi = ta.rsi(stochRSISource, rsiLength)
stochRSI_K = ta.sma(ta.stoch(rsi, rsi, rsi, stochRSILength), stochKSmooth)
// Filter Conditions
stochRSIOversoldCondition = stochRSI_K < stochRSIOversold
stochRSIOverboughtCondition = stochRSI_K > stochRSIOverbought
Filter 2: MA Separation (Anti-Chop)
Blocks signals when moving averages are too close together, indicating sideways/choppy market conditions. Default threshold is 1% separation.
// Calculate percentage separation between EMA and SMA
maSeparationPct = (math.abs(ema15 - sma50) / sma50) * 100
// MA separation filter condition
maSeparationValid = maSeparationPct >= maSeparationThreshold
Why this matters: When the 15 EMA and 50 SMA are very close (< 1% apart), the market is typically consolidating. Signals in these conditions have lower win rates.
Filter 3: Cooldown Period
Prevents over-trading by blocking new signals for a specified number of bars (default: 10) after a signal occurs. Buy and sell cooldowns are tracked separately.
// Variables to track the bar index of the last signal
var int lastBuySignalBar = na
var int lastSellSignalBar = na
// Calculate bars since last signal
barsSinceLastBuy = na(lastBuySignalBar) ? 999999 : bar_index - lastBuySignalBar
// Cooldown filter condition
buyCooldownValid = barsSinceLastBuy >= cooldownBars
// Update tracking when signal fires
if buySignal
lastBuySignalBar := bar_index
Advanced Features
Heiken Ashi Mode
Toggle between regular candles and Heiken Ashi candles for all calculations. Heiken Ashi candles smooth price action and can reduce false signals in volatile markets.
// Fetch Heiken Ashi OHLC values
[haOpen, haHigh, haLow, haClose] = request.security(
ticker.heikinashi(syminfo.tickerid),
timeframe.period,
[open, high, low, close]
)
// Select which OHLC to use based on toggle
selectedClose = useHeikenAshi ? haClose : close
First Entry Detection
Automatically identifies and labels the first signal after a trend change with "1. Trend Cycle Entry" text. This helps traders distinguish between fresh trend entries and continuation signals.
// Detect trend changes
trendChangedToBullish = bullishTrend and not bullishTrend[1]
// Reset tracking when trend changes
if trendChangedToBullish
hadBuySignalInCurrentBullTrend := false
// Identify first signal in new trend
isFirstBuyInTrendCycle = buySignal and not hadBuySignalInCurrentBullTrend
How Signals Are Generated
The indicator uses a layered approach where each condition must be satisfied:
// Apply all filters
buySignal = enableBuySignals and baseBuySignal and
(not enableStochRSIFilter or stochRSIOversoldCondition) and
(not enableMASeparationFilter or maSeparationValid) and
(not enableCooldownFilter or buyCooldownValid)
Buy Signal Requirements:
✅ 15 EMA above 50 SMA (bullish trend)
✅ Candle low touches or goes below lower Bollinger Band
✅ Candle closes bullish (green)
✅ (Optional) StochRSI < 20
✅ (Optional) MA separation > threshold %
✅ (Optional) Cooldown period expired
Sell Signal Requirements:
✅ 15 EMA below 50 SMA (bearish trend)
✅ Candle high touches or goes above upper Bollinger Band
✅ Candle closes bearish (red)
✅ (Optional) StochRSI > 80
✅ (Optional) MA separation > threshold %
✅ (Optional) Cooldown period expired
Customization Options
Moving Averages:
Adjustable EMA length (default: 15)
Adjustable SMA length (default: 50)
Source selection (Close, Open, High, Low, HL2, HLC3, OHLC4)
Bollinger Bands:
Adjustable length (default: 20)
MA type selection (SMA, EMA, SMMA, WMA, VWMA)
Adjustable standard deviation multiplier (default: 2.0)
StochRSI Filter:
Adjustable RSI length (default: 14)
Adjustable Stochastic length (default: 14)
Customizable oversold/overbought levels (default: 20/80)
MA Separation Filter:
Adjustable minimum separation percentage (default: 1.0%)
Cooldown Filter:
Adjustable cooldown period in bars (default: 10)
Visual Settings:
Customizable colors for all elements
Adjustable line widths
Toggle first entry labels on/off
How to Use
Basic Setup: Apply the indicator to your chart. By default, it shows moving averages, Bollinger Bands, and entry signals.
Choose Your Mode: Enable Heiken Ashi mode if you prefer smoother signals and are willing to accept some lag.
Enable Filters: Start with all filters disabled to see raw signals. Then enable filters one by one:
Start with MA Separation filter to avoid choppy markets
Add StochRSI filter to catch better momentum conditions
Add Cooldown filter to prevent over-trading
Adjust Parameters: Tune the parameters based on your timeframe and trading style:
Lower timeframes: Consider shorter cooldown periods
Higher timeframes: May want tighter MA separation requirements
Watch for First Entry Labels: The "1. Trend Cycle Entry" label highlights the highest-probability signals occurring right after trend changes.
Important Notes
⚠️ This indicator does not repaint. All signals appear on closed candles only.
⚠️ Past performance is not indicative of future results. This indicator should be used as part of a complete trading strategy with proper risk management.
⚠️ Filters reduce signal frequency: Enabling multiple filters will significantly reduce the number of signals. This is intentional to improve quality over quantity.
⚠️ Heiken Ashi mode considerations: While HA mode smooths signals, it can also introduce lag. Test both modes on your preferred timeframe.
Best Practices
Always backtest on your preferred timeframe before live trading
Start conservative with tighter filters, then loosen if needed
Pay special attention to "First Entry" signals for highest probability setups
Use appropriate position sizing and stop losses
Consider market conditions: trending vs ranging
Disclaimer
This indicator is for educational purposes only and should not be considered financial advice. Trading involves substantial risk of loss. Always do your own research and consider your risk tolerance before trading.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
CognitiveAlpha
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
CognitiveAlpha
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.