OPEN-SOURCE SCRIPT
更新済

EMA Ribbon Retest (Non-Repaint)

726
EMA Ribbon Retest (Non-Repaint) + Stochastic RSI Exit System
Overview

This indicator combines an EMA Ribbon structure, a trend-based retest detection system, and a Stochastic RSI exit mechanism to provide clean, non-repainting buy/sell signals with structured trade management logic.

It is designed for traders who focus on trend continuation entries after pullbacks (retests) and want a systematic exit strategy based on momentum exhaustion.

Core Components
1. EMA Ribbon Trend Structure

The indicator uses four exponential moving averages:

EMA 20
EMA 50
EMA 100
EMA 200

These EMAs form a trend ribbon that defines market direction:

Bullish Trend: EMA 20 > EMA 50 > EMA 100 > EMA 200
Bearish Trend: EMA 20 < EMA 50 < EMA 100 < EMA 200

This structure filters trades only in clear directional markets.

2. Ribbon Compression Filter

Before a valid setup is considered, the indicator checks for EMA ribbon compression.

Ribbon width is calculated as the percentage distance between the highest and lowest EMA relative to price.
When this width is below the defined threshold, the market is considered compressed (consolidation phase).

This helps identify accumulation zones before breakout continuation moves.

3. Retest Logic (Entry Signals)

The system looks for price returning to the midpoint of the EMA ribbon after compression.

Buy Setup:

A BUY signal is triggered when:

Market is in bullish trend
Previous candle shows ribbon compression
Price retests the mid-ribbon zone
Price closes back above the midpoint
Sell Setup:

A SELL signal is triggered when:

Market is in bearish trend
Previous candle shows ribbon compression
Price retests the mid-ribbon zone
Price closes back below the midpoint

This creates a trend continuation after pullback strategy.

4. Non-Repaint Signal Engine

To ensure reliability:

Signals are only confirmed on closed candles
A cooldown period prevents repeated signals in a short time
Prevents signal clustering during choppy market conditions
5. Stochastic RSI Exit System

The indicator includes a momentum-based exit filter using Stochastic RSI (K & D lines).

Long Position Exit:
Triggered when Stochastic RSI is above the upper band (default 80)
AND a bearish crossover occurs (K crosses below D)
Short Position Exit:
Triggered when Stochastic RSI is below the lower band (default 20)
AND a bullish crossover occurs (K crosses above D)

This ensures exits happen when momentum starts fading, not randomly.

Position State Logic

The script maintains internal position tracking:

Activates long state after BUY signal
Activates short state after SELL signal
Resets position state on exit conditions

This allows structured trade lifecycle logic inside an indicator.

Visual Features
EMA ribbon displayed with 4 colored EMAs
Background highlight during compression phases
BUY / SELL labels directly on chart
EXIT markers for trade management
Clean and minimal visual structure for clarity
Alerts

The script includes alert conditions for:

BUY signals
SELL signals
BUY exits
SELL exits

These can be used for real-time notifications or automation workflows.

Strategy Concept

This indicator is based on a three-stage market model:

Compression Phase → Market builds energy
Retest Phase → Price revisits equilibrium zone
Continuation Phase → Trend resumes

Combined with momentum-based exits, it creates a full trend continuation system with structured risk control.

Best Use Cases
Trend trading
Swing trading
Breakout continuation strategies
Multi-timeframe analysis (higher TF = stronger signals)
Notes
This is a non-repainting indicator
Signals are confirmed only on closed candles
Best performance in trending markets
リリースノート
📊 EMA Ribbon Retest (Non-Repaint) – Strategy Overview
🔷 General Concept

This indicator is based on an EMA Ribbon compression and breakout-retest model combined with trend direction filtering.

It uses 4 exponential moving averages:

EMA 20
EMA 50
EMA 100
EMA 200

Together, they form an EMA Ribbon structure that defines market trend and volatility phases.

🔶 1. Trend Detection

Trend direction is determined by EMA alignment:

📈 Bullish Trend:
EMA20 > EMA50 > EMA100 > EMA200
📉 Bearish Trend:
EMA20 < EMA50 > EMA100 > EMA200

This ensures trades are only taken in the direction of the dominant momentum.

🔶 2. Ribbon Compression (Squeeze Phase)

When EMAs move closer together, the market enters a compression phase.

Ribbon width is calculated as a percentage of price
If the width drops below a defined threshold:
→ Compression is activated

📌 This phase typically represents low volatility before expansion

🔶 3. Retest Signal Logic
🟢 BUY Signal
Bullish trend confirmed
Previous bar shows compression
Price retests the mid ribbon level
Price closes back above the level
🔴 SELL Signal
Bearish trend confirmed
Previous bar shows compression
Price retests the mid ribbon level from above
Price closes back below the level

