Strategy · Pine Script v4 · Own pane

Sandwich

by kat3samsin

This strategy identifies sandwich patterns using RSI, ALMA, and Stochastic indicators.

View on GitHub

GitHub stars2on the repository
Pine versionv4older, still runs
Lines of code46
Settings8inputs
LicenceMIT
Last update5 years ago17 Mar 2021

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

46 lines of Pine Script v4 from scripts/sandwich.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

sandwich.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kat3samsin

//@version=4
strategy("Sandwich", overlay=false, process_orders_on_close=true)

//rsi
rsiPeriod = input(14, title="RSI", minval=1)
_rsi = rsi(close, rsiPeriod)

//ALMA
source = close
windowsize = input(title="Window Size", type=input.integer, defval=15)
ALMAoffset = input(title="ALMA Offset", type=input.float, defval=0.85)
sigma = input(title="Sigma", type=input.float, defval=6)
ALMA15 = alma(source, windowsize, ALMAoffset, sigma)

// chop28
chopPeriod = input(28, title="CHOP", minval=1)
ci = 100 * log10(sum(atr(1), chopPeriod) / (highest(chopPeriod) - lowest(chopPeriod))) / log10(chopPeriod)

//stochastics
periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(3, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)

//condition
stochKSandwich = k <= _rsi and k >= ci
stochDSandwich = d <= _rsi and d >= ci
stochIsUp = k > d
sandwichEntry = _rsi > ci and (stochKSandwich and stochDSandwich) and stochIsUp
sandwichExit = close < ALMA15

//entry/exit
strategy.entry(id="SandwichEntry", long = true, qty = strategy.equity/close, when = sandwichEntry)
strategy.close(id="SandwichEntry", when = sandwichExit)

//plots
plotchar(sandwichEntry, "SANDWICH", "🔼", location.top)

plot(_rsi, color=color.green, linewidth=2)
plot(ci, color=color.red, linewidth=2)
plot(k, color=color.blue)
plot(d, color=color.orange)

Overview

Sandwich plots RSI, Choppiness Index (CI), Stochastic K, and D in a separate pane. Long entries trigger when RSI is above CI, both Stochastic lines fall between CI and RSI, and K exceeds D. Position size uses equity divided by close price. Exits occur when close crosses below ALMA15. Settings control periods for RSI, ALMA, CHOP, and Stochastic. It provides entry signals only with no stop loss or take profit.

Details

Published by

kat3samsin on GitHub

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

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
RSIint14rsiPeriod
Window Sizeint15windowsize
ALMA Offsetfloat0.85ALMAoffset
Sigmafloat6sigma
CHOPint28chopPeriod
Kint14periodK
Dint3periodD
Smoothint3smoothK
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

106 stars

This strategy captures strong bullish momentum by combining a 200-period SMA baseline, a custom Bollinger Band, the True Strength Index (TSI) smoothed with WMAs, and the ADX trend strength indicator. It initiates long positions when price is above the 200 SMA,

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of ADX_TSI_Bol Band Trend Chaser

EMA Ribbon MACD

by iamrichardD
57 stars

This strategy combines an EMA ribbon with MACD confirmation and plots in a separate pane. It enters when ribbon alignment, optional MACD zero or signal crosses, volume, smart-money, and multi-timeframe filters agree, then exits with percentage stop loss and ta

Strategy v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon MACD
25 stars

This Pine Script strategy calculates Bayesian probabilities of price breaking up or down relative to Bollinger Bands and a Simple Moving Average. It plots these breakout and breakdown probability lines as oscillators in a separate pane. Long entries trigger wh

Strategy v4 Oscillators & momentumVolatility & bands
Updated 6 years ago · None stated GitHub repository of Bayesian BBSMA Oscillator Strategy

Greeffer BB Strategy

by SammyEnigma
18 stars

This strategy combines Bollinger Bands, Bollinger Band Width, and the Relative Strength Index (RSI) for mean-reversion trades. It enters long when price crosses below the lower band with oversold RSI, or when band width contracts under low volatility. Short en

Strategy v4 Mean reversionOscillators & momentum
Updated 6 years ago · None stated GitHub repository of Greeffer BB Strategy

AwesomeADX

by koradiyakaushal
12 stars

AwesomeADX is a Pine Script v4 strategy that combines an Awesome Oscillator, ADX directional movement, and Bollinger percent B with an optional four-length moving-average trend filter. It sizes each position as a percentage of equity and can limit trades to a

Strategy v4 Oscillators & momentumMoving averages
Updated 5 years ago · MIT GitHub repository of AwesomeADX

Alper

by avatar-lavventura
2 stars

Alper is a multi-indicator trading strategy combining a WaveTrend oscillator, RSI, and Squeeze Momentum logic based on Bollinger Bands and Keltner Channels. Operating within a user-defined backtest time window, it plots WaveTrend lines, overbought and oversold

Strategy v4 Oscillators & momentumVolatility & bands
Updated 7 months ago · None stated GitHub repository of Alper

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