OPEN-SOURCE SCRIPT

Three SMAs with Dynamic EMA and MACD Filter Strategy

This Pine Script code is a trading strategy implemented in TradingView's strategy tester. It combines three simple moving averages (SMA), a dynamically adjustable period exponential moving average (EMA), and the moving average convergence divergence (MACD) to generate trading signals. Here’s a detailed breakdown of the code:

Strategy Settings:

The strategy() function defines the basic settings for the strategy, including the name, abbreviation, and whether it overlays on the price chart (overlay=true).
SMA Parameters:

len1, len2, and len3 are set to 5, 10, and 15, representing the periods of the three SMA lines.
sma1, sma2, and sma3 are calculated using the ta.sma() function, corresponding to the specified periods.
Dynamic EMA Setting:

ema_length is set using the input() function, allowing users to dynamically adjust the EMA period, with a default value of 200.
ema is the EMA calculated based on the user-defined period, using the ta.ema() function.
MACD Parameters:

fast_length, slow_length, and signal_length are set to 12, 26, and 9, which are standard parameters for calculating MACD.
fast_ma and slow_ma are the fast and slow EMAs, respectively.
macd represents the difference between the fast and slow EMAs.
signal is the signal line of the MACD, typically an EMA of the MACD line.
Plotting:

The plot() function is used to display the three SMA lines and the EMA line, each in a different color for easy differentiation.
Trade Conditions:

The buyCondition is triggered when sma1 > sma2 > sma3, the closing price is above the EMA, and the MACD line is above the signal line.
The sellCondition is triggered when sma3 > sma2 > sma1, the closing price is below the EMA, and the MACD line is below the signal line.
Executing Trades:

The strategy.entry() function is used to execute long or short trades based on the conditions.
This strategy combines trend-following elements (through the SMA and EMA) and momentum (through the MACD) to capture potential trading opportunities in given trend and momentum conditions. Its effectiveness depends on specific market conditions, so thorough backtesting and risk evaluation are essential before real-world application.
Candlestick analysisChart patternsCycles

開源腳本

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

想在圖表上使用此腳本?

免責聲明