Strategy · Pine Script v5 · On the chart

Sell-Only Strategy

by karma659· code credited to karmakarakash659

This short-only strategy identifies sell setups by combining a 3-period RSI overbought condition with a bearish engulfing candlestick pattern.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code86
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update11 days ago19 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

86 lines of Pine Script v5 from pine/SellOnlyStrategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

SellOnlyStrategy.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © karmakarakash659
//
// Sell-only strategy derived from the "Buy/Sell" indicator.
// The buy side is intentionally dropped — only the (reliable) SELL signal is traded, as a short.

//@version=5
strategy("Sell-Only Strategy",
     overlay              = true,
     initial_capital      = 10000,
     default_qty_type     = strategy.percent_of_equity,
     default_qty_value    = 100,
     pyramiding           = 0,
     commission_type      = strategy.commission.percent,
     commission_value     = 0.04,      // adjust to your instrument, or override in Properties tab
     slippage             = 1,
     calc_on_every_tick   = false)

// ============================================================
//  Inputs
// ============================================================
useFastExit = input.bool(true,  "Fast midpoint exit (original logic)", group = "Exits")
useTPSL     = input.bool(true,  "Use fixed Take Profit / Stop Loss",   group = "Exits")
tpPerc      = input.float(1.0,  "Take Profit %", minval = 0, step = 0.1, group = "Exits") / 100.0
slPerc      = input.float(1.0,  "Stop Loss %",   minval = 0, step = 0.1, group = "Exits") / 100.0
graceFrom   = input.int(3, "Fast-exit armed from bar", minval = 0, group = "Exits")
graceTo     = input.int(7, "Fast-exit armed until bar", minval = 1, group = "Exits")

// ============================================================
//  Signal logic (unchanged from the indicator, sell side only)
// ============================================================
bearishEC = close < open[1] and close[1] > open[1]

rsio  = ta.rsi(open,     3)
rsic  = ta.rsi(close,    3)
rsipo = ta.rsi(open[1],  3)
rsipc = ta.rsi(close[1], 3)

rsioverbought = rsio > 70
sellcond      = rsioverbought and rsio > rsipo and rsic < rsipc and bearishEC

// ============================================================
//  Entry — short only
// ============================================================
if sellcond and strategy.position_size == 0
    strategy.entry("Short", strategy.short)

// ============================================================
//  Exit 1 — fixed TP / SL (backtestable, handles intrabar)
//  Short: profit target sits BELOW entry, stop sits ABOVE entry.
// ============================================================
if useTPSL and strategy.position_size < 0
    tpPrice = strategy.position_avg_price * (1.0 - tpPerc)
    slPrice = strategy.position_avg_price * (1.0 + slPerc)
    strategy.exit("TP/SL", from_entry = "Short", limit = tpPrice, stop = slPrice)

// ============================================================
//  Exit 2 — original "fast midpoint" exit.
//  In the indicator this armed 3–7 bars after the signal and
//  fired when the bar midpoint crossed back above the signal price.
//  Here it is expressed against the actual short entry price.
// ============================================================
var float entryRef      = na
var int   entryBarIndex = na

// detect the bar we flipped into a short
if strategy.position_size < 0 and (na(strategy.position_size[1]) or strategy.position_size[1] >= 0)
    entryRef      := strategy.position_avg_price
    entryBarIndex := bar_index

barsSinceEntry = na(entryBarIndex) ? na : bar_index - entryBarIndex
midpoint       = (open + close) / 2.0

fastExit = useFastExit and strategy.position_size < 0 and not na(entryRef)
     and barsSinceEntry >= graceFrom and barsSinceEntry <= graceTo
     and midpoint > entryRef

if fastExit
    strategy.close("Short", comment = "Fast Exit")

// ============================================================
//  Visuals
// ============================================================
plotshape(sellcond, style = shape.labeldown, color = color.red, size = size.tiny,
     title = "Sell Signal", location = location.abovebar, text = "SELL")
plot(strategy.position_size < 0 ? entryRef : na, "Short entry ref", color = color.orange, style = plot.style_linebr)

Overview

Sell-Only Strategy triggers short entries when the open RSI exceeds 70 and momentum turns downward alongside a bearish engulfing bar. Exits are managed through a fixed percentage take profit and stop loss, as well as an optional fast midpoint exit mechanism that activates within a specified bar grace window after entry. It plots directly on the main price chart and only executes short positions.

Details

Published by

karma659 on GitHub

Code credit

karmakarakash659, as written in the script's header

Draws

On the price chart

Markets

Crypto

Timeframes

M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoindockerkalshinodejsreactwebsocket

Settings

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

SettingTypeDefaultVariable
Fast midpoint exit (original logic)booltrueuseFastExit
Use fixed Take Profit / Stop LossbooltrueuseTPSL
Take Profit %float1.0tpPerc
Stop Loss %float1.0slPerc
Fast-exit armed from barint3graceFrom
Fast-exit armed until barint7graceTo
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

330 stars

Improvising [Alorse] is a price-chart strategy that looks for a one-bar candle reversal filtered by a 10-period EMA, a 14-period RSI, and a rising or falling MACD. Longs require a bearish bar followed by a bullish close above the EMA, RSI below 65, and a risin

Strategy v5 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of Improvising [Alorse]
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
106 stars

This strategy enters long on an outside bar when the candle is bullish, the Klinger Volume Oscillator is positive, and price is above a Hull moving average. It enters short on an inside bar when the candle is bearish, the oscillator is negative, and price is b

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced OutSide Forex strategy

Stocks - Bullish Engulfing

by LouisLetcher
23 stars

This Pine Script strategy identifies classic bullish engulfing candlestick patterns to open long positions, deploying 100 percent of equity. It calculates a short-term Relative Strength Index to determine exits, closing open long positions when the RSI exceeds

Strategy v6 Candlestick patternsOscillators & momentum
Updated 3 months ago · Custom licence GitHub repository of Stocks - Bullish Engulfing
7 stars

This strategy combines Ichimoku Kinko Hyo components, a Stochastic oscillator, and specific candlestick patterns to generate trade signals. It identifies Kumo twists and range breakouts while evaluating candle body shapes using Fibonacci threshold filters. Tra

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · MIT GitHub repository of Soulevement / Ressaut Strategy

Improvisando [Alorse]

by Hugs-4-Bugs
4 stars

This strategy combines candlestick price action with Exponential Moving Average, RSI, and MACD filters to identify short-term trend trades. A long signal occurs when a bullish candle engulfs the previous open while price remains above the EMA, RSI stays below

Strategy v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Improvisando [Alorse]

More Oscillators & momentum scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers