The Setup Factory Short-Term Extension

TheSetupFactory · study · 54 行 · 点赞 10 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("The Setup Factory Short-Term Extension", shorttitle = "TSF ST Ext", overlay = true)
 
// ── Inputs ──────────────────────────────────────────────────────────────────
// Short term: marker when the close is at least this many ATRs above the fast EMA
showFast  = input.bool(true, "Show fast")
fastLen   = input.int(9, "Fast EMA", minval = 1)
fastMult  = input.float(2.0, "Fast x ATR", minval = 0.1, step = 0.1)
fastColor = input.color(#E53935, "Fast colour")
fastShape = input.string("Diamond", "Fast shape", options = ["Diamond", "Triangle", "Square", "Dot"])
 
// Intermediate term: marker when the close is at least this many ATRs above the slow EMA
showSlow  = input.bool(true, "Show slow")
slowLen   = input.int(21, "Slow EMA", minval = 1)
slowMult  = input.float(2.5, "Slow x ATR", minval = 0.1, step = 0.1)
slowColor = input.color(#4FB8B2, "Slow colour")
slowShape = input.string("Diamond", "Slow shape", options = ["Diamond", "Triangle", "Square", "Dot"])
 
atrLen    = input.int(14, "ATR length", minval = 1)
 
// ── Fixed values ────────────────────────────────────────────────────────────
FAST_GAP = 0.3      // red marker: distance above the candle's high, in ATRs
SLOW_GAP = 0.8      // teal marker: distance above the candle's high, in ATRs
 
// ── Values ──────────────────────────────────────────────────────────────────
emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)
atrNow  = ta.atr(atrLen)
 
// Extension in ATRs (same form as the TSF screener spec):
//   A = ATR / Close x 100
//   B = (Close - EMA) / EMA x 100
//   Extension = B / A
atrPct  = atrNow / close * 100
extFast = ((close - emaFast) / emaFast * 100) / atrPct
extSlow = ((close - emaSlow) / emaSlow * 100) / atrPct
 
fastHit = showFast and extFast >= fastMult
slowHit = showSlow and extSlow >= slowMult
 
// ── Marker shapes, taken from the settings ──────────────────────────────────
fastStyle = fastShape == "Diamond" ? shape.diamond : fastShape == "Triangle" ? shape.triangledown : fastShape == "Square" ? shape.square : shape.circle
slowStyle = slowShape == "Diamond" ? shape.diamond : slowShape == "Triangle" ? shape.triangledown : slowShape == "Square" ? shape.square : shape.circle
 
// ── Markers above the candle, on the main price chart ───────────────────────
// Each marker has its own height, so the two never cover each other: red first, teal above it.
plotshape(fastHit ? high + FAST_GAP * atrNow : na, title = "Extended from fast EMA", style = fastStyle,
     location = location.absolute, color = fastColor, size = size.tiny, force_overlay = true)
plotshape(slowHit ? high + SLOW_GAP * atrNow : na, title = "Extended from slow EMA", style = slowStyle,
     location = location.absolute, color = slowColor, size = size.tiny, force_overlay = true)
 
// ── Alerts ──────────────────────────────────────────────────────────────────
alertcondition(fastHit, "Extended from the fast EMA", "The close is extended above the fast EMA")
alertcondition(slowHit, "Extended from the slow EMA", "The close is extended above the slow EMA")

← 返回列表