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.
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.
As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.