1. Purpose of the Script The script combines the MACD (Moving Average Convergence Divergence) and ADX (Average Directional Index) to generate buy and sell signals:
MACD helps identify momentum changes in price. ADX ensures signals are only generated when the trend is strong enough. It visually plots these signals as green "Buy" markers below the candles and red "Sell" markers above the candles. It also highlights the background when the trend is strong.
2. Inputs The script uses user-defined parameters to customize the behavior of MACD and ADX:
Short EMA & Long EMA (12, 26): The two EMAs used to calculate the MACD line. Signal Length (9): The smoothing length for the MACD signal line. ADX Period (14): The period used to calculate the ADX. ADX Smoothing (14): Smooths the ADX calculation. ADX Threshold (20): Defines the minimum ADX value for a "strong trend." Signals are only valid if the ADX is above this threshold. 3. Calculations MACD (Momentum Detection) macdLine: The difference between the short EMA and long EMA. It shows the momentum of price movement. signalLine: A smoothed version of the MACD line, acting as a signal filter. histogram: The difference between macdLine and signalLine, showing the strength of momentum. ADX (Trend Strength Detection) The ADX indicator measures the strength of a trend: diPlus and diMinus: Show bullish and bearish directional movement. adxValue: The ADX value determines whether the trend is strong enough to trade. 4. Signal Logic The script generates buy and sell signals based on MACD and ADX:
Buy Signal: Occurs when the MACD line crosses above the signal line (bullish crossover) and the ADX value is greater than the threshold (indicating a strong trend). Sell Signal: Occurs when the MACD line crosses below the signal line (bearish crossover) and the ADX value is greater than the threshold. 5. Visual Elements Buy/Sell Signal Markers Buy Signal: Plotted as a green upward arrow (labelup) below the price bars. Sell Signal: Plotted as a red downward arrow (labeldown) above the price bars. Background Highlight When the ADX value exceeds the threshold (indicating a strong trend), the background is highlighted in blue. 6. Practical Use This script is designed for traders looking to:
Identify optimal buy and sell opportunities during strong trends. Filter out weak trends or sideways markets to avoid false signals. Combine momentum (MACD) and trend strength (ADX) into a single strategy.
In pieno spirito TradingView, l'autore di questo script lo ha pubblicato open-source, in modo che i trader possano comprenderlo e verificarlo. Un saluto all'autore! È possibile utilizzarlo gratuitamente, ma il riutilizzo di questo codice in una pubblicazione è regolato dal nostro Regolamento. Per aggiungerlo al grafico, mettilo tra i preferiti.
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.