📌 This is based on a breakout → retest → continuation structure.

🔶 4. Non-Repaint Logic
Signals are confirmed only on bar close
Built-in cooldown prevents signal spam
Ensures cleaner and more reliable entries
🔶 5. Visual Elements
EMA Ribbon displayed directly on chart
Compression phases highlighted with background color
BUY/SELL signals shown as labels on chart
🧠 UPDATED TAKE PROFIT (TP) SYSTEM

A new EMA-based percentage take profit system has been added.

🔷 TP Logic

Each trade uses EMA20 (EMA1) as a dynamic reference level:

The EMA value at the moment of entry is locked
A percentage-based target is applied from that level
🟢 LONG TAKE PROFIT

After a BUY signal:

TP Level = EMA20 × (1 + TP%)

📌 When price reaches this level:
→ LONG TP is triggered and position is closed

🔴 SHORT TAKE PROFIT

After a SELL signal:

TP Level = EMA20 × (1 - TP%)

📌 When price reaches this level:
→ SHORT TP is triggered and position is closed

🔔 TP FEATURES
Separate LONG and SHORT TP conditions
Individual visual labels for each TP event
Independent alert conditions
TP levels plotted directly on the chart
System resets after TP execution
📌 Why EMA-Based TP?
More adaptive than fixed % or ATR targets
Aligns with trend structure
Reduces premature exits in strong trends
Dynamically adjusts to market conditions
🚀 Summary

This system follows a 3-phase structure:

Compression (Squeeze Phase)
Breakout + Retest (Entry Signal)
Trend Continuation + EMA-Based TP (Exit Strategy)
📈 Recommended Usage
Performs best on 1H and higher timeframes
Works strongest in trending markets
May produce more signals in ranging conditions
リリースノート
🧠 TAKE PROFIT (TP) SYSTEM UPDATE – MULTI-SIGNAL VERSION
🔷 1. Previous System Limitation

In the original TP logic:

A single positionState was used (Long / Short / Flat)
New signals would overwrite previous trade data
TP levels could be replaced or invalidated by new signals
Trade behavior was not fully realistic in multi-signal conditions

📌 Result:

TP sometimes appeared delayed or inconsistent
Signal overlap caused unstable behavior
Backtest execution did not fully reflect real trade flow
🔷 2. New System Concept

The updated TP system introduces a major improvement:

❗ Every BUY/SELL signal now creates an independent trade instance.

This means:

Each signal = a new trade
Each trade = its own TP level
Trades do not interfere with each other
🔶 3. TP Calculation Logic

At the moment of each signal:

🟢 Long Trade
TP = EMA20 × (1 + TP%)
🔴 Short Trade
TP = EMA20 × (1 - TP%)

📌 Important:

EMA value is locked at entry
TP does NOT change even if EMA moves later
🔷 4. Active Trade Tracking

The system uses independent states:

longActive
shortActive

This ensures:

Long and short trades do not interfere
Each trade follows its own lifecycle
Clean and stable state management
🔷 5. TP Trigger Logic
🟢 Long TP Condition:
high >= longTp
🔴 Short TP Condition:
low <= shortTp
🔷 6. Reset After TP

Once TP is hit:

Trade is closed
TP level is cleared
System resets for the next signal
longActive = false
shortActive = false
🔷 7. Visual & Alert System

Each TP event includes:

📍 LONG TP label
📍 SHORT TP label
📈 TP level plotted on chart
🔔 Separate alert conditions for each direction
🚀 FINAL RESULT

With this update, the system becomes:

✔ Closer to real trade execution logic
✔ Fully independent per-signal trading
✔ Resistant to signal overlap issues
✔ More stable and accurate in backtesting
リリースノート
This additional code adds an EMA4 (200 EMA) based exit system to the indicator.

After a BUY signal is generated, if the price moves below EMA4, a BUY EXIT signal is triggered.
After a SELL signal is generated, if the price moves above EMA4, a SELL EXIT signal is triggered.
When an exit condition is met, an EXIT label is displayed on the chart and an alert can be triggered.
To prevent multiple exit signals from being generated for the same trade, the trade state is reset after the exit and the system waits for a new BUY or SELL signal.

This allows EMA4 to act as a dynamic trend-based exit filter, helping identify when the trade direction is no longer supported by the overall trend.
リリースノート
SuperTrend Exit System:
A separate SuperTrend module is used as an exit mechanism. Positions remain open while the SuperTrend trend direction is unchanged. An exit signal is generated only when the SuperTrend flips direction, helping traders stay in trends longer and avoid premature exits.

免責事項

これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。