本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// ═══════════════════════════════════════════════════════════════════
// EMA200 Bounce Screener
// Flags stocks in an established uptrend whose daily low pulls back to a
// RISING 200-period EMA and closes back above it. Built for the Pine Screener:
// every condition is exposed as a column, so lists can be filtered directly.
//
// Signal conditions (all on the daily close):
// 1. EMA200 is rising (higher than 20 bars ago)
// 2. Price closed at least X % above the EMA200 within the last N bars
// (the pullback comes from strength, not from a sideways range)
// 3. The bar's low touches the EMA200 (at most 1 ATR below it)
// 4. The bar closes back above the EMA200
// 5. Optional market filter: SPY above its own 200-period EMA
//
// Reference levels (information only, not a complete strategy):
// • Buy stop: signal bar high + a small offset
// • Stop: 1.5 × ATR(14) below the EMA200
//
// Pine Screener notes:
// • only one request.security() call, returning a scalar (tuple returns can
// break screener runs)
// • the screener evaluates the last 500 bars, so the EMA200 can differ
// slightly from the chart value — confirm levels on the chart
// ═══════════════════════════════════════════════════════════════════
indicator("EMA200 Bounce Screener", overlay=false)
lenEma = input.int(200, "EMA length")
vorProz = input.float(5.0, "Prior strength: min. % above EMA", step=0.5)
vorTage = input.int(30, "… within the last N bars")
nahProz = input.float(3.0, "Watch: close at most % above EMA", step=0.5)
tick = input.float(0.02, "Buy-stop offset", step=0.01)
mitSpy = input.bool(true, "Market filter: SPY above its EMA200")
ema200 = ta.ema(close, lenEma)
atr14 = ta.atr(14)
steigt = ema200 > ema200[20]
vorher = ta.highest(close / ema200, vorTage)[1] >= 1 + vorProz / 100
// Single scalar call — screener-safe
spyUeber = request.security("SPY", "D", close > ta.ema(close, 200) ? 1 : 0, lookahead = barmerge.lookahead_off)
spyOk = mitSpy ? spyUeber == 1 : true
beruehrt = low <= ema200 and low >= ema200 - atr14
signal = steigt and vorher and beruehrt and close > ema200 and spyOk
// Early stage: price approaching the EMA200 but not touching it yet
nahe = steigt and vorher and close > ema200 and close <= ema200 * (1 + nahProz / 100) and spyOk and not signal
// ── Screener columns ─────────────────────────────────────────────────
plot(signal ? 1 : 0, title="Signal (1 = bounce today)")
plot(nahe ? 1 : 0, title="Watch (near EMA200)")
plot((close / ema200 - 1) * 100, title="Distance to EMA200 %")
plot((ema200 / ema200[20] - 1) * 100, title="EMA200 slope 20 bars %")
plot(high + tick, title="Buy stop")
plot(ema200 - 1.5 * atr14, title="Stop")
plot(ema200, title="EMA200")