Strategy · Pine Script v5 · On the chart

MomGulfing

by rasimandiran

MomGulfing is a momentum strategy that identifies trade setups using multi-bar engulfing candlestick patterns paired with volume confirmation.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code102
Settings15inputs
LicenceMIT
Last update4 years ago13 Feb 2022

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

102 lines of Pine Script v5 from momgulfing.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

momgulfing.pine
//@version=5
strategy(title = "MomGulfing", shorttitle = "MomGulfing", overlay = true, initial_capital=10000, pyramiding=3, calc_on_order_fills=false, calc_on_every_tick=false, currency="USD", default_qty_type=strategy.cash, default_qty_value=1000, commission_type=strategy.commission.percent, commission_value=0.04)

syear = input(2021)
smonth = input(1)
sday = input(1)
fyear = input(2022)
fmonth = input(12)
fday = input(31)
start = timestamp(syear, smonth, sday, 01, 00)
finish = timestamp(fyear, fmonth, fday, 23, 59)
date = time >= start and time <= finish ? true : false

longs = input(true)
shorts = input(true)
rr = input(2.5)
position_risk_percent = input(1)/100
signal_bar_check = input.string(defval="3", options=["1", "2", "3"])
margin_req = input(80)
sl_increase_factor = input(0.2)
tp_decrease_factor = input(0.0)
check_for_volume = input(true)
var long_sl = 0.0
var long_tp = 0.0
var short_sl = 0.0
var short_tp = 0.0
var long_lev = 0.0
var short_lev = 0.0

initial_capital = strategy.equity
position_risk = initial_capital * position_risk_percent

bullishEngulfing_st = close[1] < open[1] and close > open and high[1] < close and (check_for_volume ? volume[1]<volume : true)
bullishEngulfing_nd = close[2] < open[2] and close[1] > open[1] and close > open and high[2] > close[1] and high[2] < close and (check_for_volume ? volume[2]<volume : true)
bullishEngulfing_rd = close[3] < open[3] and close[2] > open[2] and close[1] > open[1] and close > open and high[3] > close[2] and high[3] > close[1] and high[3] < close and (check_for_volume ? volume[3]<volume : true)
bullishEngulfing = signal_bar_check == "1" ? bullishEngulfing_st : signal_bar_check == "2" ? bullishEngulfing_st or bullishEngulfing_nd : bullishEngulfing_st or bullishEngulfing_nd or bullishEngulfing_rd
long_stop_level = bullishEngulfing_st ? math.min(low[1], low) : bullishEngulfing_nd ? math.min(low[2], low[1], low) : bullishEngulfing_rd ? math.min(low[3], low[2], low[1], low) : na
rr_amount_long = close-long_stop_level
long_exit_level = close + rr*rr_amount_long
long_leverage = math.floor(margin_req/math.floor((rr_amount_long/close)*100))

bearishEngulfing_st = close[1] > open[1] and close < open and low[1] > close and (check_for_volume ? volume[1]<volume : true)
bearishEngulfing_nd = close[2] > open[2] and close[1] < open[1] and close < open and low[2] < close[1] and low[2] > close and (check_for_volume ? volume[2]<volume : true)
bearishEngulfing_rd = close[3] > open[3] and close[2] < open[2] and close[1] < open[1] and close < open and low[3] < close[2] and low[3] < close[1] and low[3] > close and (check_for_volume ? volume[3]<volume : true)
bearishEngulfing = signal_bar_check == "1" ? bearishEngulfing_st : signal_bar_check == "2" ? bearishEngulfing_st or bearishEngulfing_nd : bearishEngulfing_st or bearishEngulfing_nd or bearishEngulfing_rd
short_stop_level = bearishEngulfing_st ? math.max(high[1], high) : bearishEngulfing_nd ? math.max(high[2], high[1], high) : bearishEngulfing_rd ? math.max(high[3], high[2], high[1], high) : na
rr_amount_short = short_stop_level-close
short_exit_level = close - rr*rr_amount_short
short_leverage = math.floor(margin_req/math.floor((rr_amount_short/short_stop_level)*100))

long = longs and date and bullishEngulfing
short = shorts and date and bearishEngulfing
bgcolor(long[1] ? color.new(color.teal, 80) : (short[1] ? color.new(color.purple, 80) : na))

if long and strategy.position_size <= 0
    long_lev := long_leverage

if short and strategy.position_size >= 0
    short_lev := short_leverage

