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.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Enable Long Trades?
bool
true
enableLong
Enable Short Trades?
bool
false
enableShort
Enable Partial Exit?
bool
true
enablePartial
Partial Exit Qty %
float
30.0
partialQtyPct
Target Price Method
string
ATR
partialType
ATR Multiplier (ATR mode)
float
3
partialAtrMult
ATR Length (ATR mode)
int
50
partialAtrLen
Fixed Points (Points mode)
float
50.0
partialFixedPts
Fixed % Move (% mode)
float
5
partialFixedPct
SuperTrend Period
int
10
st_period
SuperTrend Multiplier
float
5.0
st_factor
EMA Length
int
200
ema_len
Show all 13 settings
Setting
Type
Default
Variable
Show 200 EMA?
bool
true
show_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.
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
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
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
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
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
This educational strategy demonstrates how to configure and handle user input parameters in Pine Script. It calculates two Simple Moving Averages (SMAs) for fast and slow periods, plotting both directly on the price chart. The strategy initiates a long positio