simple pullback trend indicator help

METAL

Expert Trader
Plus
I am attempting to have a histogram that plots green bars when in uptrend. Uptrend is when price is above 20 ema and 5ema (Both ema's) If price goes below 5 ema (ema2) then Histo bar is yellow and visa versa for downtrend. At the moment I am only getting bars when price crosses the ema's and not while price is above or below and I am not getting a pullback (yellow) bar at all. Thanks in advance!

Code:
# Trend_Pullback_Indicator

input emaLength1 = 20;
input emaLength2 = 5;

def closePrice = close;
def ema1 = ExpAverage(closePrice, emaLength1);
def ema2 = ExpAverage(closePrice, emaLength2);

def isUptrend = close > ema1 and close[1] <= ema1[1];
def isDowntrend = close < ema1 and close[1] >= ema1[1];

def isPullbackUp = close > ema1 and close <= ema2;
def isPullbackDown = close < ema1 and close >= ema2;

def histogramValue = if isUptrend or isDowntrend then close - ema1 else Double.NaN;

plot histogram = histogramValue;
histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
histogram.SetLineWeight(3);
histogram.AssignValueColor(if isUptrend then Color.GREEN else if isDowntrend then Color.RED else if isPullbackUp or isPullbackDown then Color.YELLOW else Color.GRAY);
 
Solution
I am attempting to have a histogram that plots green bars when in uptrend. Uptrend is when price is above 20 ema and 5ema (Both ema's) If price goes below 5 ema (ema2) then Histo bar is yellow and visa versa for downtrend. At the moment I am only getting bars when price crosses the ema's and not while price is above or below and I am not getting a pullback (yellow) bar at all. Thanks in advance!

Code:
# Trend_Pullback_Indicator

input emaLength1 = 20;
input emaLength2 = 5;

def closePrice = close;
def ema1 = ExpAverage(closePrice, emaLength1);
def ema2 = ExpAverage(closePrice, emaLength2);

def isUptrend = close > ema1 and close[1] <= ema1[1];
def isDowntrend = close < ema1 and close[1] >= ema1[1];

def isPullbackUp = close > ema1 and...
Don’t be sorry. Supremely grateful! I have been adding custom columns recently and this is perfect. Will the scan update dynamically during the day as conditions are met? Specifically, will new stocks appear as they met conditions?

If that’s possible I’d love to be able to add a filter for volume and daily adr being above 3% as those usually move well for day trading.
The scan will not but the watchlist will and depending on the timeframe your whole watchlist is on it will up date during the day, you can also be alerted to any new stocks that have been added - not sure if it alertts you to any that drop off ...ummmm
 
The scan will not but the watchlist will and depending on the timeframe your whole watchlist is on it will up date during the day, you can also be alerted to any new stocks that have been added - not sure if it alertts you to any that drop off ...ummmm
https://tos.mx/!fxE5pHQ9
Don’t be sorry. Supremely grateful! I have been adding custom columns recently and this is perfect. Will the scan update dynamically during the day as conditions are met? Specifically, will new stocks appear as they met conditions?

If that’s possible I’d love to be able to add a filter for volume and daily adr being above 3% as those usually move well for day trading.
https://tos.mx/!fxE5pHQ9
1753655196353.png

1753655268361.png

1753655289648.png
 
Find the results very interesting..wondering if that's tell for rotational strength View attachment 25302

I also made a WL for ADR % with some coloring

Code:
# ADR% Watchlist Column, 14-Day Lookback with Color Coding
# Concept by hboogie, July 2025

input length = 14;

def hi = high(period = AggregationPeriod.DAY);
def lo = low(period = AggregationPeriod.DAY);
def c = close(period = AggregationPeriod.DAY);

def adr = Average(hi - lo, length);
def avgClose = Average(c, length);
def adrPct = if avgClose != 0 then 100 * adr / avgClose else Double.NaN;

AssignBackgroundColor(
    if adrPct > 7 then Color.DARK_GREEN
    else if adrPct > 3 then Color.VIOLET
    else CreateColor(220, 220, 220)  # Light gray
);

# AssignTextColor(Color.BLACK);

plot Data = Round(adrPct, 2);
Data.AssignValueColor(Color.BLACK);
1753655971449.png
 
Last edited by a moderator:
Well I was thinking more of adjusting one of the custom scans to which I can add as an intraday watchlist then add the columns to that WL so that dynamically updates to pickup on liquid names
Watchlist column custom this will show bullish or bearish or nan

https://tos.mx/!3sRbCo36
This is watchlist column:

1753655988789.png

Code:
# Watchlist Column: DVRSI Bullish and Bearish
# Converted from DVRSI Bullish ZeroUp Scanner

# --- Inputs ---
input rsi_length = 14;
input smoothing_length = 14;
input PriceSource = FundamentalType.HLC3;

# --- Price Source ---
def price_source_input = Fundamental(PriceSource);

# --- Dynamic Volume RSI Logic ---
script DynamicVolumeRSI {
    input source = hlc3;
    input length = 14;
    input smoothing_length = 14;
    input vol = volume;

    def fast_end = 2 / (2 + 1);
    def slow_end = 2 / (30 + 1);
    def change = AbsValue(vol - vol[smoothing_length]);
    def volatility = Sum(AbsValue(vol - vol[1]), smoothing_length);
    def efficiency_ratio = if volatility != 0 then change / volatility else 0;
    def smooth_factor = Power(efficiency_ratio * (fast_end - slow_end) + slow_end, 2);
    def rma = WildersAverage(vol, smoothing_length);
    def smoothed_volume = rma + smooth_factor * (vol - rma);
    def price_change = source - source[1];
    def up = WildersAverage(Max(price_change, 0) * smoothed_volume, length);
    def dn = WildersAverage(AbsValue(Min(price_change, 0)) * smoothed_volume, length);
    def index = if dn == 0 then 100 else if up == 0 then 0 else 100 - (100 / (1 + up / dn));
    def smooth = 2 / (length + 1);
    def ema = ExpAverage(index, length);
    def dynamicRsi = ema + smooth * (index - ema);
    plot out = dynamicRsi;
}

# --- Calculate DVRSI ---
def dvrsi = DynamicVolumeRSI(price_source_input, rsi_length, smoothing_length, volume / 10000);

# --- ZeroUp (Bullish) and ZeroDown (Bearish) Conditions ---
def zeroUp = dvrsi > 50 and dvrsi[1] <= 50;  # Bullish crossover above 50
def zeroDown = dvrsi < 50 and dvrsi[1] >= 50; # Bearish crossover below 50

# --- ADR Constraint ---
def adr = Average(high - low, 14);
def adrUsed = (high - low) / adr * 100;

# --- Watchlist Output ---
AddLabel(yes, if zeroUp and adrUsed < 90 then "Bullish"
         else if zeroDown and adrUsed < 90 then "Bearish"
         else "No",
         if zeroUp and adrUsed < 90 then Color.GREEN
         else if zeroDown and adrUsed < 90 then Color.RED
         else Color.GRAY);
 
Last edited by a moderator:
  • Like
Reactions: QED

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
339 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top