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

Script de código aberto

No verdadeiro espírito do TradingView, o autor desse script o publicou como código aberto, para que os traders possam compreendê-lo e analisá-lo. Parabéns ao autor! Você pode usá-lo gratuitamente, mas a reutilização desse código em publicações é regida pelas Regras da Casa. Você pode favoritá-lo para usá-lo em um gráfico.

Quer usar esse script no gráfico?

Aviso legal