Green/Red Candle Probability (EMA 7, SMA 20, SMA 200)

This script is designed to calculate the **probability of bullish (green) and bearish (red) candles** over a given analysis period. It leverages three key moving averages to identify market trends and display these probabilities directly on the chart, making it easier for traders to make informed decisions.
#### **How the Script Works:**
1. **Trend Detection Using Moving Averages:**
- The script calculates three moving averages:
- **EMA (Exponential Moving Average) over 7 periods**
- **SMA (Simple Moving Average) over 20 periods**
- **SMA over 200 periods**
The trend is classified as:
- **Bullish:** When EMA 7 > SMA 20 > SMA 200
- **Bearish:** When EMA 7 < SMA 20 < SMA 200
2. **Candle Analysis:**
The script analyzes the last "n" candles (based on the user-defined lookback period) to count the number of bullish and bearish candles:
- **Bullish (green) candle:** The closing price is higher than the opening price.
- **Bearish (red) candle:** The closing price is lower than the opening price.
3. **Probability Calculation:**
The probabilities are calculated as a percentage of bullish and bearish candles in the lookback period:
- **Green Probability (%) = (Number of Green Candles / Lookback Period) × 100**
- **Red Probability (%) = (Number of Red Candles / Lookback Period) × 100**
4. **Displaying Results in a Table:**
The results are displayed in a table on the chart, including:
- **Green Probability (%)**
- **Red Probability (%)**
- **Current Trend (Bullish, Bearish, or Neutral)**
#### **Strategy Overview:**
This indicator provides traders with a quick overview of the candle probabilities and the current market trend based on moving averages. It helps traders:
- Gauge the likelihood of bullish or bearish candles appearing in the near future.
- Identify the prevailing trend (bullish, bearish, or neutral).
- Adjust their trading strategies based on statistical probabilities rather than assumptions.
### **Important Notes:**
- The lookback period can be customized between **10 and 200 periods**.
- The indicator does not provide buy/sell signals but gives insights into market behavior.
By understanding the candle probabilities and the trend, traders can better assess market conditions and improve their decision-making process.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.