Pine Script v4 · Strategy
BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted
A Pine Script v4 strategy built on Change (src), CUM and EMA (result, -1, 1, 20). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays no commission. 19 settings; defaults include Start Date 1, Start Month 1 and Start Year 2010.
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 BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted 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, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Can BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L48:C14: 'pvt' was renamed to 'ta.pvt' in Pine Script v5), so no v5 download is offered; the edits are shown below.
- Does BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted run in Zeal Terminal?
- Yes
- It compiles in 63 ms and runs 1,000 bars in 1,627 ms, in the browser.
BTCUSDT · 1D · default settings
- Δ(OBV-PVT)
- BB%B
- HLine
- HLine
- HLine
- HLine
- HLine
- HLine
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BINANCE:BTCUSDT 1 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.
- 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
- 0.00%
- $0.00
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. 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
ema(normalize(result, -1, 1), 20) ignores the settings line 50
Line 50 hard-codes 20 where line 53 uses “Length”. Changing those settings moves one band but not this one.
ema(normalize(result, -1, 1), 20)ema(normalize(result, -1, 1), length) -
Check
2 settings do nothing
“Show barcolors”, “Show previous VWAP close” are declared but never read.
-
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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
6 settings have no label
In the settings dialog length (line 51), TimeFrame (line 117), l1 (line 137), xx (line 152), yy (line 153), zz (line 154) show an empty name. The labels on this page come from the variable names.
-
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 206, 208, 211, 213. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 120
iff() on line 120, 123, 125, 127, 135. v5 writes it as the ternary c ? a : b.
-
Note
Uses transp =, which v5 removed line 203
transp = on line 203, 204. v5 folds the transparency into the colour with color.new(c, transp).
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 min → math.min, max → math.max, security → request.security, change → ta.change, cum → ta.cum, ema → ta.ema, stdev → ta.stdev, sqrt → math.sqrt, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder, highest → ta.highest, lowest → ta.lowest.
- 4 strategy calls use the when = argument (line 206, 208, 211, 213). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersThe v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L48:C14: 'pvt' was renamed to 'ta.pvt' in Pine Script v5.
- Line 4: //@version=4 → //@version=5
- Line 6: input(type = input.integer) → input.int()
- Line 8: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
- Line 12: input(type = input.integer) → input.int()
- Line 14: input(type = input.integer) → input.int()
37 more edits
- Line 16: input(type = input.integer) → input.int()
- Line 25: min → math.min
- Line 26: max → math.max
- Line 27: max → math.max
- Line 38: security → request.security
- Line 46: change → ta.change
- Line 47: cum → ta.cum
- Line 49: change → ta.change
- Line 50: ema → ta.ema
- Line 53: ema → ta.ema
- Line 54: stdev → ta.stdev
- Line 59: input(type = input.float) → input.float()
- Line 60: input(type = input.integer) → input.int()
- Line 117: input(type = input.resolution) → input.timeframe()
- Line 120: iff(c, a, b) → (c ? a : b)
- Line 120: change → ta.change
- Line 123: iff(c, a, b) → (c ? a : b)
- Line 125: iff(c, a, b) → (c ? a : b)
- Line 127: iff(c, a, b) → (c ? a : b)
- Line 129: sqrt → math.sqrt
- Line 129: max → math.max
- Line 132: input(type = input.bool) → input.bool()
- Line 133: input(type = input.bool) → input.bool()
- Line 135: iff(c, a, b) → (c ? a : b)
- Line 140: sma → ta.sma
- Line 141: stdev → ta.stdev
- Line 162: crossover → ta.crossover
- Line 163: crossunder → ta.crossunder
- Line 164: crossover → ta.crossover
- Line 165: crossunder → ta.crossunder
- Line 185: highest → ta.highest
- Line 186: lowest → ta.lowest
- Line 191: lowest → ta.lowest
- Line 203: transp = 0 → color.new(color.green, 0)
- Line 204: transp = 0 → color.new(color.red, 0)
- Line 206: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 211: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// © oakwhiz and tathal-//@version=4+//@version=5strategy("BBPBΔ(OBV-PVT)BB", default_qty_type=strategy.percent_of_equity, default_qty_value=100)-startDate = input(title="Start Date", type=input.integer,+startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31)-startMonth = input(title="Start Month", type=input.integer,+startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)-startYear = input(title="Start Year", type=input.integer,+startYear = input.int(title="Start Year", defval=2010, minval=1800, maxval=2100)-endDate = input(title="End Date", type=input.integer,+endDate = input.int(title="End Date", defval=31, minval=1, maxval=31)-endMonth = input(title="End Month", type=input.integer,+endMonth = input.int(title="End Month", defval=12, minval=1, maxval=12)-endYear = input(title="End Year", type=input.integer,+endYear = input.int(title="End Year", defval=2021, minval=1800, maxval=2100)⋯ var _historicMax = -10e10- _historicMin := min(nz(_src, _historicMin), _historicMin)+ _historicMin := math.min(nz(_src, _historicMin), _historicMin)- _historicMax := max(nz(_src, _historicMax), _historicMax)+ _historicMax := math.max(nz(_src, _historicMax), _historicMax)- _min + (_max - _min) * (_src - _historicMin) / max(_historicMax - _historicMin, 10e-10)+ _min + (_max - _min) * (_src - _historicMin) / math.max(_historicMax - _historicMin, 10e-10) ⋯ -f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)+f_secureSecurity(_symbol, _res, _src) => request.security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on) ⋯src = close-float change_src = change(src)+float change_src = ta.change(src)-float i_obv = cum(change_src > 0 ? volume : change_src < 0 ? -volume : 0*volume)+float i_obv = ta.cum(change_src > 0 ? volume : change_src < 0 ? -volume : 0*volume)float i_pvt = pvt-float result = change(i_obv - i_pvt)+float result = ta.change(i_obv - i_pvt)-float nresult = ema(normalize(result, -1, 1), 20)+float nresult = ta.ema(normalize(result, -1, 1), 20)length = input(20, minval=1)mult = input(2.0, minval=0.001, maxval=50, title="StdDev")-basis = ema(nresult, length)+basis = ta.ema(nresult, length)-dev = mult * stdev(nresult, length)+dev = mult * ta.stdev(nresult, length)upper = basis + dev⋯////////////////INPUTS///////////////////-lambda = input(defval = 1000, type = input.float, title = "Smoothing Factor (Lambda)", minval = 1)+lambda = input.float(defval = 1000, title = "Smoothing Factor (Lambda)", minval = 1)-leng = input(defval = 100, type = input.integer, title = "Filter Length", minval = 1)+leng = input.int(defval = 100, title = "Filter Length", minval = 1)srcc = close⋯////////////////////Plottingd///////////////////////-TimeFrame = input('1', type=input.resolution)+TimeFrame = input.timeframe('1')start = f_secureSecurity(syminfo.tickerid, TimeFrame, time)//-------------------------------------------------newSession = iff(change(start), 1, 0)+newSession = (ta.change(start) ? 1 : 0)//------------------------------------------------vwapsum = 0.0-vwapsum := iff(newSession, o5*volume, vwapsum[1]+o5*volume)+vwapsum := (newSession ? o5*volume : vwapsum[1]+o5*volume)volumesum = 0.0-volumesum := iff(newSession, volume, volumesum[1]+volume)+volumesum := (newSession ? volume : volumesum[1]+volume)v2sum = 0.0-v2sum := iff(newSession, volume*o5*o5, v2sum[1]+volume*o5*o5)+v2sum := (newSession ? volume*o5*o5 : v2sum[1]+volume*o5*o5)myvwap = vwapsum/volumesum-dev2 = sqrt(max(v2sum/volumesum - myvwap*myvwap, 0))+dev2 = math.sqrt(math.max(v2sum/volumesum - myvwap*myvwap, 0))Coloring=close>myvwap?color.green:color.redav=myvwap-showBcol = input(false, type=input.bool, title="Show barcolors")+showBcol = input.bool(false, title="Show barcolors")-showPrevVWAP = input(false, type=input.bool, title="Show previous VWAP close")+showPrevVWAP = input.bool(false, title="Show previous VWAP close")prevwap = 0.0-prevwap := iff(newSession, myvwap[1], prevwap[1])+prevwap := (newSession ? myvwap[1] : prevwap[1])nprevwap= normalize(prevwap, 0, 1)⋯mult1 = input(2.0, minval=0.001, maxval=50, title="StdDev")-basis1 = sma(src2, l1)+basis1 = ta.sma(src2, l1)-dev1 = mult1 * stdev(src2, l1)+dev1 = mult1 * ta.stdev(src2, l1)upper1 = basis1 + dev1⋯fill(zzz, zline, color=color.green, title="GO LONG ZONE")-l20 = crossover(deltabbr, 0)+l20 = ta.crossover(deltabbr, 0)-l30 = crossunder(deltabbr, 0)+l30 = ta.crossunder(deltabbr, 0)-l40 = crossover(o5, 0)+l40 = ta.crossover(o5, 0)-l50 = crossunder(o5, 0)+l50 = ta.crossunder(o5, 0)z1 = bbr1 >= 1⋯n = input(16,"Period")-H = highest(hl2,n)+H = ta.highest(hl2,n)-L = lowest(hl2,n)+L = ta.lowest(hl2,n)hi = H[1]⋯dn = low<lo-lowerbbh = lowest(10)[1]+lowerbbh = ta.lowest(10)[1]bbh = (low == open ? open < lowerbbh ? open < close ? close > ((high[1] - low[1]) / 2) + low[1] :na : na : na)⋯buy= (z5 or z4 or a5 or long5) and (icreturn or dn)-plotshape(long and not sell ? -0.5 : na, title="Long", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)+plotshape(long and not sell ? -0.5 : na, title="Long", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))-plotshape(short and not sell? 1 : na, title="Short", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)+plotshape(short and not sell? 1 : na, title="Short", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))if (inDateRange)- strategy.entry("long", true, when = long )+ strategy.entry("long", strategy.long, when = long )if (inDateRange) and (strategy.position_size > 0)⋯if (inDateRange)- strategy.entry("short", false, when = short )+ strategy.entry("short", strategy.short, when = short )if (inDateRange) and (strategy.position_size < 0)⋯Clean v5
Not verifiedThe v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L48:C14: 'pvt' was renamed to 'ta.pvt' in Pine Script v5.), so this step could not be checked.
- Line 51: input() → input.int()
- Line 52: input() → input.float()
- Line 137: input() → input.int()
- Line 139: input() → input.float()
- Line 152: input() → input.float()
- Line 153: input() → input.float()
6 more edits
- Line 154: input() → input.int()
- Line 184: input() → input.int()
- Line 206: when = long → if block
- Line 208: when = sell or cancel → if block
- Line 211: when = short → if block
- Line 213: when = buy → if block
⋯float nresult = ta.ema(normalize(result, -1, 1), 20)-length = input(20, minval=1)+length = input.int(20, minval=1)-mult = input(2.0, minval=0.001, maxval=50, title="StdDev")+mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")basis = ta.ema(nresult, length)⋯nprevwap= normalize(prevwap, 0, 1)-l1= input(20, minval=1)+l1= input.int(20, minval=1)src2 = close-mult1 = input(2.0, minval=0.001, maxval=50, title="StdDev")+mult1 = input.float(2.0, minval=0.001, maxval=50, title="StdDev")basis1 = ta.sma(src2, l1)⋯zline = hline(0)-xx = input(.3)+xx = input.float(.3)-yy = input(.7)+yy = input.float(.7)-zz = input(-1)+zz = input.int(-1)xxx = hline(xx)⋯///-n = input(16,"Period")+n = input.int(16,"Period")H = ta.highest(hl2,n)⋯if (inDateRange)- strategy.entry("long", strategy.long, when = long )+ if long+ strategy.entry("long", strategy.long )if (inDateRange) and (strategy.position_size > 0)- strategy.close_all(when = sell or cancel)+ if sell or cancel+ strategy.close_all() if (inDateRange)- strategy.entry("short", strategy.short, when = short )+ if short+ strategy.entry("short", strategy.short )if (inDateRange) and (strategy.position_size < 0)- strategy.close_all(when = buy)+ if buy+ strategy.close_all()Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L48:C14: 'pvt' was renamed to 'ta.pvt' in Pine Script v5.), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © oakwhiz and tathal-//@version=5+//@version=6strategy("BBPBΔ(OBV-PVT)BB", default_qty_type=strategy.percent_of_equity, default_qty_value=100)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Start Date | 1 | int (written input.integer) · min 1 · max 31 | inDateRange |
| Start Month | 1 | int (written input.integer) · min 1 · max 12 | inDateRange |
| Start Year | 2010 | int (written input.integer) · min 1800 · max 2100 | inDateRange |
| End Date | 31 | int (written input.integer) · min 1 · max 31 | inDateRange |
| End Month | 12 | int (written input.integer) · min 1 · max 12 | inDateRange |
| End Year | 2021 | int (written input.integer) · min 1800 · max 2100 | inDateRange |
| Length (no label in the script) | 20 | int · min 1 | basis dev |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| Smoothing Factor (Lambda) | 1000 | float · min 1 | line 75 line 77 line 78 line 79 line 80 line 81 line 82 line 83 line 84 line 85 line 86 line 87 line 88 |
| Filter Length | 100 | int (written input.integer) · min 1 | a b c d e f ll1 ll2 i x line 111 |
| Time Frame (no label in the script) | 1 | timeframe (written input.resolution) | start |
| Show barcolors | false | bool | unused |
| Show previous VWAP close | false | bool | unused |
| L1 (no label in the script) | 20 | int · min 1 | basis1 dev1 |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev1 |
| Xx (no label in the script) | .3 | float | xxx hline |
| Yy (no label in the script) | .7 | float | yyy hline |
| Zz (no label in the script) | -1 | int | zzz hline |
| Period | 16 | int | H L |
What it calculates
- Change (
change,ta.changein v5)srcchange_src · line 46 - CUM (
cum,ta.cumin v5)change_src > 0 ? volume : change_src < 0 ? -volume : 0*volumei_obv · line 47 - Change (
change,ta.changein v5)i_obv - i_pvtresult · line 49 - EMA (
ema,ta.emain v5)normalize(result, -1, 1), 20nresult · line 50 - EMA (
ema,ta.emain v5)nresult, Length (20)basis · line 53 - Stdev (
stdev,ta.stdevin v5)nresult, Length (20)dev · line 54 - Change (
change,ta.changein v5)startnewSession · line 120 - SMA (
sma,ta.smain v5)src2, L1 (20)basis1 · line 140 - Stdev (
stdev,ta.stdevin v5)src2, L1 (20)dev1 · line 141 - Crossover (
crossover,ta.crossoverin v5)deltabbr, 0l20 · line 162 - Crossunder (
crossunder,ta.crossunderin v5)deltabbr, 0l30 · line 163 - Crossover (
crossover,ta.crossoverin v5)o5, 0l40 · line 164 - Crossunder (
crossunder,ta.crossunderin v5)o5, 0l50 · line 165 - Highest (
highest,ta.highestin v5)hl2, Period (16)H · line 185 - Lowest (
lowest,ta.lowestin v5)hl2, Period (16)L · line 186 - Lowest (
lowest,ta.lowestin v5)10lowerbbh · line 191
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.
The script has 100 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | long(long5 or z5 or a5) and (icreturn or bbh or up) | On | 206 |
| Close | sell or cancel | On | 208 |
| Open short short | short((z1 or z2 or a1 or sell5) and (l40 or l20)) and icreturn | On | 211 |
| Close | buy(z5 or z4 or a5 or long5) and (icreturn or dn) | On | 213 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- CheckHigher-timeframe data1 security call(s) use lookahead_on (line 38). Without a [1] offset this reads future bars in history.
- 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
Not run on other markets: the script requests BINANCE:BTCUSDT 1, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Crunchster's Turtle and Trend System by Crunchster1 | lowest highest ema stdev sma | v5 strategy | +18.0% | 31 | 16.7% |
| The Z-score by jensenvilhelm | sma stdev ema highest lowest | v5 strategy | +2.4% | 52 | 5.5% |
| MZ SRSI Strategy V1.0 by MightyZinger | ema sma highest lowest stdev | v4 strategy | No trades on this market | ||
| WOMBO COMBO- EMA & VWAP & MACD & BB & STC by MakeMoneyCoESTB2020 | ema sma stdev highest lowest | v4 strategy | −0.5% | 6 | 2.2% |
| Lawyers Trend Pro Strategy by ErdemDemir | sma stdev lowest highest | v4 strategy | +12.1% | 102 | 41.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 63 ms | With a workaround 1,000 bars in 1,627 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 206, 211) 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///// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © oakwhiz and tathal//@version=4strategy("BBPBΔ(OBV-PVT)BB", default_qty_type=strategy.percent_of_equity, default_qty_value=100)startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)startYear = input(title="Start Year", type=input.integer, defval=2010, minval=1800, maxval=2100)endDate = input(title="End Date", type=input.integer, defval=31, minval=1, maxval=31)endMonth = input(title="End Month", type=input.integer, defval=12, minval=1, maxval=12)endYear = input(title="End Year", type=input.integer, defval=2021, minval=1800, maxval=2100)// Normalize Functionnormalize(_src, _min, _max) => // Normalizes series with unknown min/max using historical min/max. // _src : series to rescale. // _min, _min: min/max values of rescaled series. var _historicMin = 10e10 var _historicMax = -10e10 _historicMin := min(nz(_src, _historicMin), _historicMin) _historicMax := max(nz(_src, _historicMax), _historicMax) _min + (_max - _min) * (_src - _historicMin) / max(_historicMax - _historicMin, 10e-10) // STEP 2:// Look if the close time of the current bar// falls inside the date rangeinDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0)) // Stop f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on) // Stop loss & Take Profit Sectionicreturn = falseinnercandle = if (high < high[1]) and (low > low[1]) icreturn := truesrc = closefloat change_src = change(src)float i_obv = cum(change_src > 0 ? volume : change_src < 0 ? -volume : 0*volume)float i_pvt = pvtfloat result = change(i_obv - i_pvt)float nresult = ema(normalize(result, -1, 1), 20)length = input(20, minval=1)mult = input(2.0, minval=0.001, maxval=50, title="StdDev")basis = ema(nresult, length)dev = mult * stdev(nresult, length)upper = basis + devlower = basis - devbbr = (nresult - lower)/(upper - lower)////////////////INPUTS///////////////////lambda = input(defval = 1000, type = input.float, title = "Smoothing Factor (Lambda)", minval = 1)leng = input(defval = 100, type = input.integer, title = "Filter Length", minval = 1)srcc = close///////////Construct Arrays///////////////a = array.new_float(leng, 0.0) b = array.new_float(leng, 0.0)c = array.new_float(leng, 0.0)d = array.new_float(leng, 0.0)e = array.new_float(leng, 0.0)f = array.new_float(leng, 0.0)/////////Initialize the Values/////////////for more details visit:// https://asmquantmacro.com/2015/06/25/hodrick-prescott-filter-in-excel/ll1 = leng-1ll2 = leng-2for i = 0 to ll1 array.set(a,i, lambda*(-4)) array.set(b,i, src[i]) array.set(c,i, lambda*(-4)) array.set(d,i, lambda*6 + 1) array.set(e,i, lambda) array.set(f,i, lambda)array.set(d, 0, lambda + 1.0)array.set(d, ll1, lambda + 1.0)array.set(d, 1, lambda * 5.0 + 1.0)array.set(d, ll2, lambda * 5.0 + 1.0)array.set(c, 0 , lambda * (-2.0))array.set(c, ll2, lambda * (-2.0))array.set(a, 0 , lambda * (-2.0))array.set(a, ll2, lambda * (-2.0))//////////////Solve the optimization issue/////////////////////float r = array.get(a, 0)float s = array.get(a, 1)float t = array.get(e, 0)float xmult = 0.0for i = 1 to ll2 xmult := r / array.get(d, i-1) array.set(d, i, array.get(d, i) - xmult * array.get(c, i-1)) array.set(c, i, array.get(c, i) - xmult * array.get(f, i-1)) array.set(b, i, array.get(b, i) - xmult * array.get(b, i-1)) xmult := t / array.get(d, i-1) r := s - xmult*array.get(c, i-1) array.set(d, i+1, array.get(d, i+1) - xmult * array.get(f, i-1)) array.set(b, i+1, array.get(b, i+1) - xmult * array.get(b, i-1)) s := array.get(a, i+1) t := array.get(e, i)xmult := r / array.get(d, ll2)array.set(d, ll1, array.get(d, ll1) - xmult * array.get(c, ll2))x = array.new_float(leng, 0) array.set(x, ll1, (array.get(b, ll1) - xmult * array.get(b, ll2)) / array.get(d, ll1))array.set(x, ll2, (array.get(b, ll2) - array.get(c, ll2) * array.get(x, ll1)) / array.get(d, ll2))for j = 0 to leng-3 i = leng-3 - j array.set(x, i, (array.get(b,i) - array.get(f,i)*array.get(x,i+2) - array.get(c,i)*array.get(x,i+1)) / array.get(d, i))//////////////Construct the output///////////////////o5 = array.get(x,0)////////////////////Plottingd///////////////////////TimeFrame = input('1', type=input.resolution)start = f_secureSecurity(syminfo.tickerid, TimeFrame, time)//------------------------------------------------newSession = iff(change(start), 1, 0)//------------------------------------------------vwapsum = 0.0vwapsum := iff(newSession, o5*volume, vwapsum[1]+o5*volume)volumesum = 0.0volumesum := iff(newSession, volume, volumesum[1]+volume)v2sum = 0.0v2sum := iff(newSession, volume*o5*o5, v2sum[1]+volume*o5*o5)myvwap = vwapsum/volumesumdev2 = sqrt(max(v2sum/volumesum - myvwap*myvwap, 0))Coloring=close>myvwap?color.green:color.redav=myvwapshowBcol = input(false, type=input.bool, title="Show barcolors")showPrevVWAP = input(false, type=input.bool, title="Show previous VWAP close")prevwap = 0.0prevwap := iff(newSession, myvwap[1], prevwap[1])nprevwap= normalize(prevwap, 0, 1)l1= input(20, minval=1)src2 = closemult1 = input(2.0, minval=0.001, maxval=50, title="StdDev")basis1 = sma(src2, l1)dev1 = mult1 * stdev(src2, l1)upper1 = basis1 + dev1lower1 = basis1 - dev1bbr1 = (src - lower1)/(upper1 - lower1)az = plot(bbr, "Δ(OBV-PVT)", color.rgb(0,153,0,0), style=plot.style_columns)bz = plot(bbr1, "BB%B", color.rgb(0,125,125,50), style=plot.style_columns)fill(az, bz, color=color.white)deltabbr = bbr1 - bbroneline = hline(1)twoline = hline(1.2)zline = hline(0)xx = input(.3)yy = input(.7)zz = input(-1)xxx = hline(xx)yyy = hline(yy)zzz = hline(zz)fill(oneline, twoline, color=color.red, title="Sell Zone")fill(yyy, oneline, color=color.orange, title="Slightly Overbought")fill(yyy, zline, color=color.white, title="DO NOTHING ZONE")fill(zzz, zline, color=color.green, title="GO LONG ZONE")l20 = crossover(deltabbr, 0)l30 = crossunder(deltabbr, 0)l40 = crossover(o5, 0)l50 = crossunder(o5, 0)z1 = bbr1 >= 1z2 = bbr1 < 1 and bbr1 >= .7z3 = bbr1 < .7 and bbr1 >= .3z4 = bbr1 < .3 and bbr1 >= 0z5 = bbr1 < 0a1 = bbr >= 1a2 = bbr < 1 and bbr >= .7a4 = bbr < .3 and bbr >= 0a5 = bbr < 0b4 = deltabbr < .3 and deltabbr >= 0b5 = deltabbr < 0c4 = o5 < .3 and o5 >= 0c5 = o5 < 0b1 = deltabbr >= 1b2 = deltabbr < 1 and o5 >= .7c1 = o5 >= 1c2 = o5 < 1 and o5 >= .7///n = input(16,"Period")H = highest(hl2,n)L = lowest(hl2,n)hi = H[1]lo = L[1]up = high>hidn = low<lolowerbbh = lowest(10)[1]bbh = (low == open ? open < lowerbbh ? open < close ? close > ((high[1] - low[1]) / 2) + low[1] :na : na : na)plot(normalize(av,-1,1), linewidth=2, title="Trendline", color=color.yellow)long5 = close < av and av[0] > av[1]sell5 = close > avcancel = falseif open >= high[1] cancel = truelong = (long5 or z5 or a5) and (icreturn or bbh or up)sell = ((z1 or a1) or (l40 and l20)) and (icreturn or dn) and (c1 or b1)short = ((z1 or z2 or a1 or sell5) and (l40 or l20)) and icreturnbuy= (z5 or z4 or a5 or long5) and (icreturn or dn)plotshape(long and not sell ? -0.5 : na, title="Long", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)plotshape(short and not sell? 1 : na, title="Short", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)if (inDateRange) strategy.entry("long", true, when = long )if (inDateRange) and (strategy.position_size > 0) strategy.close_all(when = sell or cancel) if (inDateRange) strategy.entry("short", false, when = short )if (inDateRange) and (strategy.position_size < 0) strategy.close_all(when = buy)