This Pine Script™ is designed for use in Trading View and generates trading signals based on moving average (MA) crossovers, RSI (Relative Strength Index) signals, and MACD (Moving Average Convergence Divergence) indicators. It provides visual markers on the chart and can be configured to suit various trading strategies.
1. Indicator Overview The indicator includes signals for:
Moving Averages (MA): It tracks crossovers between different types of moving averages.
RSI: Signals based on RSI crossing certain levels or its signal line.
MACD: Buy and sell signals generated by MACD crossovers.
2. Inputs and Customization
Moving Averages (MAs):
You can customize up to 6 moving averages with different types, lengths, and colors.
MA Type: Choose from different types of moving averages:
SMA (Simple Moving Average)
EMA (Exponential Moving Average)
HMA (Hull Moving Average)
SMMA (RMA) (Smoothed Moving Average)
WMA (Weighted Moving Average)
VWMA (Volume Weighted Moving Average)
T3, DEMA, TEMA
Source: Select the price to base the MA on (e.g., close, open, high, low).
Length: Define the number of periods for each moving average. Examples:
MA1: Exponential Moving Average (EMA) with a period of 9
MA2: Exponential Moving Average (EMA) with a period of 21
RSI Settings: RSI is calculated based on a user-defined period and is used to identify potential overbought or oversold conditions.
RSI Length: Lookback period for RSI (default 14).
Overbought Level: Defines the overbought threshold for RSI (default 70).
Oversold Level: Defines the oversold threshold for RSI (default 30). You can also adjust the smoothing for the RSI signal line and customize when to trigger buy and sell signals based on the RSI crossing these levels.
MACD Settings: MACD is used for identifying changes in momentum and trends.
Fast Length: The period for the fast moving average (default 12).
Slow Length: The period for the slow moving average (default 26).
Signal Length: The period for the signal line (default 9).
Smoothing Method: Choose between SMA or EMA for both the MACD and the signal line.
3. Signal Logic Moving Average (MA) Crossover Signals:
Crossover: A bullish signal is generated when a fast MA crosses above a slow MA.
Crossunder: A bearish signal is generated when a fast MA crosses below a slow MA.
The crossovers are plotted with distinct colors, and the chart will display markers for these crossover events.
RSI Signals:
Oversold Crossover: A bullish signal when RSI crosses over its signal line below the oversold level (30).
Overbought Crossunder: A bearish signal when RSI crosses under its signal line above the overbought level (70). RSI signals are divided into:
Aggressive (Early) Entries: Signals when RSI is crossing the oversold/overbought levels.
Conservative Entries: Signals when RSI confirms a reversal after crossing these levels.
MACD Signals:
Buy Signal: Generated when the MACD line crosses above the signal line (bullish crossover).
Sell Signal: Generated when the MACD line crosses below the signal line (bearish crossunder).
Additionally, the MACD histogram is used to identify momentum shifts:
Rising to Falling Histogram: Alerts when the MACD histogram switches from rising to falling.
Falling to Rising Histogram: Alerts when the MACD histogram switches from falling to rising.
4. Visuals and Alerts Plotting: The script plots the following on the price chart:
Moving Averages (MA): The selected MAs are plotted as lines.
Buy/Sell Shapes: Triangular markers are displayed for buy and sell signals generated by RSI and MACD.
Crossover and Crossunder Markers: Crosses are shown when two MAs crossover or crossunder.
Alerts: Alerts can be configured based on the following conditions:
RSI Signals: Alerts for oversold or overbought crossover and crossunder events.
MACD Signals: Alerts for MACD line crossovers or momentum shifts in the MACD histogram.
Alerts are triggered when specific conditions are met, such as:
RSI crosses over or under the oversold/overbought levels.
MACD crosses the signal line.
Changes in the MACD histogram.
5. Example Usage
1. Trend Reversal Setup:
Buy Signal: Use the RSI oversold crossover and MACD bullish crossover to identify potential entry points in a downtrend.
Sell Signal: Use the RSI overbought crossunder and MACD bearish crossunder to identify potential exit points or short entries in an uptrend.
2. Momentum Strategy:
Combine MACD and RSI signals to identify the strength of a trend. Use MACD histogram analysis and RSI levels for confirmation. 3. Moving Average Crossover Strategy:
Focus on specific MA crossovers, such as the 9-period EMA crossing above the 21-period EMA, for buy signals. When a longer-term MA (e.g., 50-period) crosses a shorter-term MA, it may indicate a strong trend change.
6. Alerts Conditions The script includes several alert conditions, which can be triggered and customized based on the user’s preferences:
RSI Oversold Crossover: Alerts when RSI crosses over the signal line below the oversold level (30).
RSI Overbought Crossunder: Alerts when RSI crosses under the signal line above the overbought level (70).
MACD Buy/Sell Crossover: Alerts when the MACD line crosses the signal line for a buy or sell signal.
7. Conclusion This script is highly customizable and can be adjusted to suit different trading strategies. By combining MAs, RSI, and MACD, traders can gain multiple perspectives on the market, enhancing their ability to identify potential buy and sell opportunities.