Strategy · Pine Script v4 · Own pane

BBofVWAP with entry at Pivot Point

by hasnocool· code credited to ediks123

This strategy plots a volume-weighted average price, Bollinger Bands built on that VWAP, a 200-period simple moving average, and Fibonacci pivot levels in a separate pane.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code90
Settings7inputs
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

90 lines of Pine Script v4 from BBofVWAP with entry at Pivot Point.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

BBofVWAP with entry at Pivot Point.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ediks123
//@version=4
strategy("BBofVWAP with entry at Pivot Point", overlay=false, pyramiding=1,   default_qty_type=strategy.percent_of_equity,  default_qty_value=20, initial_capital=10000, currency=currency.USD)  //default_qty_value=10, default_qty_type=strategy.fixed,
// Function outputs 1 when it's the first bar of the D/W/M/Y
is_newbar(res) =>
    ch = 0
    if(res == 'Y')
        t  = year(time('D'))
        ch := change(t) != 0 ? 1 : 0
    else
        t = time(res)
        ch := change(t) != 0 ? 1 : 0
    ch
//variables BEGIN
//smaLength=input(200,title="Slow MA Length")
bbLength=input(50,title="BB Length")  
//bbsrc = input(close, title="BB Source")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)
pp_period = input(title = "Pivot Period", type=input.string, defval="Week", options = ['Day', 'Week'])
pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : 'Y' 
riskCapital = input(title="Risk % of capital", defval=10, minval=1)
stopLoss=input(5,title="Stop Loss",minval=1)
partialExitOnIndicator=input(title = "Partial Exit with VWAP or  Fib R3", defval="VWAP_crossunder_upperBB", options = ['VWAP_crossunder_upperBB', 'VWAP_crossover_FibR3','VWAP_crossunder_FibR3'])
sma200=sma(close,200)
plot(sma200, title="SMA 200", color=color.orange)
myVwap=vwap(hlc3)
//weekly vwap
//myVwap=security(syminfo.tickerid, 'W', vwap)
//bollinger calculation
basis = sma(myVwap, bbLength)
dev = mult * stdev(myVwap, bbLength)
upperBand = basis + dev
lowerBand = basis - dev
//plot bb
plot(basis, "Basis", color=color.teal, style=plot.style_circles , offset = offset)
p1 = plot(upperBand, "Upper", color=color.teal, offset = offset)
p2 = plot(lowerBand, "Lower", color=color.teal, offset = offset)
fill(p1, p2, title = "Background", color=color.teal, transp=95)
plot(myVwap, title="VWAP", color=color.purple)
//plot(myVwapW, title="VWAPWeekly", color=color.orange)
//pivot points 
// Calc High
high_cur = 0.0
high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)
phigh = 0.0
phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1]
// Calc Low
low_cur = 0.0
low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)
plow = 0.0
plow := is_newbar(pp_res) ? low_cur[1] : plow[1]
// Calc Close
pclose = 0.0
pclose := is_newbar(pp_res) ? close[1] : pclose[1]
// CALCULATE fibonacci pivots //
vPP = (phigh + plow + pclose) / 3
//vPP = (phigh + plow + pclose) / 3
vR1 = vPP + (phigh - plow) * 0.382
vS1 = vPP - (phigh - plow) * 0.382
vR2 = vPP + (phigh - plow) * 0.618
vS2 = vPP - (phigh - plow) * 0.618
vR3 = vPP + (phigh - plow) * 1.000
vS3 = vPP - (phigh - plow) * 1.000
  
// CALCULATE fibonacci pivots //
//pivot points
//Entry--
//Echeck how many units can be purchased based on risk manage ment and stop loss
qty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  
//check if cash is sufficient  to buy qty1  , if capital not available use the available capital only
qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1
strategy.entry(id="BB_VWAP_PP",long=true, qty=qty1, when=   crossover(myVwap,basis)  and close>=vPP  )
bgcolor(strategy.position_size>=1?color.blue:na, transp=75)
barcolor(strategy.position_size>=1?color.green:na)
stopLossVal=  strategy.position_size>=1 ?  close * (1 - (stopLoss*0.01) ) : 0.00
//partial exit
//strategy.close(id="BBofVwap", qty=strategy.position_size/3, when=crossunder(myVwap,upperBand) and strategy.position_size>=1 )  //and close>strategy.position_avg_price)
//exit on lowerband or stoploss 
if(partialExitOnIndicator=="VWAP_crossunder_upperBB")
    strategy.close(id="BB_VWAP_PP", comment="PExtonVWAP" , qty=strategy.position_size/3, when= crossunder(myVwap,upperBand) and strategy.position_size>=1 and close>strategy.position_avg_price)  //
