Supertrend + EMA Long Trading

Purpose
Screen and alert for swing entries when weekly momentum is aligned: green weekly candle, price closing above EMA‑10, and Supertrend(10,3) in bullish state.
Exit and alert when the weekly close drops back below EMA‑10, preventing repeated buy signals during the same up‑leg.
Core logic
Weekly data is pulled via higher‑timeframe requests for Open, Close, EMA‑10, and Supertrend(10,3).
Buy condition: weekly candle is green (Close > Open), Close > EMA‑10, and Supertrend direction is bullish; note the built‑in Supertrend returns direction −1 for bullish and +1 for bearish.
Sell condition: the weekly Close falls below weekly EMA‑10.
One‑shot behavior
A simple state variable inLong ensures only one buy alert per trend leg; no repeated buy markers while the condition remains valid.
The state flips to flat at the sell condition, enabling the next future buy when rules are met again.
Exact timing (no next‑bar delay)
Signals are gated to the precise weekly bar close using a time alignment check and barstate confirmation.
On intraday charts, signals still trigger at the instant the weekly candle completes, not on the following bar.
Visuals
Plots the weekly EMA‑10 on the chart for context.
Draws green “BUY‑W” triangles below bars and red “SELL‑W” triangles above bars.
Optionally tints the background a subtle green while inLong is true.
Alerts
Two alertcondition entries are provided: one for the buy event and one for the sell event.
Create alerts from the chart by selecting this indicator and choosing the corresponding condition; messages include ticker and interval.
Inputs
Signal timeframe: default Weekly (can be changed if needed).
EMA length: default 10.
Supertrend parameters: ATR length 10 and factor 3.
Practical use
Add the indicator to weekly or lower‑timeframe charts; it will always evaluate and trigger at the weekly close.
Combine with position sizing and risk controls outside the script; the script is an indicator, not an order‑executing strategy.
Notes and caveats
Supertrend direction mapping is intentional: −1 indicates bullish (green), +1 bearish (red) in the built‑in function.
Because signals confirm at bar close, intra‑week fluctuations won’t trigger early; alerts only occur when the weekly candle is finalized.
Notes
The “new green” filter relies on comparing current vs previous weekly Supertrend direction in the HTF context, which is the correct way to confirm a flip rather than checking the LTF‑expanded series across many intrabars.
Supertrend turns green in uptrends and flips when price crosses its ATR‑based trail, so requiring a flip plus close>EMA‑10 and a green weekly candle add strong confluence at the exact weekly bar close for entries.
New Features Added
1. Weekly Support and Resistance Calculation
Computes Support and Resistance levels from confirmed weekly pivot highs and lows using ta.pivothigh() and ta.pivotlow() with 15 left/right bars (customizable)
Uses the same pivot-based methodology as the Lux Algo S/R indicator you referenced
Levels are calculated inside request.security() to ensure weekly accuracy regardless of chart timeframe
The [1] history reference ensures only confirmed pivots are used, avoiding repainting
2. Additional Buy Signal
New buy trigger: When a weekly green candle closes and crosses above the weekly Resistance level
This buy signal is independent of the Supertrend flip condition, giving you two distinct entry paths:
Path 1 (original): Green weekly candle + close above EMA10 + Supertrend flips from red to green
Path 2 (new): Green weekly candle crosses above weekly Resistance level
Both paths respect the one-shot state machine to prevent duplicate entries while in a position
3. Visual Enhancements
Plots horizontal Support and Resistance lines on the chart with customizable colors (red for Resistance, blue for Support by default)
Lines are drawn as flat segments that break when levels change, using the condition (wResStep != wResStep[1]) ? na : color
Lines are offset left by -(rightBars + 1) bars to align with the pivot origin, matching the visual style of your reference image
Toggle option to show/hide S/R lines
Customizable line width (1-5)
Additional buy shape labeled "BUY-R" in teal color to distinguish resistance-breakout entries from Supertrend-flip entries
4. New Alerts
Alert for resistance-cross buy: "BUY-W: Green weekly close crosses Resistance"
Original alerts for Supertrend+EMA buy and sell remain unchanged
What Stayed the Same
All original weekly Supertrend (10,3) and EMA10 logic
Weekly close detection using time_close equality
Sell condition (weekly close below EMA10)
One-shot entry state machine
No-lookahead HTF data requests for signal integrity
Weekly EMA10 blue line plot
Background coloring when in position
The indicator now provides confluence-based entries by combining trend (Supertrend), momentum (EMA), and structure (Support/Resistance) analysis, all evaluated strictly at the weekly bar close for Indian stock scanning on your watchlist.
Script sob convite
Somente usuários aprovados pelo autor podem acessar este script. Você precisará solicitar e obter permissão para usá-lo. Normalmente, essa permissão é concedida após o pagamento. Para obter mais detalhes, siga as instruções do autor abaixo ou entre em contato diretamente com yashgarg0408.
O TradingView NÃO recomenda pagar ou usar um script ao não ser que você confie totalmente no seu autor e compreende como isso funciona. Você pode também encontrar alternativas gratuitas e de código aberto em nossa comunidade de scripts.
Instruções do autor
Aviso legal
Script sob convite
Somente usuários aprovados pelo autor podem acessar este script. Você precisará solicitar e obter permissão para usá-lo. Normalmente, essa permissão é concedida após o pagamento. Para obter mais detalhes, siga as instruções do autor abaixo ou entre em contato diretamente com yashgarg0408.
O TradingView NÃO recomenda pagar ou usar um script ao não ser que você confie totalmente no seu autor e compreende como isso funciona. Você pode também encontrar alternativas gratuitas e de código aberto em nossa comunidade de scripts.