Strategy · Pine Script v5 · On the chart

Advanced VWAP-Momentum Pullback Trend Qualifier

by hasnocool· code credited to JS-TechTrading 2023

This strategy overlays the price chart and looks for VWAP pullbacks.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code233
Settings37inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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

233 lines of Pine Script v5 from Advanced VWAP_Pullback Strategy_Trend-Template Qualifier.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Advanced VWAP_Pullback Strategy_Trend-Template Qualifier.pine
//@version=5
strategy(title='Advanced VWAP-Momentum_Pullback Strategy_Trend-Template Qualifier', initial_capital=100000, pyramiding=0,default_qty_value=100, currency='USD', overlay=true,default_qty_type = strategy.percent_of_equity)
// copyright JS-TechTrading 2023
cb1 = input.bool(title="1. Stock price is above MA 150 and 200 ?" , defval=false)
cb2 = input.bool(title="2. MA 150 is above MA 200 ?", defval=false)
cb3 = input.bool(title="3. MA 200 is trending at least 1 month(22 days) ?", defval=false)
cb4 = input.bool(title="4. MA 50 is above both MA 150 and MA 200 ?", defval=false)
cb5 = input.bool(title="5. The current stock price is trading above MA 50? ", defval=false)
cb6 = input.bool(title="6. Current stock price is 25% above 52 weeks low ?", defval=false)
cb7 = input.bool(title="7. Current Price is within 25% of 52 week high ? ", defval=false)
cb8 = input.bool(title="8. Meet Minervini's Criteria?", defval=false) 
cb9= input.bool(title="9. Enable IBD Qualifier?",defval = false)
ibd_threshhold = input.float(title="IBD RS Threshhold 3Months", defval=0.5,step = 0.1)
//IBD
src = request.security(syminfo.ticker, 'D', close)
mo_3 = 0.4 * (src / src[11]) + 0.2 * (src / src[21]) + 0.2 * (src / src[42]) + 0.2 * (src / src[63])
plot(100 * mo_3, style=plot.style_line, linewidth=1, color=color.new(#1E90FF, 0),display = display.none)
//// Stoploss and Take Profit Parameters
// Enable Long Strategy
////////////
// Date Range
start_date = input.int(title='Start Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
end_date = input.int(title='End Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
start_month = input.int(title='Start Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
end_month = input.int(title='End Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
start_year = input.int(title='Start Year', defval=2000, minval=1800, maxval=3000, group='Date Range', inline='3')
end_year = input.int(title='End Year', defval=2077, minval=1800, maxval=3000, group='Date Range', inline='3')
in_date_range = time >= timestamp(syminfo.timezone, start_year, start_month, start_date, 0, 0) and time < timestamp(syminfo.timezone, end_year, end_month, end_date, 0, 0)
//// Indicator Inputs
// RSI
rsi_over_sold = input.int(defval=30, minval=1, title='Over Sold Level', group='RSI')
rsi_over_bought = input.int(defval=70, minval=1, title='Over Bought Level', group='RSI')
rsi_length = input.int(defval=14, minval=1, title='RSI Length', group='RSI')
rsi = ta.rsi(close, rsi_length)
// MACD
// VWAP
maSource = input(title='SMA source', defval=close,group = "VWAP")
maInterval = input.int(title='SMA interval', minval=0, maxval=999, step=1, defval=7,group = "VWAP")
ma = ta.sma(maSource, maInterval)
//// Strategy
// Creating Long and Short Strategy
was_over_sold = ta.barssince(rsi <= rsi_over_sold) <= 10
was_over_bought = ta.barssince(rsi >= rsi_over_bought) <= 10
crossover_bull = ta.crossover(ma, ta.vwap)
crossover_bear = ta.crossunder(ma, ta.vwap)
/////////////////
sma50 = ta.sma(close, 50)
sma150 = ta.sma(close, 150)
sma200 = ta.sma(close, 200)
sma200_22 = sma200[22]
// 1. stock price is above ma 150 and 200
is_price_above_sma_150_and_200 = close > sma150 and close > sma200 ? true:false
c_1 = is_price_above_sma_150_and_200 ? true : false
// 2. sma 150 is above sma 200
is_sma_150_above_sma_200 = sma150 > sma200 ? true : false
c_2 = is_sma_150_above_sma_200 ? true : false
// 3. sma 200 is trending at least 1 month(22 days)
is_trending_at_least_1_month = sma200 > sma200_22 ? true : false
c_3 = is_trending_at_least_1_month ? true : false
// 4. sma 50 is above both sma 150 and 200
is_sma_50_above_sma_150_and_200 = sma50 > sma150 and sma50 > sma200 ? true : false
c_4 = is_sma_50_above_sma_150_and_200 ? true : false
// 5. current stock price is above sma 50 
is_current_price_above_ma_50 = close > sma50 ? true:false
c_5 = is_current_price_above_ma_50 ? true : false
// 6. current stock price is 25% above 52 weeks low
// Many of the best are up 100-300% before coming out of consolidation
high_loopback = input(260, 'High Lookback Length')
low_loopback = input(260, 'Low Lookback Length')
highest_price = ta.highest(high, high_loopback)
lowest_price = ta.lowest(low, low_loopback)
is_price_25_percent_above_52_weeks_low = (close / lowest_price - 1) * 100 >= 25 ? true : false
c_6 = is_price_25_percent_above_52_weeks_low ? true : false
// Show 52 High / Low Line 
show_52_week_high_low = input(title='Show 52 week highest/lowest', defval=true)
plot(show_52_week_high_low ? highest_price : na, title='52 Week High', trackprice=true, color=color.new(color.orange, 0), offset=-9999)
plot(show_52_week_high_low ? lowest_price : na, title='52 Week Low', trackprice=true, color=color.new(color.orange, 0), offset=-9999)
// 7. Current Price is within 25% of 52 week high
is_price_within_52_high = (1 - close / highest_price) * 100 <= 25 ? true : false
c_7 = is_price_within_52_high ? true : false
// relative strength IBD style
three_month_rs = 0.4 * (close / close[13])
six_month_rs = 0.2 * (close / (close[26] * 2))
nine_month_rs = 0.2 * (close / (close[39] * 3))
twelve_month_rs = 0.2 * (close / (close[52] * 4))
rs_rating = (three_month_rs + six_month_rs + nine_month_rs + twelve_month_rs) * 100
rs_rating_str = str.tostring(rs_rating, '#.00')
is_rs_rating_more_than_seventy = rs_rating > 70
//c_8 = is_rs_rating_more_than_seventy ? 1 : 0
is_meet_all_criteria = is_price_above_sma_150_and_200 and is_sma_150_above_sma_200 and is_trending_at_least_1_month and is_sma_50_above_sma_150_and_200 and is_price_25_percent_above_52_weeks_low and is_price_within_52_high and is_current_price_above_ma_50 and mo_3>=ibd_threshhold
//count = c_1 + c_2 + c_3 + c_4 + c_5 + c_6 + c_7 
//
//selection
allConditionTrue = true
if (cb1 == true) 
    if (allConditionTrue==true and is_price_above_sma_150_and_200==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb2 == true) 
    if (allConditionTrue==true and is_sma_150_above_sma_200==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb3 == true) 
    if (allConditionTrue==true and is_trending_at_least_1_month==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb4 == true) 
    if (allConditionTrue==true and is_sma_50_above_sma_150_and_200==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb5 == true) 
    if (allConditionTrue==true and is_current_price_above_ma_50==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb6 == true) 
    if (allConditionTrue==true and is_price_25_percent_above_52_weeks_low==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb7 == true) 
    if (allConditionTrue==true and is_price_within_52_high==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb8 == true) 
    if (allConditionTrue==true and is_meet_all_criteria==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
if (cb9 == true) 
    if (allConditionTrue==true and mo_3>=ibd_threshhold==true)
        allConditionTrue := true
    else 
        allConditionTrue := false
//
label1=cb1==true?'1. Stock price is above MA 150 and 200 ? ' + (is_price_above_sma_150_and_200 ? 'yes' : 'no') + '\n' : na
label2=cb2==true?'2. MA 150 is above MA 200 ? ' + (is_sma_150_above_sma_200 ? 'yes' : 'no') + '\n':na
label3=cb3==true?'3. MA 200 is trending at least 1 month(22 days) ? ' + (is_trending_at_least_1_month ? 'yes' : 'no') + '\n':na 
label4=cb4==true?'4. MA 50 is above both MA 150 and MA 200 ? ' + (is_sma_50_above_sma_150_and_200 ? 'yes' : 'no') + '\n':na
label5=cb5==true?'5. The current stock price is trading above MA 50? ' + (is_current_price_above_ma_50 ? 'yes' : 'no') + '\n':na
label6=cb6==true?'6. Current stock price is 25% above 52 weeks low ? ' + (is_price_25_percent_above_52_weeks_low ? 'yes' : 'no') + '\n':na
label7=cb7==true?'7. Current Price is within 25% of 52 week high ? ' + (is_price_within_52_high ? 'yes' : 'no') + '\n':na
label8=cb8==true?'8. Meet Minervini Criteria? ' + (is_meet_all_criteria ? 'yes' : 'no') + '\n':na
label9=cb9==true?('9.IBD Qualifier? Enabled') + " "+ (mo_3>=ibd_threshhold?"IBD Mathed":"IBD not matched") +" " + str.tostring(mo_3) : na
text_ = ""
text_ += 'Minervinis Strategy' + '\n'
text_ += '˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭˭' + '\n'
text_ += 'Selected qualifiers are as below:' + '\n'+ '\n'
text_ += label1
text_ += label2
text_ += label3
text_ += label4
text_ += label5
text_ += label6
text_ += label7
text_ += label8
text_ += label9
///////
bars_right = input(5, 'x bars right')
position = input(close, 'Label position')
one_color = input(false, 'Label only in one color')
lab_color = input(#ffd700, 'Label color')
t = timenow + math.round(ta.change(time) * bars_right)
var label lab = na
label.delete(lab)
lab := label.new(t, position, text=text_, style=label.style_label_left, yloc=yloc.price, xloc=xloc.bar_time, textalign=text.align_left, color=#ffd700, textcolor=color.black)
//////////////////////////////////
fastExit = input(false, title='Close Trade when opposite trading signal is triggered')
clrBars = input(false, title='Mark candles according to order status')
orderType = input.string('Only Long', title='Long/Short Strategy', options=['Long & Short', 'Only Long', 'Only Short', 'Flip'])
//
buy_signal = orderType=='Flip'?was_over_bought and crossover_bear :was_over_sold and crossover_bull 
sell_signal = orderType=='Flip'?was_over_sold and crossover_bull :was_over_bought and crossover_bear
//
//enable_long_strategy = input.bool(true, title='Enable Long Strategy', group='SL/TP für Long Strategie', inline='1')
//enable_short_strategy = input.bool(false, title='Enable Short Strategy', group='SL/TP For Short Strategy', inline='3')
//lpp = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=5, group='SL/TP für Long Strategie', inline='2') / 100
AQUA = #00FFFFFF
BLUE = #0000FFFF
RED = #FF0000FF
LIME = #00FF00FF
GRAY = #808080FF
DARKRED = #8B0000FF
DARKGREEN = #006400FF
bclr = not clrBars ? na : strategy.position_size==0 ? GRAY : ta.change(strategy.position_size) and strategy.position_size>0 ? DARKGREEN : strategy.position_size>0? LIME : ta.change(strategy.position_size) and strategy.position_size<0 ?  DARKRED : strategy.position_size<0 ?RED : GRAY
barcolor(bclr, title='Trade State Bar Colouring')
//lsl = input.float(title="Long Stop Loss (%)", minval=0.0, step=0.1, defval=5, group='SL/TP für Long Strategie', inline='2') / 100
isS = input(false, 'Stop Loss Enable')
slv = input.float(defval=5, title='Stop Loss (%)', minval=0, step=0.1)/100
// Enable Short Strategy
isTS = input(false, 'Trailing Stop Loss Enable')
trailPerc=input.float(title='Trailing Stop Loss (%)', minval=0.0, step=0.1, defval=2) * 0.01
isTP = input(false, 'Take Profit Enable')
tpv = input.float(defval=5, title='Take Profit %', minval=0, step=0.1)/100
// Plot Stoploss & Take Profit Levels
long_stoploss_price = strategy.position_avg_price * (1 - slv )
long_takeprofit_price = strategy.position_avg_price * (1 +  tpv)
short_stoploss_price = strategy.position_avg_price * (1 + slv)
short_takeprofit_price = strategy.position_avg_price * (1 - tpv)
// Long Strategy
if strategy.equity > 0 and (fastExit==false?strategy.position_size ==0:true) and buy_signal and in_date_range and allConditionTrue==true and (orderType=="Only Long" or orderType=='Long & Short' or orderType=='Flip')
    strategy.entry('Long', strategy.long, alert_message='Open Long Position')
longStopPrice = 0.0
longStopPrice := if strategy.position_size>0
    stopValue = high * (1 - trailPerc)
    math.max(stopValue, longStopPrice[1])
else
    0
if strategy.position_size>0
    strategy.exit("LEx","Long",limit = (isTP?long_takeprofit_price:na),stop = isTS?longStopPrice:(isS?long_stoploss_price:na),alert_message='Close Long Position')
// Short Strategy
if strategy.equity > 0 and (fastExit==false?strategy.position_size ==0:true) and sell_signal and in_date_range and (orderType=="Short" or orderType=='Long & Short' or orderType=='Flip')
    strategy.entry('Short', strategy.short, alert_message='Open Short Position')
shortStopPrice = 0.0
shortStopPrice := if strategy.position_size<0
    stopValue = low * (1 + trailPerc)
    math.min(stopValue, shortStopPrice[1])
else
    9999
if strategy.position_size<0 
    strategy.exit('SEx',"Short", limit =(isTP?short_takeprofit_price:na) ,stop = isTS?shortStopPrice:(isS?short_stoploss_price:na), alert_message='Your Short SL/TP Limit As Been Triggered.')
plot(strategy.position_size > 0  and isTS==true?longStopPrice:na,"Long Trailing SL",color=color.red,style = plot.style_linebr)
plot(strategy.position_size < 0  and isTS==true?shortStopPrice:na,"Short Trailing SL",color=color.red,style = plot.style_linebr)
plot(strategy.position_size > 0  and isTS==false?long_stoploss_price:na,"Long SL",color=color.red,style = plot.style_linebr)
plot(strategy.position_size < 0  and isTS==false?short_stoploss_price:na,"Short SL",color=color.red,style = plot.style_linebr)
plot(strategy.position_size > 0  ?long_takeprofit_price:na,"Long TP",color=color.green,style = plot.style_linebr)
plot(strategy.position_size < 0  ?short_takeprofit_price:na,"Short TP",color=color.green,style = plot.style_linebr)
Expand (306 lines)

Overview

Advanced VWAP-Momentum Pullback Trend Qualifier goes long when a short SMA crosses above VWAP after RSI has been oversold within ten bars, and short on the opposite cross after RSI has been overbought. Optional Minervini-style moving-average checks, a 52-week high and low filter, and an IBD-style daily relative-strength threshold can block trades. A date window limits when orders are allowed. An optional setting closes a trade when the opposite signal appears. No stop-loss or take-profit inputs are shown, and size defaults to full equity.

Details

Published by

hasnocool on GitHub

Code credit

JS-TechTrading 2023, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages, Support & resistance

Markets

Stocks

Timeframes

H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
1. Stock price is above MA 150 and 200 ?boolfalsecb1
2. MA 150 is above MA 200 ?boolfalsecb2
3. MA 200 is trending at least 1 month(22 days) ?boolfalsecb3
4. MA 50 is above both MA 150 and MA 200 ?boolfalsecb4
5. The current stock price is trading above MA 50? boolfalsecb5
6. Current stock price is 25% above 52 weeks low ?boolfalsecb6
7. Current Price is within 25% of 52 week high ? boolfalsecb7
8. Meet Minervini's Criteria?boolfalsecb8
9. Enable IBD Qualifier?boolfalsecb9
IBD RS Threshhold 3Monthsfloat0.5ibd_threshhold
Start Dateint1start_date
End Dateint1end_date
Show all 37 settings
SettingTypeDefaultVariable
Start Monthint1start_month
End Monthint1end_month
Start Yearint2000start_year
End Yearint2077end_year
Over Sold Levelint30rsi_over_sold
Over Bought Levelint70rsi_over_bought
RSI Lengthint14rsi_length
SMA sourcesourceclosemaSource
SMA intervalint7maInterval
High Lookback Lengthint260high_loopback
Low Lookback Lengthint260low_loopback
Show 52 week highest/lowestbooltrueshow_52_week_high_low
x bars rightint5bars_right
Label positionsourcecloseposition
Label only in one colorboolfalseone_color
Label colorcolor#ffd700lab_color
Close Trade when opposite trading signal is triggeredboolfalsefastExit
Mark candles according to order statusboolfalseclrBars
Long/Short StrategystringOnly LongorderType
Stop Loss EnableboolfalseisS
Stop Loss (%)float5slv
Trailing Stop Loss EnableboolfalseisTS
Trailing Stop Loss (%)float2trailPerc
Take Profit EnableboolfalseisTP
Take Profit %float5tpv
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

This strategy trades 1-minute futures contracts on Binance. It plots pivot high and low resistance and support levels on the price chart, along with an EMA and a custom Cto indicator. Long and short entries trigger on EMA and Cto crossovers combined with price

Strategy v5 TrendMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of Binancash Futures Strategy 1M Candles

Optimizer v1

by QuantGeekDev
7 stars

This strategy generates long signals on the price chart using multiple technical indicators. It computes EMA 70 and 100, SMA 70, ADX with DMI, CCI, and MACD values. A long entry occurs when EMA crossover condition, SMA condition, ADX above 15, CCI above 30, an

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · None stated GitHub repository of Optimizer v1

This strategy combines MACD momentum signals with support and resistance levels from pivot points and an EMA100 trend filter for long positions. It plots the 100-period EMA on the price chart and signals when price breaks above the EMA or forms bullish pivot p

Strategy v4 TrendOscillators & momentum
Updated 3 years ago · Apache-2.0 GitHub repository of MACD + Support / Resistance Long Strategy

This overlay strategy combines swing price structure with MACD structure and two higher-timeframe exponential moving averages. It finds pivot highs and lows over ten bars, labels higher highs, lower highs, higher lows and lower lows, and builds matching states

Strategy v5 TrendOscillators & momentum Repaints
Updated 5 months ago · None stated GitHub repository of Price Action Candles with MACD Signals Strategy

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