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.
قام مؤلف هذا النص البرمجي بنشره وجعله مفتوح المصدر، بحيث يمكن للمتداولين فهمه والتحقق منه، وهو الأمر الذي يدخل ضمن قيم TradingView. تحياتنا للمؤلف! يمكنك استخدامه مجانًا، ولكن إعادة استخدام هذا الرمز في المنشور يخضع لقواعدقوانين الموقع. يمكنك جعله مفضلاً لاستخدامه على الرسم البياني.
هل تريد استخدام هذا النص البرمجي على الرسم البياني؟
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.