Pine Script v4 · Strategy
Long only strategy VWAP with BB and Golden Cross EMA50-200
A Pine Script v4 strategy built on EMA (close, 200), VWAP (close) and SMA (close, 7). It has 3 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 14 settings; defaults include From Day 1, From Month 6 and From Year 2020.
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 Long only strategy VWAP with BB and Golden Cross EMA50-200 repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Long only strategy VWAP with BB and Golden Cross EMA50-200 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. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Can Long only strategy VWAP with BB and Golden Cross EMA50-200 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 Long only strategy VWAP with BB and Golden Cross EMA50-200 use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Long only strategy VWAP with BB and Golden Cross EMA50-200 run in Zeal Terminal?
- Yes
- It compiles in 20 ms and runs 1,000 bars in 71 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Upper
- Lower
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- 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, $10,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(close, 200) ignores the settings line 68
Line 68 hard-codes 200 where line 66 uses “slow EMA”. Changing those settings moves one band but not this one.
ema(close, 200)ema(close, longEMA) -
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 96, 98, 100. The upgraded version below moves each call inside an if block.
-
Note
Uses iff(), which v5 removed line 17
iff() on line 17, 19, 21, 23. v5 writes it as the ternary c ? a : b.
-
Note
Uses transp =, which v5 removed line 72
transp = on line 72, 73, 74, 88, 89. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 96
long = on line 96, 98. 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 ema → ta.ema, vwap → ta.vwap, sma → ta.sma, stdev → ta.stdev, crossover → ta.crossover.
- 3 strategy calls use the when = argument (line 96, 98, 100). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 26 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 17: iff(c, a, b) → (c ? a : b)
- Line 19: iff(c, a, b) → (c ? a : b)
- Line 21: iff(c, a, b) → (c ? a : b)
- Line 23: iff(c, a, b) → (c ? a : b)
- Line 58: input(type = input.string) → input.string()
15 more edits
- Line 66: ema → ta.ema
- Line 67: ema → ta.ema
- Line 68: ema → ta.ema
- Line 69: vwap → ta.vwap
- Line 72: transp = 0 → color.new(color.green, 0)
- Line 73: transp = 0 → color.new(color.orange, 0)
- Line 74: transp = 0 → color.new(color.purple, 0)
- Line 77: sma → ta.sma
- Line 78: stdev → ta.stdev
- Line 81: input(type = input.integer) → input.int()
- Line 88: transp = 95 → color.new(#198787, 95)
- Line 89: transp = 0 → color.new(color.purple, 0)
- Line 96: long = true → direction = strategy.long
- Line 98: long = true → direction = strategy.long
- Line 100: crossover → ta.crossover
⋯// © mohanee-//@version=4+//@version=5strategy(title="VWAP and BB strategy [$$]", overlay=true,pyramiding=2, default_qty_value=1, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯//--- Europe-London = iff(DST==0,"0000-0900","0100-1000")+London = (DST==0 ? "0000-0900" : "0100-1000")//--- America-NewYork = iff(DST==0,"0400-1300","0500-1400")+NewYork = (DST==0 ? "0400-1300" : "0500-1400")//--- Pacific-Sydney = iff(DST==0,"1300-2200","1400-2300")+Sydney = (DST==0 ? "1300-2200" : "1400-2300")//--- Asia-Tokyo = iff(DST==0,"1500-2400","1600-0100")+Tokyo = (DST==0 ? "1500-2400" : "1600-0100")//-- Time In Range⋯bbsrc = input(close, title="BB Source")-strategyCalcOption = input(title="strategy to use", type=input.string, options=["BB", "BB_percentageB"], defval="BB")+strategyCalcOption = input.string(title="strategy to use", options=["BB", "BB_percentageB"], defval="BB")//addOnDivergence = input(true,title="Add to existing on Divergence")⋯//variables END-longEMAval= ema(close, longEMA)+longEMAval= ta.ema(close, longEMA)-shortEMAval= ema(close, shortEMA)+shortEMAval= ta.ema(close, shortEMA)-ema200val = ema(close, 200)+ema200val = ta.ema(close, 200)-vwapVal=vwap(close)+vwapVal=ta.vwap(close)// Drawings//plot emas-plot(shortEMAval, color = color.green, linewidth = 1, transp=0)+plot(shortEMAval, color = color.new(color.green, 0), linewidth = 1)-plot(longEMAval, color = color.orange, linewidth = 1, transp=0)+plot(longEMAval, color = color.new(color.orange, 0), linewidth = 1)-plot(ema200val, color = color.purple, linewidth = 2, style=plot.style_line ,transp=0)+plot(ema200val, color = color.new(color.purple, 0), linewidth = 2, style=plot.style_line )//bollinger calculation mult = input(2.0, minval=0.001, maxval=50, title="StdDev")-basis = sma(bbsrc, smaLength)+basis = ta.sma(bbsrc, smaLength)-dev = mult * stdev(bbsrc, smaLength)+dev = mult * ta.stdev(bbsrc, smaLength)upperBand = basis + devlowerBand = basis - dev-offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)+offset = input.int(0, "Offset", minval = -500, maxval = 500)bbr = (bbsrc - lowerBand)/(upperBand - lowerBand) ⋯p2 = plot(lowerBand, "Lower", color=color.teal, offset = offset)-fill(p1, p2, title = "Background", color=#198787, transp=95)+fill(p1, p2, title = "Background", color=color.new(#198787, 95))-plot(vwapVal, color = color.purple, linewidth = 2, transp=0)+plot(vwapVal, color = color.new(color.purple, 0), linewidth = 2)// Colour background⋯//Entry-strategy.entry(id="long", comment="VB LE" , long=true, when= longCondition and ( strategyCalcOption=="BB"? is_price_dipped_bb(10,lowerBand) : is_bb_per_dipped(10,bbr) ) and strategy.position_size<1 ) //is_price_dipped_bb(10,lowerBand)) //and strategy.position_size<1 is_bb_per_dipped(15,bbr) +strategy.entry(id="long", comment="VB LE" , direction = strategy.long, when= longCondition and ( strategyCalcOption=="BB"? is_price_dipped_bb(10,lowerBand) : is_bb_per_dipped(10,bbr) ) and strategy.position_size<1 ) //is_price_dipped_bb(10,lowerBand)) //and strategy.position_size<1 is_bb_per_dipped(15,bbr) //add to the existing position-strategy.entry(id="long", comment="Add" , long=true, when=strategy.position_size>=1 and close<strategy.position_avg_price and close>vwapVal) //and time_cond)+strategy.entry(id="long", comment="Add" , direction = strategy.long, when=strategy.position_size>=1 and close<strategy.position_avg_price and close>vwapVal) //and time_cond)barcolor(strategy.position_size>=1 ? color.blue: na)-strategy.close(id="long", comment="TP Exit", when=crossover(close,upperBand) )+strategy.close(id="long", comment="TP Exit", when=ta.crossover(close,upperBand) )//stoploss⋯Same 26 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
9 more edits
- Line 53: input() → input.int()
- Line 54: input() → input.int()
- Line 56: input() → input.int()
- Line 57: input() → input.source()
- Line 64: input() → input.int()
- Line 76: input() → input.float()
- Line 96: when = longCondition and ( strategyCalcOption=="BB"? is_price_dipped_bb(10,lowerBand) : is_bb_per_dipped(10,bbr) ) and strategy.position_size<1 → if block
- Line 98: when = strategy.position_size>=1 and close<strategy.position_avg_price and close>vwapVal → if block
- Line 100: when = ta.crossover(close,upperBand) → if block
⋯strategy(title="VWAP and BB strategy [$$]", overlay=true,pyramiding=2, default_qty_value=1, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)-fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-fromMonth = input(defval = 6, title = "From Month", minval = 1, maxval = 12)+fromMonth = input.int(defval = 6, title = "From Month", minval = 1, maxval = 12)-fromYear = input(defval = 2020, title = "From Year", minval = 1970)+fromYear = input.int(defval = 2020, title = "From Year", minval = 1970) // To Date Inputs-toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+toDay = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-toMonth = input(defval = 8, title = "To Month", minval = 1, maxval = 12)+toMonth = input.int(defval = 8, title = "To Month", minval = 1, maxval = 12)-toYear = input(defval = 2020, title = "To Year", minval = 1970)+toYear = input.int(defval = 2020, title = "To Year", minval = 1970) ⋯// variables BEGIN-shortEMA = input(50, title="fast EMA", minval=1)+shortEMA = input.int(50, title="fast EMA", minval=1)-longEMA = input(200, title="slow EMA", minval=1)+longEMA = input.int(200, title="slow EMA", minval=1)//BB-smaLength = input(7, title="BB SMA Length", minval=1)+smaLength = input.int(7, title="BB SMA Length", minval=1)-bbsrc = input(close, title="BB Source")+bbsrc = input.source(close, title="BB Source")strategyCalcOption = input.string(title="strategy to use", options=["BB", "BB_percentageB"], defval="BB")⋯//vwap_res = input(title="VWAP Resolution", type=input.resolution, defval="session")-stopLoss = input(title="Stop Loss%", defval=1, minval=1)+stopLoss = input.int(title="Stop Loss%", defval=1, minval=1)//variables END⋯//bollinger calculation -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.sma(bbsrc, smaLength)⋯//Entry-strategy.entry(id="long", comment="VB LE" , direction = strategy.long, when= longCondition and ( strategyCalcOption=="BB"? is_price_dipped_bb(10,lowerBand) : is_bb_per_dipped(10,bbr) ) and strategy.position_size<1 ) //is_price_dipped_bb(10,lowerBand)) //and strategy.position_size<1 is_bb_per_dipped(15,bbr) +if longCondition and ( strategyCalcOption=="BB"? is_price_dipped_bb(10,lowerBand) : is_bb_per_dipped(10,bbr) ) and strategy.position_size<1+ strategy.entry(id="long", comment="VB LE" , direction = strategy.long ) //is_price_dipped_bb(10,lowerBand)) //and strategy.position_size<1 is_bb_per_dipped(15,bbr) //add to the existing position-strategy.entry(id="long", comment="Add" , direction = strategy.long, when=strategy.position_size>=1 and close<strategy.position_avg_price and close>vwapVal) //and time_cond)+if strategy.position_size>=1 and close<strategy.position_avg_price and close>vwapVal+ strategy.entry(id="long", comment="Add" , direction = strategy.long) //and time_cond)barcolor(strategy.position_size>=1 ? color.blue: na)-strategy.close(id="long", comment="TP Exit", when=ta.crossover(close,upperBand) )+if ta.crossover(close,upperBand)+ strategy.close(id="long", comment="TP Exit" )//stoploss⋯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: 26 before, 0 after on BTCUSDT 4h, 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.
⋯// © mohanee-//@version=5+//@version=6strategy(title="VWAP and BB strategy [$$]", overlay=true,pyramiding=2, default_qty_value=1, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)⋯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 |
|---|---|---|---|
| From Day | 1 | int · min 1 · max 31 | startDate |
| From Month | 6 | int · min 1 · max 12 | startDate |
| From Year | 2020 | int · min 1970 | startDate |
| To Day | 1 | int · min 1 · max 31 | finishDate |
| To Month | 8 | int · min 1 · max 12 | finishDate |
| To Year | 2020 | int · min 1970 | finishDate |
| fast EMA | 50 | int · min 1 | shortEMAval |
| slow EMA | 200 | int · min 1 | longEMAval |
| BB SMA Length | 7 | int · min 1 | basis dev |
| BB Source | close | source | basis dev bbr |
| strategy to use | BB | string · options ["BB", "BB_percentageB"] | entry long |
| Stop Loss% | 1 | int · min 1 | stopLossVal |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | Upper Lower |
What it calculates
- EMA (
ema,ta.emain v5)close, slow EMA (200)longEMAval · line 66 - EMA (
ema,ta.emain v5)close, fast EMA (50)shortEMAval · line 67 - EMA (
ema,ta.emain v5)close, 200ema200val · line 68 - VWAP (
vwap,ta.vwapin v5)closevwapVal · line 69 - SMA (
sma,ta.smain v5)BB Source (close), BB SMA Length (7)basis · line 77 - Stdev (
stdev,ta.stdevin v5)BB Source (close), BB SMA Length (7)dev · line 78
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | longCondition and ( strategyCalcOption=="BB"? is_price_dipped_bb(10,lowerBand) : is_bb_per_dipped(10,bbr) ) and strategy.position_size<1 | On | 96 |
| Open long long | strategy.position_size>=1 and close<strategy.position_avg_price and close>vwapVal | On | 98 |
| Close long | crossover(close,upperBand) | On | 100 |
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.
- 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.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +202.1% | +5.5% | 26 | 62% | 3.10 | 66.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +8.8% | +8.4% | 33 | 67% | 2.48 | 5.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.4% | +21.5% | 29 | 72% | 2.09 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.8% | +17.1% | 27 | 74% | 3.15 | 1.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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Long only strategy VWAP with BB and Golden Cross EMA50-200 this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| VWAP and BB strategy [EEMANI] by mohanee | ema vwap sma stdev | v4 strategy | No trades on this market | ||
| Buying Selling Volume Strategy by exlux99 | vwap ema sma stdev | v5 strategy | No trades on this market | ||
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema sma stdev | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy | No trades on this market | ||
| ZVWAP strategy by mohanee | sma ema vwap | v4 strategy | +614.4% | 13 | 748.5% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 20 ms | With a workaround 1,000 bars in 71 ms | Not measured |
| PineTS | No 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 (lines 96, 98) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © mohanee//@version=4strategy(title="VWAP and BB strategy [$$]", overlay=true,pyramiding=2, default_qty_value=1, default_qty_type=strategy.fixed, initial_capital=10000, currency=currency.USD)fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)fromMonth = input(defval = 6, title = "From Month", minval = 1, maxval = 12)fromYear = input(defval = 2020, title = "From Year", minval = 1970) // To Date InputstoDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)toMonth = input(defval = 8, title = "To Month", minval = 1, maxval = 12)toYear = input(defval = 2020, title = "To Year", minval = 1970) // Calculate start/end date and time conditionDST = 1 //day light saving for usa//--- EuropeLondon = iff(DST==0,"0000-0900","0100-1000")//--- AmericaNewYork = iff(DST==0,"0400-1300","0500-1400")//--- PacificSydney = iff(DST==0,"1300-2200","1400-2300")//--- AsiaTokyo = iff(DST==0,"1500-2400","1600-0100")//-- Time In Rangetimeinrange(res, sess) => time(res, sess) != 0london = timeinrange(timeframe.period, London)newyork = timeinrange(timeframe.period, NewYork)startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)finishDate = timestamp(toYear, toMonth, toDay, 00, 00)time_cond = time >= startDate and time <= finishDate is_price_dipped_bb(pds,source1) => t_bbDipped=false for i=1 to pds t_bbDipped:= (t_bbDipped or close[i]<source1) ? true : false if t_bbDipped==true break else continue t_bbDippedis_bb_per_dipped(pds,bbrSrc) => t_bbDipped=false for i=1 to pds t_bbDipped:= (t_bbDipped or bbrSrc[i]<=0) ? true : false if t_bbDipped==true break else continue t_bbDipped // variables BEGINshortEMA = input(50, title="fast EMA", minval=1)longEMA = input(200, title="slow EMA", minval=1)//BBsmaLength = input(7, title="BB SMA Length", minval=1)bbsrc = input(close, title="BB Source")strategyCalcOption = input(title="strategy to use", type=input.string, options=["BB", "BB_percentageB"], defval="BB")//addOnDivergence = input(true,title="Add to existing on Divergence")//exitOption = input(title="exit on RSI or BB", type=input.string, options=["RSI", "BB"], defval="BB")//bbSource = input(title="BB source", type=input.string, options=["close", "vwap"], defval="close") //vwap_res = input(title="VWAP Resolution", type=input.resolution, defval="session")stopLoss = input(title="Stop Loss%", defval=1, minval=1)//variables ENDlongEMAval= ema(close, longEMA)shortEMAval= ema(close, shortEMA)ema200val = ema(close, 200)vwapVal=vwap(close)// Drawings//plot emasplot(shortEMAval, color = color.green, linewidth = 1, transp=0)plot(longEMAval, color = color.orange, linewidth = 1, transp=0)plot(ema200val, color = color.purple, linewidth = 2, style=plot.style_line ,transp=0)//bollinger calculation mult = input(2.0, minval=0.001, maxval=50, title="StdDev")basis = sma(bbsrc, smaLength)dev = mult * stdev(bbsrc, smaLength)upperBand = basis + devlowerBand = basis - devoffset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)bbr = (bbsrc - lowerBand)/(upperBand - lowerBand) //bollinger calculation //plot bb//plot(basis, "Basis", color=#872323, 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=#198787, transp=95)plot(vwapVal, color = color.purple, linewidth = 2, transp=0)// Colour background//barcolor(shortEMAval>longEMAval and close<=lowerBand ? color.yellow: na) //longCondition= shortEMAval > longEMAval and close>open and close>vwapVallongCondition= ( shortEMAval > longEMAval and close>open and close>vwapVal and close<upperBand ) //and time_cond // and close>=vwapVal //Entrystrategy.entry(id="long", comment="VB LE" , long=true, when= longCondition and ( strategyCalcOption=="BB"? is_price_dipped_bb(10,lowerBand) : is_bb_per_dipped(10,bbr) ) and strategy.position_size<1 ) //is_price_dipped_bb(10,lowerBand)) //and strategy.position_size<1 is_bb_per_dipped(15,bbr) //add to the existing positionstrategy.entry(id="long", comment="Add" , long=true, when=strategy.position_size>=1 and close<strategy.position_avg_price and close>vwapVal) //and time_cond)barcolor(strategy.position_size>=1 ? color.blue: na)strategy.close(id="long", comment="TP Exit", when=crossover(close,upperBand) )//stoplossstopLossVal = strategy.position_avg_price * (1-(stopLoss*0.01) )//strategy.close(id="long", comment="SL Exit", when= close < stopLossVal)//strategy.risk.max_intraday_loss(stopLoss, strategy.percent_of_equity)