Indicator · Pine Script v6 · On the chart

Indicator Template

by Jahanzaib211

A starter indicator template that plots a fast and slow exponential moving average on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code77
Settings7inputs
LicenceMIT
Last updateyesterday28 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

77 lines of Pine Script v6 from skills/public/pine-script/templates/indicator.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

indicator.pine
//@version=6
// Indicator template — signals, levels, alerts, and an info table.
// Companion to strategy.pine. One script per file: if you need a backtest
// too, that is a second file.
indicator("Indicator Template", overlay = true, max_labels_count = 500)

// ── Inputs ──────────────────────────────────────────────────────────────────
fastLen  = input.int(9,     "Fast EMA",      minval = 1)
slowLen  = input.int(21,    "Slow EMA",      minval = 1)
rsiLen   = input.int(14,    "RSI length",    minval = 1)
atrLen   = input.int(14,    "ATR length",    minval = 1)
atrMult  = input.float(1.5, "Stop (ATR x)",  minval = 0.1, step = 0.1)
rr       = input.float(2.0, "Reward:Risk",   minval = 0.1, step = 0.1)
showLbls = input.bool(true, "Show signal labels")

// ── Indicators ──────────────────────────────────────────────────────────────
fastEma = ta.ema(close, fastLen)
slowEma = ta.ema(close, slowLen)
rsiVal  = ta.rsi(close, rsiLen)
atr     = ta.atr(atrLen)

// ── Signals ─────────────────────────────────────────────────────────────────
// barstate.isconfirmed keeps live signals from flickering as the bar forms.
longSignal  = ta.crossover(fastEma, slowEma)  and rsiVal > 50 and barstate.isconfirmed
shortSignal = ta.crossunder(fastEma, slowEma) and rsiVal < 50 and barstate.isconfirmed

// ── Levels ──────────────────────────────────────────────────────────────────
var float entryPx = na
var float stopPx  = na
var float tgtPx   = na

if longSignal
    entryPx := close
    stopPx  := close - atr * atrMult
    tgtPx   := close + atr * atrMult * rr
else if shortSignal
    entryPx := close
    stopPx  := close + atr * atrMult
    tgtPx   := close - atr * atrMult * rr

// ── Plots ───────────────────────────────────────────────────────────────────
plot(fastEma, "Fast EMA", color.new(color.aqua,   0))
plot(slowEma, "Slow EMA", color.new(color.orange, 0))

plotshape(longSignal,  "Long",  shape.triangleup,   location.belowbar, color.new(color.green, 0), size = size.small)
plotshape(shortSignal, "Short", shape.triangledown, location.abovebar, color.new(color.red,   0), size = size.small)

if showLbls and longSignal
    label.new(bar_index, low,  "LONG\nSL " + str.tostring(stopPx, format.mintick) + "\nTP " + str.tostring(tgtPx, format.mintick),
              style = label.style_label_up,   color = color.new(color.green, 20), textcolor = color.white, size = size.small)
if showLbls and shortSignal
    label.new(bar_index, high, "SHORT\nSL " + str.tostring(stopPx, format.mintick) + "\nTP " + str.tostring(tgtPx, format.mintick),
              style = label.style_label_down, color = color.new(color.red,   20), textcolor = color.white, size = size.small)

// ── Alerts ──────────────────────────────────────────────────────────────────
// alert() over alertcondition(): the message is built at runtime, so it can
// carry live prices. alertcondition() needs a compile-time constant string.
if longSignal
    alert("LONG " + syminfo.ticker + " @ " + str.tostring(close, format.mintick) +
          " | SL " + str.tostring(stopPx, format.mintick) +
          " | TP " + str.tostring(tgtPx,  format.mintick), alert.freq_once_per_bar_close)
if shortSignal
    alert("SHORT " + syminfo.ticker + " @ " + str.tostring(close, format.mintick) +
          " | SL " + str.tostring(stopPx, format.mintick) +
          " | TP " + str.tostring(tgtPx,  format.mintick), alert.freq_once_per_bar_close)

// ── Info table ──────────────────────────────────────────────────────────────
if barstate.islast
    var table info = table.new(position.top_right, 2, 4, border_width = 1)
    table.cell(info, 0, 0, "RSI",   text_color = color.white)
    table.cell(info, 1, 0, str.tostring(rsiVal, "#.#"),          text_color = color.white)
    table.cell(info, 0, 1, "ATR",   text_color = color.white)
    table.cell(info, 1, 1, str.tostring(atr, format.mintick),    text_color = color.white)
    table.cell(info, 0, 2, "Stop",  text_color = color.white)
    table.cell(info, 1, 2, str.tostring(stopPx, format.mintick), text_color = color.white)
    table.cell(info, 0, 3, "Target", text_color = color.white)
    table.cell(info, 1, 3, str.tostring(tgtPx, format.mintick),  text_color = color.white)

Overview

A long or short marker appears on a confirmed bar when the averages cross and RSI is above or below 50. Each signal calculates an ATR-based stop level and a target set by a reward-to-risk ratio, shown in optional labels. Settings control the average lengths, RSI and ATR lengths, multiplier and label display.

Details

Published by

Jahanzaib211 on GitHub

Draws

On the price chart

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

agentaideveloper-toolsfastapilanggraphnextjsopen-sourcepythonsandbox

Settings

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

SettingTypeDefaultVariable
Fast EMAint9fastLen
Slow EMAint21slowLen
RSI lengthint14rsiLen
ATR lengthint14atrLen
Stop (ATR x)float1.5atrMult
Reward:Riskfloat2.0rr
Show signal labelsbooltrueshowLbls
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

947 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 11 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
280 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 2 days ago · 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
228 stars

This indicator computes moving average and RSI bias signals across the current timeframe and four higher timeframes. It sums biases from the MA and RSI to derive an overall bullish or bearish signal. The results appear in a configurable table that displays eac

Indicator v6 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of Multi-Timeframe Analysis Template

More Moving averages scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers