//@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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Fast EMA
int
9
fastLen
Slow EMA
int
21
slowLen
RSI length
int
14
rsiLen
ATR length
int
14
atrLen
Stop (ATR x)
float
1.5
atrMult
Reward:Risk
float
2.0
rr
Show signal labels
bool
true
showLbls
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.
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
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
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
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
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
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