PROTECTED SOURCE SCRIPT

4-Hour Trend Strategy

95
4-Hour Trend Strategy
This Pine Script® (v6) indicator is designed for high-conviction trend following on the 4-hour (240m) timeframe. It utilizes a multi-step confirmation process—Trend, Trigger, and Entry—to filter out market noise and identify high-probability reversal or continuation setups.

📈 Strategy Overview
The strategy follows a disciplined 3-step state machine logic to ensure trades are only taken when momentum and price action align.
1. The Trend Candle (State 1)
The process begins when the 4-hour price crosses the 50-period Simple Moving Average (SMA 50).
  • Long Bias: Price closes above SMA 50.
  • Short Bias: Price closes below SMA 50.
  • Visual: The candle bar color turns White.


2. The Trigger Candle (State 2)
Once a trend is identified, we wait for moving average momentum to confirm.
  • Long Trigger: SMA 5 crosses over SMA 50.
  • Short Trigger: SMA 5 crosses under SMA 50.
  • Visual: The candle bar turns Lime (Long) or Yellow (Short).


3. The Entry Candle (Execution)
We do not "chase" the trigger. Instead, we wait for a minor mean reversion (pullback) to the SMA 5.
  • Buy Entry: Price retraces down to touch or go below SMA 5 while in a Long Setup.
  • Sell Entry: Price retraces up to touch or go above SMA 5 while in a Short Setup.
  • Visual: A Green Triangle (Buy) or Red Triangle (Sell) appears.


🛠 Features
Multi-Timeframe Analysis: Automatically fetches SMA 200 from the Daily timeframe and SMA 50/5/10 from the 4-Hour timeframe, regardless of your current chart view.
Dynamic Stop Loss Levels: Upon entry, the script calculates and draws three distinct risk management levels:
  • 1x ATR: Tight stop for aggressive momentum.
  • 2x ATR: Standard stop for trend volatility.
  • 50 SMA: Structural stop based on the primary trend line.

Clean UI: A "Show Only Latest" toggle ensures your chart isn't cluttered with old labels, keeping your focus on the current live setup.
Visual Backgrounds: The chart background is shaded Green (Bullish territory) or Red (Bearish territory) based on price relation to the SMA 50.

⚙️ Inputs & Configuration
Input | Default | Description
ATR Period | 20 | Period used to calculate volatility for Stop Loss levels.
Show Only Latest | True | When enabled, only the most recent signal's lines and labels are visible.

🚀 How to Use
  1. Installation: Copy the code into the Pine Editor on TradingView and click "Add to Chart."
  2. Identify the Bias: Watch for the background color and the White "Trend" candle.
  3. Wait for Trigger: Look for the Lime/Yellow bars indicating SMA crossover.
  4. Execute on Signal: Enter when the Triangle signal appears. Use the projected Blue Entry Line and Black SL Lines to set your orders.


Note: This is an Indicator, not a Strategy (backtesting) script. It provides visual signals and labels for manual execution or alert integration.

Disclaimer: This script is for educational and informational purposes only. Trading involves significant risk. Always perform your own due diligence.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.