Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

BBofVWAP with entry at Pivot Point

A Pine Script v4 strategy built on Change (t), SMA (close, 200) and VWAP (hlc3). It has 6 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 20% of equity and pays no commission. 7 settings; defaults include BB Length 50, StdDev 2.0 and Offset 0.

Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.

Does BBofVWAP with entry at Pivot Point repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did BBofVWAP with entry at Pivot Point do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings; it opened a long position that was still open on the last bar, so there is no result to report. On ETHUSDT 1D it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
Can BBofVWAP with entry at Pivot Point be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does BBofVWAP with entry at Pivot Point use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does BBofVWAP with entry at Pivot Point run in Zeal Terminal?
Yes
It compiles in 43 ms and runs 1,000 bars in 74 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA 200
  • Basis
  • Upper
  • Lower
  • VWAP
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctSMA 200$12,985$20,253Equity from $10,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots. Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 74) so the engine trades the way the script says.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
24.89%
−$2,488.72

One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.

Review

What a careful reader of this script would point out, found by checking the source and the backtest.

  • Likely bug

    sma(close, 200) ignores the settings line 26

    Line 26 hard-codes 200 where line 32 uses “BB Length”. Changing those settings moves one band but not this one.

    sma(close,200)sma(close, bbLength)
  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses an argument v6 removed

    when = on line 74, 82, 84, 86, 87, 89. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 40

    transp = on line 40, 75. v5 folds the transparency into the colour with color.new(c, transp).

  • Note

    Uses long =, which v5 renamed line 74

    long = on line 74. v5 writes it as direction = strategy.long or strategy.short.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames change → ta.change, sma → ta.sma, vwap → ta.vwap, stdev → ta.stdev, max → math.max, min → math.min, crossover → ta.crossover, crossunder → ta.crossunder.
  • 6 strategy calls use the when = argument (line 74, 82, 84, 86, 87, 89). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 7 trades and the same P&L on ETHUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 10: change → ta.change
  • Line 13: change → ta.change
  • Line 20: input(type = input.integer) → input.int()
  • Line 21: input(type = input.string) → input.string()
  • Line 26: sma → ta.sma
14 more edits
  • Line 28: vwap → ta.vwap
  • Line 32: sma → ta.sma
  • Line 33: stdev → ta.stdev
  • Line 40: transp = 95 → color.new(color.teal, 95)
  • Line 46: max → math.max
  • Line 51: min → math.min
  • Line 74: long = true → direction = strategy.long
  • Line 74: crossover → ta.crossover
  • Line 75: transp = 75 → color.new(strategy.position_size>=1?color.blue:na, 75)
  • Line 82: crossunder → ta.crossunder
  • Line 84: crossover → ta.crossover
  • Line 86: crossunder → ta.crossunder
  • Line 87: crossunder → ta.crossunder
  • Line 89: crossunder → ta.crossunder
