OPEN-SOURCE SCRIPT

SMA Buy/Sell Strategy with Significant Slope and Dynamic TP/SL

Description:
This strategy uses a simple moving average (SMA) to detect trading opportunities based on the slope and proximity of price action. It ensures trades are only executed during significant trends, reducing false signals caused by sideways movements. The strategy incorporates dynamic risk management with an initial ambitious Take Profit (TP) and a Trailing Stop Loss (SL) to protect profits.

Key Features:
Trend Detection with SMA:

Two SMAs are calculated: one on High values and one on Low values.
Signals are generated when the price crosses these SMAs, ensuring:
Buy: Price closes above the SMA on High, with a significant upward slope.
Sell: Price closes below the SMA on Low, with a significant downward slope.
Slope Significance Check:

The slope of the SMA is calculated over a configurable period.
Only trends with a slope variation exceeding a user-defined percentage threshold are considered significant.
Dynamic Risk Management:

Ambitious Initial TP: Positions target a high percentage gain upon entry.
Trailing SL: Automatically adjusts as the price moves in favor of the trade, locking in profits.
Automatic Position Management:

Opposing signals close existing positions to avoid conflicting trades.
Configurable position size for risk control.

Parameters:
SMA Period: Number of candles for calculating the SMA.
Initial Take Profit (%): Percentage gain for the initial TP.
Trailing Stop Loss (%): Percentage for trailing SL based on the current price.
Slope Threshold (%): Minimum percentage change in SMA slope to confirm trend significance.

How It Works:
Buy Signal:
The price closes above the SMA on High values.
The slope of the SMA (on High) is positive and exceeds the slope threshold.
Sell Signal:
The price closes below the SMA on Low values.
The slope of the SMA (on Low) is negative and exceeds the slope threshold.
Exits:
A position closes at the Take Profit level, Trailing Stop Loss, or when an opposing signal is generated.

Use Case:
This strategy is ideal for trending markets where price action respects moving averages. It can be used on any timeframe or asset but is particularly effective in markets with clear directional movements.

Recommended Settings:
Timeframe: Works well on higher timeframes (e.g., 1H, 4H, Daily).
Slope Threshold (%): Default is 5%, adjust based on market volatility.
Initial TP and Trailing SL: Tailor to your risk/reward preferences.
By utilizing this strategy, traders can capitalize on significant market trends while dynamically managing risk. Test it on historical data to optimize the parameters for your preferred market!
Moving Averages

開源腳本

在真正的TradingView精神中,這個腳本的作者以開源的方式發佈,這樣交易員可以理解和驗證它。請向作者致敬!您可以免費使用它,但在出版物中再次使用這段程式碼將受到網站規則的約束。 您可以收藏它以在圖表上使用。

想在圖表上使用此腳本?

免責聲明