long_pos_size = long_lev * position_risk
long_pos_qty = long_pos_size/close
short_pos_size = short_lev * position_risk
short_pos_qty = short_pos_size/close

if long
    if strategy.position_size <= 0
        long_sl := long_stop_level
        long_tp := long_exit_level

    else if strategy.position_size > 0
        long_sl := long_stop_level + sl_increase_factor*rr_amount_long
        long_tp := long_exit_level - tp_decrease_factor*rr_amount_long

    strategy.entry("L"+str.tostring(long_lev)+"X", strategy.long, qty=long_pos_qty)
    label_text = str.tostring(long_lev)+"X\nSL:"+str.tostring(long_sl)+"\nTP:"+str.tostring(long_tp)
    label.new(bar_index+1, na, text=label_text, color=color.green, style=label.style_label_up, xloc=xloc.bar_index, yloc=yloc.belowbar)

else if short
    if strategy.position_size >= 0
        short_sl := short_stop_level
        short_tp := short_exit_level

    else if strategy.position_size < 0
        short_sl := short_stop_level - sl_increase_factor*rr_amount_short
        short_tp := short_exit_level + tp_decrease_factor*rr_amount_short

    strategy.entry("S"+str.tostring(short_lev)+"X", strategy.short, qty=short_pos_qty)
    label_text = str.tostring(short_lev)+"X\nSL:"+str.tostring(short_sl)+"\nTP:"+str.tostring(short_tp)
    label.new(bar_index+1, na, text=label_text, color=color.red, style=label.style_label_down, xloc=xloc.bar_index, yloc=yloc.abovebar)

if (strategy.position_size > 0)
    strategy.exit(id="L TP/SL", stop=long_sl, limit=long_tp)

if (strategy.position_size < 0)
    strategy.exit(id="S TP/SL", stop=short_sl, limit=short_tp)

sl_level = strategy.position_size > 0 ? long_sl : strategy.position_size < 0 ? short_sl : na
plot(sl_level, color=color.red, style=plot.style_linebr)

tp_level = strategy.position_size > 0 ? long_tp : strategy.position_size < 0 ? short_tp : na
plot(tp_level, color=color.green, style=plot.style_linebr)

Overview

MomGulfing triggers long or short entries when price breaks key candle bounds across one to three bars while volume expands. The strategy establishes a dynamic stop loss at the pattern's price extreme and sets a take profit based on a customizable risk-reward ratio. User settings control pattern lookback depth, volume filters, risk percentage per position, and backtesting date windows. Signals highlight background chart colors directly on the price pane.

Details

Published by

rasimandiran on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, Oscillators & momentum, Volume

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction

Topics

tradingtrading-strategiestrading-algorithmstradingview-pine-scriptsmomentum-trading-strategycandlestick-patterns

Settings

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

SettingTypeDefaultVariable
syearint2021syear
smonthint1smonth
sdayint1sday
fyearint2022fyear
fmonthint12fmonth
fdayint31fday
longsbooltruelongs
shortsbooltrueshorts
rrfloat2.5rr
position_risk_percentint1position_risk_percent
signal_bar_checkstring3signal_bar_check
margin_reqint80margin_req
Show all 15 settings
SettingTypeDefaultVariable
sl_increase_factorfloat0.2sl_increase_factor
tp_decrease_factorfloat0.0tp_decrease_factor
check_for_volumebooltruecheck_for_volume
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 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

Volume Spike Reversal

by Basant1Saini
1 stars

The Volume Spike Reversal strategy identifies potential price reversals driven by high volume activity. It triggers long entries when a volume spike occurs while price is below a 20-period simple moving average, combined with oversold RSI readings and bullish

Strategy v5 VolumeOscillators & momentum
Updated 7 months ago · None stated GitHub repository of Volume Spike Reversal
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
105 stars

This overlay strategy looks for gold scalps from break of structure and change of character. It enters long when a bullish break, a bullish character change, and an optional volume filter align, and short on the opposite set. Optional RSI levels can block trad

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints

CombinedBinHAndClucV8

by viktors1982
36 stars

This strategy trades on the price chart using multiple indicators. It enters long positions when price dips meet conditions on Bollinger Bands 40 and 20, RSI, MFI, volume and other thresholds. It exits at custom ROI profit levels based on RSI or after timeout

Strategy v4 Oscillators & momentumMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of CombinedBinHAndClucV8

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