OPEN-SOURCE SCRIPT
Dual SMA Crossover Strategy

Dual SMA Crossover Strategy with Advanced Risk Management
This Pine Script strategy utilizes a Dual Simple Moving Average (SMA) Crossover system for identifying trend changes, enhanced with comprehensive money and risk management features.
Strategy Logic
The core of the strategy is based on the interaction of two SMAs: a Fast SMA (default 24 periods) and a Slow SMA (default 48 periods).
Long Entry: Triggered when the Fast SMA crosses above the Slow SMA.
Short Entry: Triggered when the Fast SMA crosses below the Slow SMA.
Exit: Positions are closed when an opposite crossover signal occurs.
All trading decisions are made on the close of the candle to prevent any look-ahead bias, ensuring realistic backtest results.
Key Risk Management Features
Money Management:
Risk Per Trade (%): Defines the maximum percentage of account equity to risk on any single trade (default 2.0%). Position sizing is automatically calculated to ensure this risk limit is not exceeded when the Stop Loss is hit.
Stop Loss (SL):
A fixed Stop Loss (%) (default 0.8%) from the entry price is set immediately upon trade entry to limit potential losses.
Take Profit (TP):
A Risk-Reward Ratio (default 2.0) is used to calculate the Take Profit target. For instance, a 2.0 RRR with a 0.8% SL means a 1.6% TP target.
Advanced Trailing Stop Loss (TSL):
Trailing Stop Start (%): The TSL only activates once the trade reaches a predefined profit percentage (default 1.0%).
Trailing Stop Trail (%): Once activated, the TSL moves to lock in profits by trailing the highest (for long) or lowest (for short) price by a specified percentage (default 0.5%). This ensures that the TSL level never falls below the initial Stop Loss, providing continuous risk protection while allowing for further profit accumulation.
This strategy provides a robust framework for trend-following with built-in risk controls, aiming to protect capital and manage potential gains effectively.
This Pine Script strategy utilizes a Dual Simple Moving Average (SMA) Crossover system for identifying trend changes, enhanced with comprehensive money and risk management features.
Strategy Logic
The core of the strategy is based on the interaction of two SMAs: a Fast SMA (default 24 periods) and a Slow SMA (default 48 periods).
Long Entry: Triggered when the Fast SMA crosses above the Slow SMA.
Short Entry: Triggered when the Fast SMA crosses below the Slow SMA.
Exit: Positions are closed when an opposite crossover signal occurs.
All trading decisions are made on the close of the candle to prevent any look-ahead bias, ensuring realistic backtest results.
Key Risk Management Features
Money Management:
Risk Per Trade (%): Defines the maximum percentage of account equity to risk on any single trade (default 2.0%). Position sizing is automatically calculated to ensure this risk limit is not exceeded when the Stop Loss is hit.
Stop Loss (SL):
A fixed Stop Loss (%) (default 0.8%) from the entry price is set immediately upon trade entry to limit potential losses.
Take Profit (TP):
A Risk-Reward Ratio (default 2.0) is used to calculate the Take Profit target. For instance, a 2.0 RRR with a 0.8% SL means a 1.6% TP target.
Advanced Trailing Stop Loss (TSL):
Trailing Stop Start (%): The TSL only activates once the trade reaches a predefined profit percentage (default 1.0%).
Trailing Stop Trail (%): Once activated, the TSL moves to lock in profits by trailing the highest (for long) or lowest (for short) price by a specified percentage (default 0.5%). This ensures that the TSL level never falls below the initial Stop Loss, providing continuous risk protection while allowing for further profit accumulation.
This strategy provides a robust framework for trend-following with built-in risk controls, aiming to protect capital and manage potential gains effectively.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.