⋯// © ediks123-//@version=4+//@version=5strategy("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,⋯        t  = year(time('D'))-        ch := change(t) != 0 ? 1 : 0+        ch := ta.change(t) != 0 ? 1 : 0    else        t = time(res)-        ch := change(t) != 0 ? 1 : 0+        ch := ta.change(t) != 0 ? 1 : 0    ch⋯mult = input(2.0, minval=0.001, maxval=50, title="StdDev")-offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)+offset = input.int(0, "Offset", minval = -500, maxval = 500)-pp_period = input(title = "Pivot Period", type=input.string, defval="Week", options = ['Day', 'Week'])+pp_period = input.string(title = "Pivot Period", defval="Week", options = ['Day', 'Week'])pp_res = pp_period == 'Day' ? 'D' : pp_period == 'Week' ? 'W' : pp_period == 'Month' ? 'M' : 'Y' ⋯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)+sma200=ta.sma(close,200)plot(sma200, title="SMA 200", color=color.orange)-myVwap=vwap(hlc3)+myVwap=ta.vwap(hlc3)//weekly vwap⋯//bollinger calculation-basis = sma(myVwap, bbLength)+basis = ta.sma(myVwap, bbLength)-dev = mult * stdev(myVwap, bbLength)+dev = mult * ta.stdev(myVwap, bbLength)upperBand = basis + dev⋯p2 = plot(lowerBand, "Lower", color=color.teal, offset = offset)-fill(p1, p2, title = "Background", color=color.teal, transp=95)+fill(p1, p2, title = "Background", color=color.new(color.teal, 95))plot(myVwap, title="VWAP", color=color.purple)⋯high_cur = 0.0-high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)+high_cur := is_newbar(pp_res) ? high : math.max(high_cur[1], high)phigh = 0.0⋯low_cur = 0.0-low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)+low_cur := is_newbar(pp_res) ? low : math.min(low_cur[1], low)plow = 0.0⋯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  )+strategy.entry(id="BB_VWAP_PP",direction = strategy.long, qty=qty1, when=   ta.crossover(myVwap,basis)  and close>=vPP  )-bgcolor(strategy.position_size>=1?color.blue:na, transp=75)+bgcolor(color.new(strategy.position_size>=1?color.blue:na, 75))barcolor(strategy.position_size>=1?color.green:na)⋯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)  //+    strategy.close(id="BB_VWAP_PP", comment="PExtonVWAP" , qty=strategy.position_size/3, when= ta.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] )+    strategy.close(id="BB_VWAP_PP", comment="PExtonFibR3" , qty=strategy.position_size/3, when= ta.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="PExtonFibR3" , qty=strategy.position_size/3, when= ta.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="BB_VWAP_PP", comment="Exit All", when=ta.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 )+strategy.close(id="BB_VWAP_PP", comment="Stop Loss Exit", when=ta.crossunder(close,stopLossVal) and strategy.position_size>=1 )

Clean v5

VerifiedDownload the v5 script

Same 7 trades and the same P&L on ETHUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 17: input() → input.int()
  • Line 19: input() → input.float()
  • Line 23: input() → input.int()
  • Line 24: input() → input.int()
  • Line 25: input() → input.string()
  • Line 74: when = ta.crossover(myVwap,basis) and close>=vPP → if block
5 more edits
  • Line 82: when = ta.crossunder(myVwap,upperBand) and strategy.position_size>=1 and close>strategy.position_avg_price → if block
  • Line 84: when = ta.crossover(myVwap,vR3) and strategy.position_size>=1 and close>strategy.position_avg_price → if block
  • Line 86: when = ta.crossunder(myVwap,vR3) and strategy.position_size>=1 and close>strategy.position_avg_price → if block
  • Line 87: when = ta.crossunder(myVwap,lowerBand) and strategy.position_size>=1 → if block
  • Line 89: when = ta.crossunder(close,stopLossVal) and strategy.position_size>=1 → if block
