sabyasachi27

SMA corssover strategy

NIFTY
The script is called "SMA Crossover Strategy" and is an indicator that uses two Simple Moving Averages (SMA) with different lengths to generate buy and sell signals. The script has two user inputs, "Short MA Length" and "Long MA Length" that allow the user to set the lengths of the two moving averages. The short moving average is plotted in green, while the long moving average is plotted in red.

The script uses the sma() function to calculate the short and long moving averages, and the plot() function to display them on the chart. The if-else statements generate the buy and sell signals based on the crossover of the two moving averages. If the short moving average crosses above the long moving average, a long position is entered, and if the short moving average crosses below the long moving average, a short position is entered.

It is worth noting that this is a basic example, and you should always do your own research and testing before making any trades.

EXPLANATION :-

The Simple Moving Average (SMA) Crossover strategy is a technical analysis strategy that uses moving averages to identify potential buy or sell opportunities in the market. Here is a step-by-step explanation of how the strategy works:

Step 1: Identify the stock or asset you want to trade. The strategy can be applied to any stock or asset that is traded on a public exchange.

Step 2: Select the time frame for the analysis. The length of the time frame will depend on the research question and the objectives of the analysis, it could be short term or long term.

Step 3: Choose the moving average lengths. The strategy typically uses a short-term moving average and a long-term moving average. The length of the moving averages will depend on the research question and the objectives of the analysis. Commonly used lengths are 50 and 200 days moving averages.

Step 4: Plot the moving averages on the chart of the stock or asset. The short-term moving average will be plotted on top of the long-term moving average.

Step 5: Identify the crossover points. When the short-term moving average crosses above the long-term moving average, it is a bullish signal, indicating that the stock or asset is likely to rise in value. Conversely, when the short-term moving average crosses below the long-term moving average, it is a bearish signal, indicating that the stock or asset is likely to decrease in value.

Step 6: Take action based on the crossover points. If the short-term moving average crosses above the long-term moving average, it is a signal to buy. If the short-term moving average crosses below the long-term moving average, it is a signal to sell.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?