PROTECTED SOURCE SCRIPT
Magic Color-Changing EMA (Stateful) + Buy/Sell

This indicator is a state-based, adjustable EMA crossover engine designed to expose real momentum shifts at the earliest statistically valid moment. It uses a user-defined Fast EMA and Slow EMA (default 8 & 21) and tracks how their directional behavior changes over time. Instead of reacting to candle color or price position alone, it measures directional acceleration and structural regime change, allowing traders to clearly see when the market transitions from bearish momentum to bullish momentum and vice versa.
The core of the system operates as a three-state market engine. When bullish acceleration is confirmed, the EMA turns green. When bearish acceleration is confirmed, it turns red. When neither condition is clearly valid, the EMA enters a neutral (black) state. A built-in two-bar debounce filter prevents one-bar fakeouts and random noise from triggering false transitions, ensuring that color changes only occur when momentum is actually stabilizing in a new direction.
Buy and Sell signals are generated using a non-repainting state transition model. A Buy signal is only issued when the market transitions from a confirmed bearish state into a confirmed bullish state. A Sell signal is only issued when the market transitions from a confirmed bullish state into a confirmed bearish state. This prevents repetitive signals in the same direction and ensures that each tag marks a true regime change, not simple continuation noise.
Each Buy and Sell label is intentionally offset back one candle, placing it directly on the bar where the transition actually became structurally valid, not the reaction bar afterward. A matching vertical confirmation line is drawn through that candle to visually anchor the exact moment when momentum flipped. This makes trade review, execution timing, and historical analysis extremely precise.
Because the Fast EMA and Slow EMA lengths are fully user-adjustable, this indicator can function as a scalping engine, intraday trend detector, or higher-timeframe swing system simply by changing the EMA lengths. Shorter values increase responsiveness and frequency, while larger values increase trend filtering and reduce noise. This adaptability allows the same tool to be used across crypto, futures, forex, metals, and equities without redesigning the strategy.
This indicator does not attempt to predict price. It is a state confirmation and momentum transition detector. It performs best during volatility expansion, trending sessions, and institutional liquidity windows. Like all momentum systems, it should be used with caution during low-volatility ranges, overnight compression, and pre-news conditions.
The core of the system operates as a three-state market engine. When bullish acceleration is confirmed, the EMA turns green. When bearish acceleration is confirmed, it turns red. When neither condition is clearly valid, the EMA enters a neutral (black) state. A built-in two-bar debounce filter prevents one-bar fakeouts and random noise from triggering false transitions, ensuring that color changes only occur when momentum is actually stabilizing in a new direction.
Buy and Sell signals are generated using a non-repainting state transition model. A Buy signal is only issued when the market transitions from a confirmed bearish state into a confirmed bullish state. A Sell signal is only issued when the market transitions from a confirmed bullish state into a confirmed bearish state. This prevents repetitive signals in the same direction and ensures that each tag marks a true regime change, not simple continuation noise.
Each Buy and Sell label is intentionally offset back one candle, placing it directly on the bar where the transition actually became structurally valid, not the reaction bar afterward. A matching vertical confirmation line is drawn through that candle to visually anchor the exact moment when momentum flipped. This makes trade review, execution timing, and historical analysis extremely precise.
Because the Fast EMA and Slow EMA lengths are fully user-adjustable, this indicator can function as a scalping engine, intraday trend detector, or higher-timeframe swing system simply by changing the EMA lengths. Shorter values increase responsiveness and frequency, while larger values increase trend filtering and reduce noise. This adaptability allows the same tool to be used across crypto, futures, forex, metals, and equities without redesigning the strategy.
This indicator does not attempt to predict price. It is a state confirmation and momentum transition detector. It performs best during volatility expansion, trending sessions, and institutional liquidity windows. Like all momentum systems, it should be used with caution during low-volatility ranges, overnight compression, and pre-news conditions.
Protected script
This script is published as closed-source. However, you can use it freely and without any limitations – learn more here.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Protected script
This script is published as closed-source. However, you can use it freely and without any limitations – learn more here.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.