⋯//smaLength=input(200,title="Slow MA Length")-bbLength=input(50,title="BB Length")  +bbLength=input.int(50,title="BB Length")  //bbsrc = input(close, title="BB Source")-mult = input(2.0, minval=0.001, maxval=50, title="StdDev")+mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")offset = input.int(0, "Offset", minval = -500, maxval = 500)⋯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)+riskCapital = input.int(title="Risk % of capital", defval=10, minval=1)-stopLoss=input(5,title="Stop Loss",minval=1)+stopLoss=input.int(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'])+partialExitOnIndicator=input.string(title = "Partial Exit with VWAP or  Fib R3", defval="VWAP_crossunder_upperBB", options = ['VWAP_crossunder_upperBB', 'VWAP_crossover_FibR3','VWAP_crossunder_FibR3'])sma200=ta.sma(close,200)⋯qty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1-strategy.entry(id="BB_VWAP_PP",direction = strategy.long, qty=qty1, when=   ta.crossover(myVwap,basis)  and close>=vPP  )+if ta.crossover(myVwap,basis)  and close>=vPP+    strategy.entry(id="BB_VWAP_PP",direction = strategy.long, qty=qty1  )bgcolor(color.new(strategy.position_size>=1?color.blue:na, 75))⋯if(partialExitOnIndicator=="VWAP_crossunder_upperBB")-    strategy.close(id="BB_VWAP_PP", comment="PExtonVWAP" , qty=strategy.position_size/3, when= ta.crossunder(myVwap,upperBand) and strategy.position_size>=1 and close>strategy.position_avg_price)  //+    if ta.crossunder(myVwap,upperBand) and strategy.position_size>=1 and close>strategy.position_avg_price+        strategy.close(id="BB_VWAP_PP", comment="PExtonVWAP" , qty=strategy.position_size/3)  //else if (partialExitOnIndicator=="VWAP_crossover_FibR3")-    strategy.close(id="BB_VWAP_PP", comment="PExtonFibR3" , qty=strategy.position_size/3, when= ta.crossover(myVwap,vR3)  and strategy.position_size>=1 and close>strategy.position_avg_price)  //  or  (close[1]<vR3[1] and close>vR3[1] )+    if ta.crossover(myVwap,vR3)  and strategy.position_size>=1 and close>strategy.position_avg_price+        strategy.close(id="BB_VWAP_PP", comment="PExtonFibR3" , qty=strategy.position_size/3)  //  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= ta.crossunder(myVwap,vR3) and strategy.position_size>=1 and close>strategy.position_avg_price)  //+    if ta.crossunder(myVwap,vR3) and strategy.position_size>=1 and close>strategy.position_avg_price+        strategy.close(id="BB_VWAP_PP", comment="PExtonFibR3" , qty=strategy.position_size/3)  //-strategy.close(id="BB_VWAP_PP", comment="Exit All", when=ta.crossunder(myVwap,lowerBand) and strategy.position_size>=1 )+if ta.crossunder(myVwap,lowerBand) and strategy.position_size>=1+    strategy.close(id="BB_VWAP_PP", comment="Exit All" )//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=ta.crossunder(close,stopLossVal) and strategy.position_size>=1 )+if ta.crossunder(close,stopLossVal) and strategy.position_size>=1+    strategy.close(id="BB_VWAP_PP", comment="Stop Loss Exit" )

Does it run in Pine Script v6?

No

The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 7 before, 5 after on ETHUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © ediks123-//@version=5+//@version=6strategy("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,⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
BB Length50intbasis dev
StdDev2.0float · min 0.001 · max 50dev
Offset0int (written input.integer) · min -500 · max 500Upper Lower Basis
Pivot PeriodWeekstring · options ['Day', 'Week']pp_res
Risk % of capital10int · min 1qty1
Stop Loss5int · min 1qty1 stopLossVal
Partial Exit with VWAP or Fib R3VWAP_crossunder_upperBBstring · options ['VWAP_crossunder_upperBB', 'VWAP_crossover_FibR3','VWAP_crossunder_FibR3']close BB_VWAP_PP close BB_VWAP_PP close BB_VWAP_PP line 81 line 83 line 85

What it calculates

  • Change (change, ta.change in v5)tch · line 10
  • SMA (sma, ta.sma in v5)close, 200sma200 · line 26
  • VWAP (vwap, ta.vwap in v5)hlc3myVwap · line 28
  • SMA (sma, ta.sma in v5)myVwap, BB Length (50)basis · line 32
  • Stdev (stdev, ta.stdev in v5)myVwap, BB Length (50)dev · line 33

Signal flow

How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.

closecloseprice datahlc3hlc3price datahlc3 · volumehlc3 · volumeprice databbLengthBB Lengthsetting · 50multStdDevsetting · 2.0pp_periodPivot Periodsetting · Weekhighhighprice datalowlowprice datariskCapitalRisk % of capitalsetting · 10stopLossStop Losssetting · 5chChange→ chsma200SMA→ sma200myVwapVWAP→ myVwapbasisSMA→ basisdevStdev→ devttvaluepp_respp_resvalueupperBand, lowerBandupperBand · lowerBand2 valueshigh_curhigh_curvaluephighphighvaluelow_curlow_curvalueplowplowvaluepclosepclosevaluevPPvPPvaluevR1, vS1, vR2, vS2, vR3, vS3vR1 · vS1 +46 valuesqty1qty1valuestopLossValstopLossValvalueentry:BB_VWAP_PPOpen BB_VWAP_PPstrategy.entryclose:BB_VWAP_PPClose BB_VWAP_PPstrategy.closeplot:27SMA 200plotplot:37Basisplotplot:38Upperplotplot:39Lowerplotfill:BackgroundBackgroundfillplot:41VWAPplotbgcolor:75bgcolorbgcolorbarcolor:76barcolorbarcolor