else if (partialExitOnIndicator=="VWAP_crossover_FibR3")
    strategy.close(id="BB_VWAP_PP", comment="PExtonFibR3" , qty=strategy.position_size/3, when= crossover(myVwap,vR3)  and strategy.position_size>=1 and close>strategy.position_avg_price)  //  or  (close[1]<vR3[1] and close>vR3[1] )
else if (partialExitOnIndicator=="VWAP_crossunder_FibR3")
    strategy.close(id="BB_VWAP_PP", comment="PExtonFibR3" , qty=strategy.position_size/3, when= crossunder(myVwap,vR3) and strategy.position_size>=1 and close>strategy.position_avg_price)  //
strategy.close(id="BB_VWAP_PP", comment="Exit All", when=crossunder(myVwap,lowerBand) and strategy.position_size>=1 )
//strategy.close(id="BBofVwapWithFibPivot", comment="Exit All", when=crossunder(close,vPP) and strategy.position_size>=1 )
strategy.close(id="BB_VWAP_PP", comment="Stop Loss Exit", when=crossunder(close,stopLossVal) and strategy.position_size>=1 )
Expand (128 lines)

Overview

BBofVWAP with entry at Pivot Point opens a long position when VWAP crosses above the band basis and the close is at or above the pivot point. Position size uses a risk percent of equity and a stop-loss percent, capped by available capital. Main settings change band length, deviation, pivot period, risk percent, and the stop-loss percent. The stop is calculated, but no exit order appears in the provided code.

Details

Published by

hasnocool on GitHub

Code credit

ediks123, as written in the script's header

Type

Strategy, Pine Script v4

Draws

Separate pane below the chart

Category

Volatility & bands, Support & resistance, Volume, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

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
BB Lengthint50bbLength
StdDevfloat2.0mult
Offsetint0offset
Pivot PeriodstringWeekpp_period
Risk % of capitalint10riskCapital
Stop Lossint5stopLoss
Partial Exit with VWAP or Fib R3stringVWAP_crossunder_upperBBpartialExitOnIndicator
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

257 stars

This overlay strategy is built for ES futures on the one-minute chart. It plots a volume-weighted moving average of price opens and standard-deviation bands at Fibonacci ratios, plus a second longer volume-weighted average from a higher-timeframe open. Call an

Strategy v5 Volatility & bandsMoving averages
Updated 6 weeks ago · None stated GitHub repository of ES Futures 1M No Repaint

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

KC15

by benso87
24 stars

KC15 is a price-chart strategy that configures two moving averages, a Bollinger Band Width Percentile filter, and PMARP entry and exit thresholds for long and short trades. Users can switch each average between SMA and EMA, set lengths and colors, and toggle l

Strategy v5 Moving averagesVolatility & bands
Updated 4 years ago · MPL-2.0 GitHub repository of KC15

This strategy enters long or short when eight conditions align over the last two bars. It requires EMA 10 and EMA 55 alignment on the one-hour, four-hour and daily charts, a positive ADX slope, matching monitor direction, and price relative to a 400-bar point

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino B002
8 stars

This overlay strategy combines three distinct SuperTrend levels with multiple moving averages and volume profile analytics on the main price chart. It calculates trend directions using three configurable ATR periods and multipliers alongside SMA, EMA, and HMA

Strategy v5 TrendVolatility & bands
Updated 4 years ago · None stated GitHub repository of ATR 3Lvls VP Strategy
7 stars

This strategy plots a customizable Bollinger Band basis using selectable moving average types such as HMA, SMA, EMA, or others. It draws the basis line, multiple standard deviation levels, and fills the region between L1 and L6 on the price chart. Buy signals

Strategy v5 Volatility & bandsMoving averages
Updated 4 months ago · None stated GitHub repository of Bollinger Bands 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