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
83 lines of Pine Script v5 from public/code/memecoin__tiered_exit.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
memecoin__tiered_exit.pine
//@version=5
// =====================================================
// Tiered Exit Strategy (Memecoin) - Strategy Lab
// =====================================================
// Tiered profit-taking: partial exits at +50% / +150% / +300% levels,
// moonbag tracking via trailing stop, hard SL protection.
// =====================================================
strategy("Tiered Exit (Memecoin)", overlay=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
pyramiding=0, calc_on_every_tick=true)
// ============ ENTRY (basit momentum trigger) ============
useSimpleEntry = input.bool(true, "Use simple momentum entry")
emaFast = input.int(9, "EMA Fast")
emaSlow = input.int(21, "EMA Slow")
// ============ TIERED EXIT PARAMS ============
tp1Pct = input.float(50.0, "TP1 % gain") / 100
tp2Pct = input.float(150.0, "TP2 % gain") / 100
tp3Pct = input.float(300.0, "TP3 % gain") / 100
sell1 = input.float(30.0, "TP1 sell %") / 100
sell2 = input.float(30.0, "TP2 sell %") / 100
sell3 = input.float(30.0, "TP3 sell %") / 100
hardSL = input.float(25.0, "Hard SL %") / 100
trailDD = input.float(35.0, "Trailing drawdown from ATH %") / 100
ef = ta.ema(close, emaFast)
es = ta.ema(close, emaSlow)
entrySig = useSimpleEntry and ta.crossover(ef, es)
if entrySig and strategy.position_size == 0
strategy.entry("Long", strategy.long)
// ============ POSITION TRACKING ============
var float entryPrice = na
var float athPrice = na
var bool tp1Done = false
var bool tp2Done = false
var bool tp3Done = false
if strategy.position_size > 0 and na(entryPrice)
entryPrice := strategy.position_avg_price
athPrice := close
tp1Done := false
tp2Done := false
tp3Done := false
if strategy.position_size > 0
athPrice := math.max(athPrice, high)
// ============ TIERED EXITS ============
if strategy.position_size > 0 and not na(entryPrice)
pctChange = (close - entryPrice) / entryPrice
// Hard SL
if pctChange <= -hardSL
strategy.close("Long", comment="Hard SL")
entryPrice := na
// Trailing stop (in profit zone)
ddFromAth = (athPrice - close) / athPrice
if pctChange > 0.30 and ddFromAth >= trailDD
strategy.close("Long", comment="Trail Stop")
entryPrice := na
// TP kademeleri
if not tp1Done and close >= entryPrice * (1 + tp1Pct)
strategy.close("Long", qty_percent=sell1 * 100, comment="TP1 +50%")
tp1Done := true
if not tp2Done and close >= entryPrice * (1 + tp2Pct)
strategy.close("Long", qty_percent=sell2 * 100, comment="TP2 +150%")
tp2Done := true
if not tp3Done and close >= entryPrice * (1 + tp3Pct)
strategy.close("Long", qty_percent=sell3 * 100, comment="TP3 +300%")
tp3Done := true
if strategy.position_size == 0
entryPrice := na
plot(ef, "EMA Fast", color.aqua)
plot(es, "EMA Slow", color.orange)
plotshape(entrySig, "Entry", shape.triangleup, location.belowbar, color.lime)
Overview
Position risk and profits are managed through tiered exit stages: three custom percentage-based profit targets with partial exits, a hard percentage stop loss, and a trailing drawdown exit trigger calculated from the peak high since trade entry. Indicators and signal arrows plot directly on the price chart. The strategy recalculates on every tick, which means signals can fluctuate on open live bars before closing.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Use simple momentum entry
bool
true
useSimpleEntry
EMA Fast
int
9
emaFast
EMA Slow
int
21
emaSlow
TP1 % gain
float
50.0
tp1Pct
TP2 % gain
float
150.0
tp2Pct
TP3 % gain
float
300.0
tp3Pct
TP1 sell %
float
30.0
sell1
TP2 sell %
float
30.0
sell2
TP3 sell %
float
30.0
sell3
Hard SL %
float
25.0
hardSL
Trailing drawdown from ATH %
float
35.0
trailDD
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