OPEN-SOURCE SCRIPT
MAVW Trend Angle Strategy

This strategy is developed using the Mavilim indicator. It was chosen specifically because its smooth nature makes it ideal for trend angle analysis. However, this angle logic can also be applied to raw price action or other moving averages.
Overview This script is a Long-Only strategy designed specifically for spot markets (Stocks, Crypto) where short selling is not desired. It utilizes a highly smoothed custom moving average (MAVW - Weighted Moving Average of WMAs) and calculates the geometric angle (slope) of the trend to identify strong momentum and filter out market noise.
Unlike traditional Moving Average crossovers which often lag, this strategy focuses on the steepness of the trend. It aims to enter positions when the trend accelerates upward and exit when the momentum fades or turns downward.
How It Works
MAVW Calculation: The script calculates a complex chain of Weighted Moving Averages (WMAs) to create the "MAVW". This results in a curve that is extremely smooth and resistant to fake-outs compared to a standard SMA or EMA.
Trend Angle (The Core Logic): Instead of looking at raw price action, the script calculates the angle (in degrees) of the MAVW line over a specific lookback period.
Buy Signal: Triggered when the MAVW angle exceeds the Buy Threshold (e.g., > 0.2°). This indicates a strong upward impulse.
Sell (Exit) Signal: Triggered when the MAVW angle drops below the Sell Threshold (e.g., < -0.2°). This indicates a strong downward impulse.
Weak Trend / Flat Market Filter: A unique feature of this strategy is the "Close on Weak Trend" option. If enabled, the strategy will exit the position and go to CASH (Flat) if the trend angle falls between the Buy and Sell thresholds (e.g., between -0.2° and 0.2°). This protects capital during choppy, sideways markets.
Key Features
Long Only: No short selling. Ideal for spot trading and investors.
Angle Filtering: filters out insignificant price movements by measuring the trend's slope.
Sideways Market Protection: Optional setting to exit positions when the market loses direction (Trend Strength becomes "Weak").
Visuals: The MAVW line changes color based on your position status (Green = In Position, Gray = Cash).
Info Panel: Displays the current trend angle and position status in real-time on the chart.
Backtest Range: Includes a date filter to test specific time periods.
Settings & Configuration
MAVW Lengths: Adjust the First and Second lengths to change the sensitivity of the base curve.
Buy Angle Threshold: Minimum angle required to enter a Long position (Default: 0.2). Increase this value to wait for stronger trends.
Sell Angle Threshold: Angle required to hard-exit a position (Default: -0.2).
Close on Weak Trend: If checked (True), the strategy exits to cash when the angle is near zero (sideways market). If unchecked, it holds until a negative trend angle occurs.
Disclaimer This strategy is for educational purposes only. Past performance does not guarantee future results. Always perform your own backtesting before live trading.
Overview This script is a Long-Only strategy designed specifically for spot markets (Stocks, Crypto) where short selling is not desired. It utilizes a highly smoothed custom moving average (MAVW - Weighted Moving Average of WMAs) and calculates the geometric angle (slope) of the trend to identify strong momentum and filter out market noise.
Unlike traditional Moving Average crossovers which often lag, this strategy focuses on the steepness of the trend. It aims to enter positions when the trend accelerates upward and exit when the momentum fades or turns downward.
How It Works
MAVW Calculation: The script calculates a complex chain of Weighted Moving Averages (WMAs) to create the "MAVW". This results in a curve that is extremely smooth and resistant to fake-outs compared to a standard SMA or EMA.
Trend Angle (The Core Logic): Instead of looking at raw price action, the script calculates the angle (in degrees) of the MAVW line over a specific lookback period.
Buy Signal: Triggered when the MAVW angle exceeds the Buy Threshold (e.g., > 0.2°). This indicates a strong upward impulse.
Sell (Exit) Signal: Triggered when the MAVW angle drops below the Sell Threshold (e.g., < -0.2°). This indicates a strong downward impulse.
Weak Trend / Flat Market Filter: A unique feature of this strategy is the "Close on Weak Trend" option. If enabled, the strategy will exit the position and go to CASH (Flat) if the trend angle falls between the Buy and Sell thresholds (e.g., between -0.2° and 0.2°). This protects capital during choppy, sideways markets.
Key Features
Long Only: No short selling. Ideal for spot trading and investors.
Angle Filtering: filters out insignificant price movements by measuring the trend's slope.
Sideways Market Protection: Optional setting to exit positions when the market loses direction (Trend Strength becomes "Weak").
Visuals: The MAVW line changes color based on your position status (Green = In Position, Gray = Cash).
Info Panel: Displays the current trend angle and position status in real-time on the chart.
Backtest Range: Includes a date filter to test specific time periods.
Settings & Configuration
MAVW Lengths: Adjust the First and Second lengths to change the sensitivity of the base curve.
Buy Angle Threshold: Minimum angle required to enter a Long position (Default: 0.2). Increase this value to wait for stronger trends.
Sell Angle Threshold: Angle required to hard-exit a position (Default: -0.2).
Close on Weak Trend: If checked (True), the strategy exits to cash when the angle is near zero (sideways market). If unchecked, it holds until a negative trend angle occurs.
Disclaimer This strategy is for educational purposes only. Past performance does not guarantee future results. Always perform your own backtesting before live trading.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.