Certainly! Here's a TradingView Pine Script indicator that highlights candles that do not touch the 5-period Exponential Moving Average (EMA 5). This script will color the bars yellow when the candle's range does not intersect with the EMA 5 line.
//@version=5
indicator("Candles Not Touching EMA 5", overlay=true)
// Calculate EMA 5
ema5 = ta.ema(close, 5)
// Identify candles that do not touch EMA 5
// A candle does not touch EMA 5 if:
// - The entire candle is above the EMA (low > ema5), or
// - The entire candle is below the EMA (high < ema5)
not_touching = (low > ema5) or (high < ema5)
// Highlight candles that do not touch EMA 5
barcolor(not_touching ? color.yellow : na)
// (Optional) Plot EMA 5 for reference
plot(ema5, color=color.orange, linewidth=2, title="EMA 5")
How to Use This Indicator:
-
Open TradingView: Go to TradingView and open a chart of your choice.
-
Access the Pine Script Editor:
- Click on "Pine Editor" at the bottom of the TradingView chart.
-
Create a New Script:
- Delete any pre-existing code in the editor.
- Paste the entire script provided above into the editor.
-
Save and Add to Chart:
- Click on "Save" (you may need to name your script).
- Click on "Add to Chart" to apply the indicator to your current chart.
Explanation of the Script:
-
Indicator Declaration:
//@version=5
indicator("Candles Not Touching EMA 5", overlay=true)
- Sets the Pine Script version to 5.
- Names the indicator "Candles Not Touching EMA 5".
overlay=true ensures the indicator appears on the price chart, not in a separate pane.
-
Calculating EMA 5:
ema5 = ta.ema(close, 5)
- Computes the 5-period Exponential Moving Average of the closing prices.
-
Identifying Candles Not Touching EMA 5:
not_touching = (low > ema5) or (high < ema5)
- A candle does not touch the EMA 5 if:
- The entire candle is above the EMA (
low > ema5), or
- The entire candle is below the EMA (
high < ema5).
- If either condition is true,
not_touching is true for that candle.
-
Highlighting the Candles:
barcolor(not_touching ? color.yellow : na)
- Uses the
barcolor function to change the color of the candles.
- If
not_touching is true, the candle is colored yellow.
- If
not_touching is false, no color change is applied (na).
-
(Optional) Plotting EMA 5:
plot(ema5, color=color.orange, linewidth=2, title="EMA 5")
- Plots the EMA 5 line on the chart in orange for visual reference.
- You can remove or comment out this line if you prefer not to display the EMA line.
Visual Interpretation:
-
Yellow Candles: Indicate that the candle did not touch the EMA 5 at all during its formation.
- The price stayed entirely above or below the EMA 5 throughout the period.
-
Regular Candles: Candles that do touch the EMA 5 at some point during their formation are not colored and appear with their default colors.
Customization Tips:
Note:
- Ensure you're using the correct version of Pine Script (version 5) as specified at the top of the script.
- This indicator can help identify trends where the price is consistently moving away from the EMA, which might be indicative of strong momentum.
Feel free to ask if you need further customization or have any questions!