Order rules

OrderFires whenBy defaultLine
Open BB_VWAP_PP longcrossover(myVwap,basis) and close>=vPPOn74
Close BB_VWAP_PPcrossunder(myVwap,upperBand) and strategy.position_size>=1 and close>strategy.position_avg_priceOn82
Close BB_VWAP_PPcrossover(myVwap,vR3) and strategy.position_size>=1 and close>strategy.position_avg_priceOn84
Close BB_VWAP_PPcrossunder(myVwap,vR3) and strategy.position_size>=1 and close>strategy.position_avg_priceOn86
Close BB_VWAP_PPcrossunder(myVwap,lowerBand) and strategy.position_size>=1On87
Close BB_VWAP_PPcrossunder(close,stopLossVal) and strategy.position_size>=1On89

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Does it repaint?

No

No repainting patterns in the source.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
  • ClearFuture-bar referencesNo negative history offsets such as close[-1].
  • ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
  • ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.

The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.

Other markets

The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D0.0%+102.5%00%—24.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—25.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−30.0%+9.8%757%0.2847.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+11.3%+8.4%978%1.989.8%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+22.7%+16.7%2286%1.4636.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+38.4%+21.5%1486%6.927.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−28.1%+148.3%1776%0.4545.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+4.6%+17.1%1486%1.4410.3%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
BBofVWAP with entry at Pivot Point this page—v4 strategy0.0%024.9%
VWAP and BB strategy [EEMANI] by mohaneevwap sma stdevv4 strategyNo trades on this market
Buying Selling Volume Strategy by exlux99vwap sma stdevv5 strategyNo trades on this market
Long only strategy VWAP with BB and Golden Cross EMA50-200 by SoftKill21vwap sma stdevv4 strategyNo trades on this market
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99sma stdevv4 strategy−20.4%722.3%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 43 msWith a workaround 1,000 bars in 74 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 74) so the engine trades the way the script says.

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report. PineTS runs Pine Script v5 and v6 only.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © ediks123//@version=4strategy("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/Yis_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 calculationbasis = sma(myVwap, bbLength)dev = mult * stdev(myVwap, bbLength)upperBand = basis + devlowerBand = basis - dev//plot bbplot(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 Highhigh_cur = 0.0high_cur := is_newbar(pp_res) ? high : max(high_cur[1], high)phigh = 0.0phigh := is_newbar(pp_res) ? high_cur[1] : phigh[1]// Calc Lowlow_cur = 0.0low_cur := is_newbar(pp_res) ? low : min(low_cur[1], low)plow = 0.0plow := is_newbar(pp_res) ? low_cur[1] : plow[1]// Calc Closepclose = 0.0pclose := is_newbar(pp_res) ? close[1] : pclose[1]// CALCULATE fibonacci pivots //vPP = (phigh + plow + pclose) / 3//vPP = (phigh + plow + pclose) / 3vR1 = vPP + (phigh - plow) * 0.382vS1 = vPP - (phigh - plow) * 0.382vR2 = vPP + (phigh - plow) * 0.618vS2 = vPP - (phigh - plow) * 0.618vR3 = vPP + (phigh - plow) * 1.000vS3 = 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 lossqty1 = (strategy.equity  * riskCapital / 100 ) /  (close*stopLoss/100)  //check if cash is sufficient  to buy qty1  , if capital not available use the available capital onlyqty1:= (qty1 * close >= strategy.equity ) ? (strategy.equity / close) : qty1strategy.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 )