Indicator · Pine Script v6 · On the chart

Signal Forge

by jayadevrana

Signal Forge is a trend-following overlay indicator that combines an ATR trailing stop with a customizable Exponential Moving Average trend filter.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code64
Settings6inputs
LicenceMPL-2.0
Last update2 days ago26 Oct 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

64 lines of Pine Script v6 from scripts/signal-forge-part-1.pine.txt, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

signal-forge-part-1.pine.txt
//@version=6
// Signal Forge, part 1: the core engine. By Jayadev Rana.
indicator("Signal Forge", overlay = true)

// 1. Inputs: how far the trail sits, and the trend baseline
atrLen  = input.int(10, "ATR length", minval = 1)
atrMult = input.float(3.0, "ATR multiplier", minval = 0.5, step = 0.1)
emaLen  = input.int(200, "Trend EMA length", minval = 1)
useEma  = input.bool(true, "Only signal with the EMA trend")
bullCol = input.color(#26a69a, "Bull colour")
bearCol = input.color(#ef5350, "Bear colour")

// 2. Volatility and trend
atr = ta.atr(atrLen)
ema = ta.ema(close, emaLen)

// 3. The trail: it only ever moves in the trend's favour
longStop  = close - atrMult * atr
shortStop = close + atrMult * atr
var float trail = na
var int   dir   = 1
if na(trail)
    trail := longStop
else if dir == 1
    trail := math.max(trail, longStop)
    if close < trail
        dir   := -1
        trail := shortStop
else
    trail := math.min(trail, shortStop)
    if close > trail
        dir   := 1
        trail := longStop

// 4. Draw the trail by direction, and shade it to price
upLine = dir == 1 ? trail : na
dnLine = dir == -1 ? trail : na
pMid = plot(hl2, "Mid", display = display.none)
pUp  = plot(upLine, "Bull trail", bullCol, 2, plot.style_linebr)
pDn  = plot(dnLine, "Bear trail", bearCol, 2, plot.style_linebr)
fill(pMid, pUp, color.new(bullCol, 85), "Bull zone")
fill(pMid, pDn, color.new(bearCol, 85), "Bear zone")
plot(ema, "Trend EMA", color.orange, 2)

// 5. Candles: coloured when trail and EMA agree, grey when not
bullOk = dir == 1 and (not useEma or close > ema)
bearOk = dir == -1 and (not useEma or close < ema)
barcolor(bullOk ? bullCol : bearOk ? bearCol : color.gray)

// 6. Raw signals: a flip, with the trend, on a CLOSED candle only
flipUp   = dir == 1 and dir[1] == -1
flipDown = dir == -1 and dir[1] == 1
rawBuy   = flipUp and bullOk and barstate.isconfirmed
rawSell  = flipDown and bearOk and barstate.isconfirmed

// 7. Markers and alerts. For now, buy is simply the raw signal
buy  = rawBuy
sell = rawSell
plotshape(buy, "BUY", shape.labelup, location.belowbar, bullCol,
  text = "BUY", textcolor = color.white, size = size.small)
plotshape(sell, "SELL", shape.labeldown, location.abovebar, bearCol,
  text = "SELL", textcolor = color.white, size = size.small)
alertcondition(buy, "Signal Forge BUY", "BUY {{ticker}} at {{close}}")
alertcondition(sell, "Signal Forge SELL", "SELL {{ticker}} at {{close}}")

Overview

Signal Forge plots dynamic trailing stop lines and colors bars based on whether price action aligns with the EMA baseline. Non-repainting buy and sell signals generate on confirmed bar closes when a directional flip agrees with the trend filter. Inputs allow customization of ATR length, ATR multiplier, trend EMA period, and an option to disable the EMA trend requirement.

Details

Published by

jayadevrana on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Volatility & bands, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

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.

Topics

algorithmic-tradingbacktestingema-crossoverpine-scriptpine-script-v6pinescriptrsitechnical-analysistrading-automationtrading-indicators

Settings

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

SettingTypeDefaultVariable
ATR lengthint10atrLen
ATR multiplierfloat3.0atrMult
Trend EMA lengthint200emaLen
Only signal with the EMA trendbooltrueuseEma
Bull colourcolor#26a69abullCol
Bear colourcolor#ef5350bearCol
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

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

Bollinger Bands Force

by harryguiacorn
219 stars

This indicator modifies standard Bollinger Bands to measure directional trend force based on line alignment. It calculates a simple moving average basis along with upper and lower volatility bands. When all three lines move upward or downward simultaneously, i

Indicator v5 Volatility & bandsTrend
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Force

Adaptive MA Slope

by capissimo
114 stars

This indicator calculates Kaufman's Adaptive Moving Average (KAMA) on a chosen price source and determines trend direction based on the slope across a configurable lookback window. Signals can be filtered by short-term volatility expansion using ATR comparison

Indicator v4 Moving averagesTrend
Updated 1 year ago · None stated GitHub repository of Adaptive MA Slope

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