Refined Trend and Consolidation with MACD, RSI, OBV, and Volume
We are implementing a trend analysis system using multiple technical indicators to determine the market state. We calculate two Simple Moving Averages (SMA 9 and SMA 21), the Relative Strength Index (RSI), the On-Balance Volume (OBV), and the MACD. Based on these indicators, we classify the market into three states: uptrend, downtrend, or consolidation. The script then changes the background color of the chart to visually represent the current market state: green for uptrend, red for downtrend, and yellow for consolidation. The transparency of the background is adjusted for a clear view of the price action.
The uptrend is identified when the short-term SMA (SMA 9) is above the long-term SMA (SMA 21), RSI is above 55 (indicating strong bullish momentum), OBV is rising, MACD line is above the signal line and zero, and volume is higher than the average.
The downtrend is recognized when the short-term SMA is below the long-term SMA, RSI is below 45 (indicating bearish momentum), OBV is falling, MACD line is below the signal line and zero, and volume exceeds the average.
Consolidation occurs when none of the uptrend or downtrend conditions are met, indicating range-bound movement. This is signified by the SMAs being close to each other, RSI near 50, OBV flat, MACD oscillating around zero, and volume either below average or neutral.
This provides a clear, visual representation of the market's current state by dynamically changing the chart's background color. The uptrend is shown with a green background, indicating a strong bullish market, while the downtrend is represented with a red background, signaling a bearish market. A yellow background marks consolidation, suggesting a period of sideways or range-bound movement with no clear direction. By using a combination of SMAs, RSI, OBV, MACD, and volume, the script helps traders quickly identify the prevailing market conditions, allowing them to make more informed decisions based on current trends and potential consolidations.
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.