OPEN-SOURCE SCRIPT
SwingTrades-Long-Daily

// =====================================================================================
// SwingTrades-Long-Daily — WHAT THIS INDICATOR DOES AND HOW (read this first)
// =====================================================================================
// THIS IS HALF OF A PAIR
// SwingTrades-Long used to be one script covering 4 categories (MT, 3Q, TR, R). It
// has been split into two independent indicators so each runs on the timeframe that
// actually fits its checks:
// - SwingTrades-Long-Daily (THIS script) — Category 1 (MT) + Category 2 (3Q).
// Runs on the DAILY chart. Answers: "is this stock structurally set up to buy,
// and is the trade worth the reward vs. risk?" Updates once per day.
// - SwingTrades-Long-30Mins (companion script) — Category 3 (TR) + Category 4 (R).
// Runs on the 30-MINUTE chart. Answers: "right now, intraday, is this a safe
// moment to pull the trigger, and how big should the position be?" Updates
// every 30 minutes throughout the session.
// The two scripts are fully independent — each computes and displays its OWN 0-10
// score. There is no shared/combined score across the pair. Run both side by side
// (Daily chart + 30-min chart): use Daily to decide whether to even be watching a
// stock, and 30-Min to decide whether right now is the moment to act.
//
// PURPOSE OF THIS SCRIPT
// Scores a stock 0-10 on: (1) Multi-Timeframe Price Action — is price aligned with
// higher timeframes, the broader market, and in an uptrend structure — and (2) 3Q —
// where has it come from, where can it go, and is the reward-vs-risk worth it. Every
// threshold is a configurable input.
//
// WHERE DATA COMES FROM
// - Runs on a DAILY chart. Daily Fast/Mid/Slow SMA (defaults 20/50/200), a separate
// Daily 5-SMA (used only for the 30-min pattern check), ATR, and volume are native.
// - Weekly data (HTF alignment) uses its OWN independently configurable Fast/Mid/Slow
// SMA lengths (defaults 10/20/50) — Daily and Weekly lengths are no longer tied
// together. The benchmark symbol (broader market alignment) is also pulled via
// request.security(), on "D", reusing the Daily Mid SMA length.
// - The 30-minute timeframe is pulled via request.security() purely to help confirm
// the "pattern" check (1.b.i) — the Trend Reading / Risk checks that used to also
// reference intraday data now live entirely in the companion 30-min script.
//
// STEP-BY-STEP LOGIC
// STEP A — Inputs, grouped by category.
// STEP B — Daily-native series: Daily Fast/Mid/Slow SMA, a separate Daily 5-SMA, ATR,
// and their "rising" slope flags.
// STEP C — Multi-timeframe pulls: Weekly (HTF, using its own Fast/Mid/Slow lengths),
// Benchmark (broader market), 30-min (just the close, for the pattern check).
// STEP D — 1. MULTI-TIMEFRAME PRICE ACTION (MT) — 9 checks, category score /10:
// a. HTF Aligned (Weekly) — weekly close > rising Weekly Fast SMA, AND
// Weekly Fast SMA > Weekly Mid SMA > Weekly Slow
// SMA (a full weekly SMA-stack check, mirroring
// the Daily stack checks below)
// b. Broader Market Aligned — benchmark close > rising benchmark Daily Mid
// SMA
// c. Pattern Confirmed — Daily price above a rising Daily Fast SMA, AND
// the current 30-min close is above the Daily
// 5-SMA AND that Daily 5-SMA is sloped up (see
// pattern-recognition note below)
// d. Price > Daily Fast SMA
// e. Price > Daily Mid SMA
// f. Daily Fast SMA > Daily Mid SMA
// g. Daily Mid SMA > Daily Slow SMA
// h. Volume > configured minimum
// i. Daily Fast, Mid, AND Slow SMA all sloped up
// NOTE: true chart-pattern recognition (flags, H&S, triangles, etc.) can't
// be reliably automated in Pine. The Daily side of "pattern confirmed" is
// approximated as price trading above a rising short-term SMA; the 30-min
// side checks that the live 30-min price is above the Daily 5-SMA AND that
// the Daily 5-SMA itself is sloped up — not a full trend-structure test.
// STEP E — 2. 3Q — BASE / TARGET / RvR — 3 checks, category score /10:
// a. Good Base Position — where close sits (%) within the recent N-bar
// high/low range ("where has it come from?")
// b. Reward Potential — % distance from close to the recent M-bar high
// ("where can it go?")
// c. RvR >= minimum — reward (target - close) vs risk (close - a local
// ATR/swing-low stop) ("is it worth it?"). NOTE: this stop is only used
// to size the RvR ratio here; the companion 30-min script computes its
// own live stop / position size for actual order placement.
// STEP F — Overall score: MT and 3Q category scores (0-10 each) are weighted
// (wMT/wQ, auto-normalized) and averaged into one 0-10 score. If the
// broader market is NOT aligned (Step D.b failed), the score is hard-capped
// (default 3) regardless of how good everything else looks — "go with the
// market, very little tolerance against it."
// STEP G — Optionally plots the Daily Fast/Mid/Slow SMAs (off by default — toggle in
// "Chart Display") and builds the dashboard table.
// =====================================================================================
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.
Скрипт с открытым кодом
В истинном духе TradingView, создатель этого скрипта сделал его открытым исходным кодом, чтобы трейдеры могли проверить и убедиться в его функциональности. Браво автору! Вы можете использовать его бесплатно, но помните, что перепубликация кода подчиняется нашим Правилам поведения.
Отказ от ответственности
Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.