Strategy · Pine Script v6 · On the chart

Pro-Swing System: 200 EMA and SuperTrend

by rosijay17-cmd

A swing strategy that goes long when the SuperTrend (period 10, multiplier 5) is bullish, price is above a rising 200-period EMA, and the long side is enabled.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code108
Settings13inputs
LicenceGPL-3.0
Last update7 days ago22 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

108 lines of Pine Script v6 from Pro_Swing_System_200EMA_SuperTrend.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Pro_Swing_System_200EMA_SuperTrend.pine
//@version=6
strategy("Pro-Swing system: 200 EMA & SuperTrend 10-5 - Simple Swing System", overlay=true, initial_capital=5000000, default_qty_type=strategy.percent_of_equity, default_qty_value=40, currency=currency.INR)

// ─── Strategy Toggles ────────────────────────────────────────────────────────
enableLong        = input.bool(true,  "Enable Long Trades?",  group="Strategy Toggles")
enableShort       = input.bool(false, "Enable Short Trades?", group="Strategy Toggles")

// ─── Partial Exit Settings ───────────────────────────────────────────────────
enablePartial     = input.bool(true,  "Enable Partial Exit?",         group="Partial Exit")
partialQtyPct     = input.float(30.0, "Partial Exit Qty %",           group="Partial Exit", minval=1.0, maxval=100.0, step=1.0)
partialType       = input.string("ATR", "Target Price Method",        group="Partial Exit", options=["ATR", "Fixed Points", "Fixed %"])
partialAtrMult    = input.float(3,  "ATR Multiplier (ATR mode)",    group="Partial Exit", minval=0.1, step=0.1)
partialAtrLen     = input.int(50,     "ATR Length (ATR mode)",        group="Partial Exit", minval=1)
partialFixedPts   = input.float(50.0, "Fixed Points (Points mode)",   group="Partial Exit", minval=0.1, step=0.5)
partialFixedPct   = input.float(5,  "Fixed % Move (% mode)",       group="Partial Exit", minval=0.01, step=0.1)

// ─── Core Inputs ─────────────────────────────────────────────────────────────
st_period  = input.int(10,    "SuperTrend Period")
st_factor  = input.float(5.0, "SuperTrend Multiplier")
ema_len    = input.int(200,   "EMA Length")
show_ema   = input.bool(true, "Show 200 EMA?")

// ─── Indicators ──────────────────────────────────────────────────────────────
[superTrend, direction] = ta.supertrend(st_factor, st_period)
ema200 = ta.ema(close, ema_len)
atrVal = ta.atr(partialAtrLen)

// ─── Logic Conditions ────────────────────────────────────────────────────────
aboveEma = close > ema200
belowEma = close < ema200
emaUp    = ema200 > ema200[1]
emaDown  = ema200 < ema200[1]
stBuy    = direction < 0
stSell   = direction > 0

longCondition  = enableLong  and stBuy  and aboveEma and emaUp
shortCondition = enableShort and stSell and belowEma  and emaDown

// ─── Partial Exit State ───────────────────────────────────────────────────────
// Tracks entry price and whether the partial has already fired this trade
var float entryPx        = na
var bool  partialDone    = false

// Reset state on new entry
if longCondition and strategy.position_size <= 0
    entryPx     := close
    partialDone := false

if shortCondition and strategy.position_size >= 0
    entryPx     := close
    partialDone := false

// ─── Compute Partial Target ───────────────────────────────────────────────────
partialTarget(entryPrice, isLong) =>
    float offset = switch partialType
        "ATR"          => atrVal * partialAtrMult
        "Fixed Points" => partialFixedPts
        "Fixed %"      => entryPrice * (partialFixedPct / 100.0)
        => atrVal * partialAtrMult
    isLong ? entryPrice + offset : entryPrice - offset

// ─── Entries ──────────────────────────────────────────────────────────────────
if longCondition
    strategy.entry("Long",  strategy.long,  comment="ST Buy + EMA Up")

if shortCondition
    strategy.entry("Short", strategy.short, comment="ST Sell + EMA Down")

// ─── Partial Exits ────────────────────────────────────────────────────────────
if enablePartial and not partialDone
    if strategy.position_size > 0 and not na(entryPx)
        longTarget = partialTarget(entryPx, true)
        if high >= longTarget
            strategy.close("Long", qty_percent=partialQtyPct, comment="Partial TP")
            partialDone := true

    if strategy.position_size < 0 and not na(entryPx)
        shortTarget = partialTarget(entryPx, false)
        if low <= shortTarget
            strategy.close("Short", qty_percent=partialQtyPct, comment="Partial TP")
            partialDone := true

// ─── Full Exit on SuperTrend Flip ─────────────────────────────────────────────
if strategy.position_size > 0 and stSell
    strategy.close("Long",  comment="ST Flip")
    partialDone := false

if strategy.position_size < 0 and stBuy
    strategy.close("Short", comment="ST Flip")
    partialDone := false

// ─── Visuals ──────────────────────────────────────────────────────────────────
plot(superTrend, "SuperTrend", color=direction < 0 ? color.green : color.red, linewidth=2)

emaColor = emaUp ? color.green : emaDown ? color.red : color.gray
plot(show_ema ? ema200 : na, "200 EMA", color=emaColor, linewidth=3)

bgcolor(longCondition ? color.new(color.green, 90) : shortCondition ? color.new(color.red, 90) : na)

// Partial target line — visible only while in a trade and partial not yet hit
float displayTarget = na
if enablePartial and not partialDone and not na(entryPx)
    if strategy.position_size > 0
        displayTarget := partialTarget(entryPx, true)
    else if strategy.position_size < 0
        displayTarget := partialTarget(entryPx, false)

plot(displayTarget, "Partial TP Target", color=color.new(color.orange, 0), linewidth=1, style=plot.style_linebr)

Overview

Shorts follow the mirror rules but are switched off by default. An optional partial exit closes a set percentage of the position at a target set by ATR multiple, fixed points or a fixed percent move. Position size is a share of equity. The code shows no hard stop loss, so exits depend on the SuperTrend flip. The EMA and signals draw on the price chart.

Details

Published by

rosijay17-cmd on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Enable Long Trades?booltrueenableLong
Enable Short Trades?boolfalseenableShort
Enable Partial Exit?booltrueenablePartial
Partial Exit Qty %float30.0partialQtyPct
Target Price MethodstringATRpartialType
ATR Multiplier (ATR mode)float3partialAtrMult
ATR Length (ATR mode)int50partialAtrLen
Fixed Points (Points mode)float50.0partialFixedPts
Fixed % Move (% mode)float5partialFixedPct
SuperTrend Periodint10st_period
SuperTrend Multiplierfloat5.0st_factor
EMA Lengthint200ema_len
Show all 13 settings
SettingTypeDefaultVariable
Show 200 EMA?booltrueshow_ema
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.

Similar Pine Scripts

Doge SMA

by hackingthemarkets
474 stars

Doge SMA is a long-only moving-average crossover strategy drawn on the price chart. It calculates a fast and a slow simple moving average of close and enters a long position when the fast average crosses above the slow average, but only inside a user-defined s

Strategy v4 TrendMoving averages
Updated 4 years ago · None stated GitHub repository of Doge SMA

This strategy calculates and plots a fast Exponential Moving Average (EMA) and a slow EMA directly on the main price chart. It enters long trades when the fast EMA crosses above the slow EMA and exits when the fast EMA crosses below the slow EMA. Inputs allow

Strategy v6 TrendMoving averages
Updated yesterday · AGPL-3.0 GitHub repository of Forven S01508 — Simple EMA20/50 Cross
330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 6 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers