OPEN-SOURCE SCRIPT
MACD crossover while RSI Oversold/Overbought

# MACD Crossover with RSI Overbought/Oversold Indicator Explained
## Indicator Overview
This is a trading signal system that combines two classic technical indicators: **MACD (Moving Average Convergence Divergence)** and **RSI (Relative Strength Index)**. Its core logic is: MACD crossover signals are only triggered when RSI is in extreme zones (overbought/oversold), thereby filtering out many false signals and improving trading accuracy.
## Core Principles
### 1. **Dual Confirmation Mechanism**
This indicator doesn't use MACD or RSI alone, but requires both conditions to be met simultaneously:
- **Short Signal (Orange Triangle)**: MACD bearish crossover (fast line crosses below signal line) + RSI was overbought (≥71)
- **Long Signal (Green Triangle)**: MACD bullish crossover (fast line crosses above signal line) + RSI was oversold (≤29)
### 2. **RSI Memory Function**
The indicator checks the RSI values of the current and past 5 candlesticks. As long as any one of them reaches the overbought/oversold level, the condition is satisfied. This design avoids overly strict requirements, as RSI may have already left the extreme zone before the MACD crossover occurs.
```pine
wasOversold = rsi <= 29 or rsi[1] <= 29 or ... or rsi[5] <= 29
wasOverbought = rsi >= 71 or rsi[1] >= 71 or ... or rsi[5] >= 71
```
## Parameter Settings
### MACD Parameters
- **Fast MA**: 12 periods (adjustable 7-∞)
- **Slow MA**: 26 periods (adjustable 7-∞)
- **Signal Line**: 9 periods
### RSI Parameters
- **Oversold Threshold**: 29 (traditional 30)
- **Overbought Threshold**: 71 (traditional 70)
- **Calculation Period**: 14
## Visual Elements
### 1. **Signal Markers**
- 🔻 **Orange Downward Triangle**: Appears above the candlestick, labeled "overbought", indicating a shorting opportunity
- 🔺 **Green Upward Triangle**: Appears below the candlestick, labeled "oversold", indicating a long opportunity
### 2. **Price Level Lines**
- **Orange Dashed Line**: Extends rightward from the high of the short signal, serving as a potential resistance level
- **Green Dashed Line**: Extends rightward from the low of the long signal, serving as a potential support level
Each time a new signal appears, the old level line is deleted, keeping only the most recent reference line.
## Trading Logic Explained
### Short Signal Scenario
1. Price rises, RSI surges above 71 (market overheated)
2. Momentum subsequently weakens, MACD fast line crosses below signal line
3. Indicator draws an orange triangle at the high, alerting to reversal risk
4. Orange dashed line marks the high point of the short entry position
### Long Signal Scenario
1. Price falls, RSI drops below 29 (market oversold)
2. Selling pressure exhausted, MACD fast line crosses above signal line
3. Indicator draws a green triangle at the low, suggesting a rebound opportunity
4. Green dashed line marks the low point of the long entry position
## Advantages and Limitations
### ✅ Advantages
- **Filters Noise**: Reduces false signals through dual confirmation
- **Captures Reversals**: Catches trend reversals in extreme conditions
- **Visual Clarity**: Level lines help identify support/resistance
- **Built-in Alerts**: Can set up message push notifications
### ⚠️ Limitations
- **Lag**: Both indicators are lagging, signals may be delayed
- **Poor Performance in Ranging Markets**: Prone to whipsaws during consolidation
- **Needs Other Analysis**: Should not be the sole decision-making basis
- **Parameter Sensitivity**: Different markets and timeframes may require parameter adjustments
## Practical Trading Suggestions
1. **Confirm Trend Context**: Counter-trend signals carry high risk in strong trending markets
2. **Combine with Candlestick Patterns**: Confirm with patterns (such as engulfing, hammer candles)
3. **Set Stop Losses**: Use level lines as stop-loss references (long stop below green line, short stop above orange line)
4. **Watch Volume**: Signals accompanied by high volume are more reliable
5. **Multi-Timeframe Verification**: Signals appearing simultaneously on daily and 4-hour charts are more credible
## Summary
This indicator follows the "mean reversion from extremes" philosophy, seeking reversal opportunities when market sentiment becomes excessive. It's suitable for auxiliary judgment, particularly in swing trading and position trading strategies. But remember, no indicator is perfect—always combine risk management and multi-dimensional analysis when making trading decisions
## Indicator Overview
This is a trading signal system that combines two classic technical indicators: **MACD (Moving Average Convergence Divergence)** and **RSI (Relative Strength Index)**. Its core logic is: MACD crossover signals are only triggered when RSI is in extreme zones (overbought/oversold), thereby filtering out many false signals and improving trading accuracy.
## Core Principles
### 1. **Dual Confirmation Mechanism**
This indicator doesn't use MACD or RSI alone, but requires both conditions to be met simultaneously:
- **Short Signal (Orange Triangle)**: MACD bearish crossover (fast line crosses below signal line) + RSI was overbought (≥71)
- **Long Signal (Green Triangle)**: MACD bullish crossover (fast line crosses above signal line) + RSI was oversold (≤29)
### 2. **RSI Memory Function**
The indicator checks the RSI values of the current and past 5 candlesticks. As long as any one of them reaches the overbought/oversold level, the condition is satisfied. This design avoids overly strict requirements, as RSI may have already left the extreme zone before the MACD crossover occurs.
```pine
wasOversold = rsi <= 29 or rsi[1] <= 29 or ... or rsi[5] <= 29
wasOverbought = rsi >= 71 or rsi[1] >= 71 or ... or rsi[5] >= 71
```
## Parameter Settings
### MACD Parameters
- **Fast MA**: 12 periods (adjustable 7-∞)
- **Slow MA**: 26 periods (adjustable 7-∞)
- **Signal Line**: 9 periods
### RSI Parameters
- **Oversold Threshold**: 29 (traditional 30)
- **Overbought Threshold**: 71 (traditional 70)
- **Calculation Period**: 14
## Visual Elements
### 1. **Signal Markers**
- 🔻 **Orange Downward Triangle**: Appears above the candlestick, labeled "overbought", indicating a shorting opportunity
- 🔺 **Green Upward Triangle**: Appears below the candlestick, labeled "oversold", indicating a long opportunity
### 2. **Price Level Lines**
- **Orange Dashed Line**: Extends rightward from the high of the short signal, serving as a potential resistance level
- **Green Dashed Line**: Extends rightward from the low of the long signal, serving as a potential support level
Each time a new signal appears, the old level line is deleted, keeping only the most recent reference line.
## Trading Logic Explained
### Short Signal Scenario
1. Price rises, RSI surges above 71 (market overheated)
2. Momentum subsequently weakens, MACD fast line crosses below signal line
3. Indicator draws an orange triangle at the high, alerting to reversal risk
4. Orange dashed line marks the high point of the short entry position
### Long Signal Scenario
1. Price falls, RSI drops below 29 (market oversold)
2. Selling pressure exhausted, MACD fast line crosses above signal line
3. Indicator draws a green triangle at the low, suggesting a rebound opportunity
4. Green dashed line marks the low point of the long entry position
## Advantages and Limitations
### ✅ Advantages
- **Filters Noise**: Reduces false signals through dual confirmation
- **Captures Reversals**: Catches trend reversals in extreme conditions
- **Visual Clarity**: Level lines help identify support/resistance
- **Built-in Alerts**: Can set up message push notifications
### ⚠️ Limitations
- **Lag**: Both indicators are lagging, signals may be delayed
- **Poor Performance in Ranging Markets**: Prone to whipsaws during consolidation
- **Needs Other Analysis**: Should not be the sole decision-making basis
- **Parameter Sensitivity**: Different markets and timeframes may require parameter adjustments
## Practical Trading Suggestions
1. **Confirm Trend Context**: Counter-trend signals carry high risk in strong trending markets
2. **Combine with Candlestick Patterns**: Confirm with patterns (such as engulfing, hammer candles)
3. **Set Stop Losses**: Use level lines as stop-loss references (long stop below green line, short stop above orange line)
4. **Watch Volume**: Signals accompanied by high volume are more reliable
5. **Multi-Timeframe Verification**: Signals appearing simultaneously on daily and 4-hour charts are more credible
## Summary
This indicator follows the "mean reversion from extremes" philosophy, seeking reversal opportunities when market sentiment becomes excessive. It's suitable for auxiliary judgment, particularly in swing trading and position trading strategies. But remember, no indicator is perfect—always combine risk management and multi-dimensional analysis when making trading decisions
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.