OPEN-SOURCE SCRIPT
MA Strategy: Dual Entry Filter

Configurable MA Dual-Filter Strategy
This strategy is an enhanced and highly configurable Moving Average (MA) Crossover system designed to mitigate false signals and align trades with the prevailing market trend. It is built to offer traders granular control over entry criteria, elevating it beyond basic, built-in MA crossover indicators.
Originality & Key Features
The script's originality and utility lie in the combination of its two primary, optional filtering mechanics:
Dual Entry Mode (Key Filter): Users can choose between two distinct methods for trade entry:
Crossover (Classic): Immediate entry when the price crosses the main MA.
Full Candle Confirmation (Unique Feature): This mode requires the entire candle body (open, high, low, and close) to be completely above or below the main MA after a crossover event to confirm the signal before entry. This strict confirmation helps to filter out weak crossovers, reducing whipsaws in choppy markets.
Optional Trend Filter: A second, slower MA (Trend Filter MA) can be activated. Trades are only permitted when the faster main MA is aligned with the slower Trend MA (i.e., long only if main MA > Trend MA), ensuring trades are executed with the established higher-timeframe direction.
How to Use the Strategy
The strategy logic is built on simple MA principles but utilizes Pine Script's switch function to allow users to select from six different MA types for both the main signal and the trend filter: SMA, EMA, WMA, HMA, VWMA, and RMA.
Core Logic:
Signal: A cross of the price over the Main MA (filtered by the chosen Entry Mode).
Directional Filter: The Trend Filter must confirm the direction (if enabled).
Exit: Trades are exited on the opposite price crossover of the Main MA.
Customizable Settings Include:
Main MA Type & Length (Default: 40 EMA): The primary signal generator.
Trend Filter MA Type & Length (Default: 70 EMA): The optional, slower trend bias.
Entry Mode: Switch between Crossover or Full Candle Confirmation.
Strategy Results and High-Risk Disclaimer
The default setting for trade size is set to 40% of equity for backtesting demonstration purposes only. This high value is used to generate a large and diverse sample size of trades for historical review on the chart.
This 40% value is NOT a recommended setting for live trading. Per TradingView guidelines, traders are strongly advised to change this input to a sustainable risk level, typically 5% to 10% of equity per trade. Past performance is not a guarantee of future results.
This strategy is an enhanced and highly configurable Moving Average (MA) Crossover system designed to mitigate false signals and align trades with the prevailing market trend. It is built to offer traders granular control over entry criteria, elevating it beyond basic, built-in MA crossover indicators.
Originality & Key Features
The script's originality and utility lie in the combination of its two primary, optional filtering mechanics:
Dual Entry Mode (Key Filter): Users can choose between two distinct methods for trade entry:
Crossover (Classic): Immediate entry when the price crosses the main MA.
Full Candle Confirmation (Unique Feature): This mode requires the entire candle body (open, high, low, and close) to be completely above or below the main MA after a crossover event to confirm the signal before entry. This strict confirmation helps to filter out weak crossovers, reducing whipsaws in choppy markets.
Optional Trend Filter: A second, slower MA (Trend Filter MA) can be activated. Trades are only permitted when the faster main MA is aligned with the slower Trend MA (i.e., long only if main MA > Trend MA), ensuring trades are executed with the established higher-timeframe direction.
How to Use the Strategy
The strategy logic is built on simple MA principles but utilizes Pine Script's switch function to allow users to select from six different MA types for both the main signal and the trend filter: SMA, EMA, WMA, HMA, VWMA, and RMA.
Core Logic:
Signal: A cross of the price over the Main MA (filtered by the chosen Entry Mode).
Directional Filter: The Trend Filter must confirm the direction (if enabled).
Exit: Trades are exited on the opposite price crossover of the Main MA.
Customizable Settings Include:
Main MA Type & Length (Default: 40 EMA): The primary signal generator.
Trend Filter MA Type & Length (Default: 70 EMA): The optional, slower trend bias.
Entry Mode: Switch between Crossover or Full Candle Confirmation.
Strategy Results and High-Risk Disclaimer
The default setting for trade size is set to 40% of equity for backtesting demonstration purposes only. This high value is used to generate a large and diverse sample size of trades for historical review on the chart.
This 40% value is NOT a recommended setting for live trading. Per TradingView guidelines, traders are strongly advised to change this input to a sustainable risk level, typically 5% to 10% of equity per trade. Past performance is not a guarantee of future results.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
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.