Indicator · Pine Script v6 · On the chart

PowerTrend

by peterdmv

PowerTrend is a price-chart overlay that recreates Webby's Power Trend.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code93
Settings5inputs
LicenceMPL-2.0
Last update8 weeks ago30 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

93 lines of Pine Script v6 from indicators/PowerTrend.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

PowerTrend.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peterdmv
//
// Recreation of Webby's Power Trend indicator (Mike Webster, IBD/O'Neil). Reimplemented for educational purposes.
//
// Release: v1

//@version=6
indicator("PowerTrend", overlay=true)

// --- Inputs ---
emaLen       = input.int(21,  "EMA Length",                       minval=1)
smaLen       = input.int(50,  "SMA Length",                       minval=1)
lowEmaDays   = input.int(10,  "Low Above EMA (consecutive days)", minval=1)
emaSmadays   = input.int(5,   "EMA Above SMA (consecutive days)", minval=1)
highLookback = input.int(252, "Recent High Lookback (days)",      minval=10)

// --- Core indicators ---
ema21 = ta.ema(close, emaLen)
sma50 = ta.sma(close, smaLen)

// --- Consecutive-day counters ---
var int lowAboveEmaCount = 0
var int emaAboveSmaCount = 0

lowAboveEmaCount := low > ema21 ? lowAboveEmaCount + 1 : 0
emaAboveSmaCount := ema21 > sma50 ? emaAboveSmaCount + 1 : 0

// --- Four start conditions ---
// 1. Daily low above 21 EMA for N consecutive days
cond1 = lowAboveEmaCount >= lowEmaDays
// 2. 21 EMA above 50 SMA for N consecutive days
cond2 = emaAboveSmaCount >= emaSmadays
// 3. 50 SMA trending upward
cond3 = sma50 > sma50[1]
// 4. Closes up on the day
cond4 = close > open

// --- End / circuit-breaker conditions ---
// Primary: 21 EMA crosses back under 50 SMA
endPrimary = ta.crossunder(ema21, sma50)

// Circuit breaker: closes below 50 SMA while more than 10% off recent high
recentHigh = ta.highest(high, highLookback)
pctOffHigh = (recentHigh - close) / recentHigh * 100
endCircuit = close < sma50 and pctOffHigh > 10.0

// --- PowerTrend state machine ---
var bool inPowerTrend = false

if inPowerTrend
    if endPrimary or endCircuit
        inPowerTrend := false
else
    if cond1 and cond2 and cond3 and cond4
        inPowerTrend := true

// --- Visual output ---
ema21Plot = plot(ema21, "21 EMA", color.new(color.blue, 0), 1)
sma50Plot = plot(sma50, "50 SMA", color.new(color.orange, 0), 1)

fill(ema21Plot, sma50Plot,
     color = ema21 > sma50 ? color.new(color.green, 90) : color.new(color.red, 90),
     title = "EMA/SMA Spread")

bgcolor(inPowerTrend ? color.new(color.green, 85) : na, title = "PowerTrend Active")

plotshape(not inPowerTrend[1] and inPowerTrend,
     title    = "PowerTrend Start",
     style    = shape.arrowup,
     location = location.belowbar,
     color    = color.green,
     size     = size.normal)

plotshape(inPowerTrend[1] and not inPowerTrend,
     title    = "PowerTrend End",
     style    = shape.arrowdown,
     location = location.abovebar,
     color    = color.red,
     size     = size.normal)

// --- Alerts ---
alertcondition(not inPowerTrend[1] and inPowerTrend,
     title   = "PowerTrend Started",
     message = "PowerTrend activated — all four conditions met")

alertcondition(inPowerTrend[1] and not inPowerTrend and endPrimary,
     title   = "PowerTrend Ended (EMA cross)",
     message = "PowerTrend ended — 21 EMA crossed below 50 SMA")

alertcondition(inPowerTrend[1] and not inPowerTrend and endCircuit,
     title   = "PowerTrend Ended (Circuit Breaker)",
     message = "PowerTrend ended — circuit breaker triggered (close < 50 SMA and >10% off high)")

Overview

PowerTrend plots a configurable EMA and SMA, counts consecutive days the low stays above the EMA and the EMA stays above the SMA, and starts an uptrend when those counts, a rising SMA, and an up close all occur together. It ends the state on an EMA cross under the SMA or when price closes below the SMA more than 10 percent under a recent high. Background color, arrows, and alerts mark starts and ends. Lengths and lookback are adjustable.

Details

Published by

peterdmv on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages

Markets

Stocks

Timeframes

H4 and above

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
EMA Lengthint21emaLen
SMA Lengthint50smaLen
Low Above EMA (consecutive days)int10lowEmaDays
EMA Above SMA (consecutive days)int5emaSmadays
Recent High Lookback (days)int252highLookback
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

948 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 10 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon
257 stars

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba

Indicator v5 Moving averagesTrend Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

60K均線

by TaichiS
219 stars

This multi-timeframe indicator calculates and plots 20-period and 60-period simple moving averages from the 60-minute timeframe directly onto the price chart. The 20-period average displays as a green line, while the 60-period average appears in blue. It serve

Indicator v4 Moving averagesTrend Repaints
Updated 5 years ago · None stated GitHub repository of 60K均線

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers