Pine Script v4 · Strategy
Wave Trend w- VWMA overlay
A Pine Script v4 strategy built on VWMA or WMA (close, 21), EMA (ap, 10) and SMA (wt1, 4). It has 4 order rules and no entry of its own. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 20 settings; defaults include Base Quantity 1, Session 1: Start Hour 8 and Session 1: Start Minute 25.
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 Wave Trend w- VWMA overlay repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Wave Trend w- VWMA overlay 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 entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- Can Wave Trend w- VWMA overlay be converted to Pine Script v5?
- Not tested
- The steps are shown below, but neither version placed a trade on any market tested, so there was nothing to compare and no download is offered.
- Does Wave Trend w- VWMA overlay use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Wave Trend w- VWMA overlay run in Zeal Terminal?
- Yes
- It compiles in 43 ms and runs 1,000 bars in 83 ms, in the browser.
BTCUSDT · 1D · default settings
- VWMA High band
- VWMA Low band
- VWMA
- 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, $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.
-
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 transp =, which v5 removed line 84
transp = on line 84, 86, 88, 90, 119. 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 vwma → ta.vwma, wma → ta.wma, ema → ta.ema, abs → math.abs, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.
v4 → v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 12: //@version=4 → //@version=5
- Line 19: input(type = input.float) → input.float()
- Line 21: input(type = input.integer) → input.int()
- Line 23: input(type = input.integer) → input.int()
- Line 25: input(type = input.integer) → input.int()
- Line 27: input(type = input.integer) → input.int()
26 more edits
- Line 29: input(type = input.integer) → input.int()
- Line 31: input(type = input.integer) → input.int()
- Line 33: input(type = input.integer) → input.int()
- Line 35: input(type = input.integer) → input.int()
- Line 49: input(type = input.integer) → input.int()
- Line 51: vwma → ta.vwma
- Line 52: vwma → ta.vwma
- Line 53: vwma → ta.vwma
- Line 55: wma → ta.wma
- Line 56: wma → ta.wma
- Line 57: wma → ta.wma
- Line 84: transp = bandTrans → color.new(vwma_color, bandTrans)
- Line 86: transp = bandTrans → color.new(vwma_color, bandTrans)
- Line 88: transp = fillTrans → color.new(vwma_color, fillTrans)
- Line 90: transp = bandTrans → color.new(vwma_color, bandTrans)
- Line 105: ema → ta.ema
- Line 106: ema → ta.ema
- Line 106: abs → math.abs
- Line 108: ema → ta.ema
- Line 111: sma → ta.sma
- Line 119: transp = 80 → color.new(color.blue, 80)
- Line 126: crossover → ta.crossover
- Line 127: crossunder → ta.crossunder
- Line 134: abs → math.abs
- Line 140: abs → math.abs
- Line 146: abs → math.abs
⋯//-//@version=4+//@version=5//==============================================================================⋯ -baseQty = input(defval=1, title="Base Quantity", type=input.float, minval=1)+baseQty = input.float(defval=1, title="Base Quantity", minval=1)useSessions = input(defval=true, title="Limit Signals to Trading Sessions?")-sess1_startHour = input(defval=8, title="Session 1: Start Hour",- type=input.integer, minval=0, maxval=23)+sess1_startHour = input.int(defval=8, title="Session 1: Start Hour", minval=0, maxval=23)-sess1_startMinute = input(defval=25, title="Session 1: Start Minute",- type=input.integer, minval=0, maxval=59)+sess1_startMinute = input.int(defval=25, title="Session 1: Start Minute", minval=0, maxval=59)-sess1_stopHour = input(defval=10, title="Session 1: Stop Hour",- type=input.integer, minval=0, maxval=23)+sess1_stopHour = input.int(defval=10, title="Session 1: Stop Hour", minval=0, maxval=23)-sess1_stopMinute = input(defval=25, title="Session 1: Stop Minute",- type=input.integer, minval=0, maxval=59)+sess1_stopMinute = input.int(defval=25, title="Session 1: Stop Minute", minval=0, maxval=59)-sess2_startHour = input(defval=12, title="Session 2: Start Hour",- type=input.integer, minval=0, maxval=23)+sess2_startHour = input.int(defval=12, title="Session 2: Start Hour", minval=0, maxval=23)-sess2_startMinute = input(defval=55, title="Session 2: Start Minute",- type=input.integer, minval=0, maxval=59)+sess2_startMinute = input.int(defval=55, title="Session 2: Start Minute", minval=0, maxval=59)-sess2_stopHour = input(defval=14, title="Session 2: Stop Hour",- type=input.integer, minval=0, maxval=23)+sess2_stopHour = input.int(defval=14, title="Session 2: Stop Hour", minval=0, maxval=23)-sess2_stopMinute = input(defval=55, title="Session 2: Stop Minute",- type=input.integer, minval=0, maxval=59)+sess2_stopMinute = input.int(defval=55, title="Session 2: Stop Minute", minval=0, maxval=59)sess1_closeAll = input(defval=false, title="Close All at End of Session 1")⋯ defval=true)-vwmaLen = input(defval=21, title="VWMA: Length", type=input.integer, minval=1,+vwmaLen = input.int(defval=21, title="VWMA: Length", minval=1, maxval=200)-vwma = vwma(close, vwmaLen)+vwma = ta.vwma(close, vwmaLen)-vwma_high = vwma(high, vwmaLen)+vwma_high = ta.vwma(high, vwmaLen)-vwma_low = vwma(low, vwmaLen)+vwma_low = ta.vwma(low, vwmaLen)if not(useVolume)- vwma := wma(close, vwmaLen)+ vwma := ta.wma(close, vwmaLen)- vwma_high := wma(high, vwmaLen)+ vwma_high := ta.wma(high, vwmaLen)- vwma_low := wma(low, vwmaLen)+ vwma_low := ta.wma(low, vwmaLen)// +1 when above, -1 when below, 0 when inside⋯highband = plot(plotVWMA?fixnan(vwma_high):na, title='VWMA High band', - color = vwma_color, linewidth=1, transp=bandTrans)+ color = color.new(vwma_color, bandTrans), linewidth=1)lowband = plot(plotVWMA?fixnan(vwma_low):na, title='VWMA Low band',- color = vwma_color, linewidth=1, transp=bandTrans)+ color = color.new(vwma_color, bandTrans), linewidth=1)-fill(lowband, highband, title='VWMA Band fill', color=vwma_color,- transp=fillTrans)+fill(lowband, highband, title='VWMA Band fill', color=color.new(vwma_color, fillTrans))-plot(plotVWMA?vwma:na, title='VWMA', color = vwma_color, linewidth=3,- transp=bandTrans)+plot(plotVWMA?vwma:na, title='VWMA', color = color.new(vwma_color, bandTrans), linewidth=3)//==============================================================================⋯ap = hlc3 -esa = ema(ap, n1)+esa = ta.ema(ap, n1)-d = ema(abs(ap - esa), n1)+d = ta.ema(math.abs(ap - esa), n1)ci = (ap - esa) / (0.015 * d)-tci = ema(ci, n2)+tci = ta.ema(ci, n2) wt1 = tci-wt2 = sma(wt1,4)+wt2 = ta.sma(wt1,4)plot(plotWaveTrend?0:na, color=color.gray)⋯plot(plotWaveTrend?wt2:na, color=color.red, style=3)-plot(plotWaveTrend?wt1-wt2:na, color=color.blue, transp=80)+plot(plotWaveTrend?wt1-wt2:na, color=color.new(color.blue, 80))//==============================================================================⋯// Define Long and Short Conditions-longCondition = crossover(wt1, wt2)+longCondition = ta.crossover(wt1, wt2)-shortCondition = crossunder(wt1, wt2)+shortCondition = ta.crossunder(wt1, wt2)// Define Quantities⋯ strategy.position_size < 0 )- orderQty := baseQty * 4 + abs(strategy.position_size)+ orderQty := baseQty * 4 + math.abs(strategy.position_size) else⋯ strategy.position_size < 0 )- orderQty := baseQty * 2 + abs(strategy.position_size)+ orderQty := baseQty * 2 + math.abs(strategy.position_size) else⋯ strategy.position_size < 0 )- orderQty := baseQty * 1 + abs(strategy.position_size)+ orderQty := baseQty * 1 + math.abs(strategy.position_size) else⋯Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 20: input() → input.bool()
- Line 29: input() → input.bool()
- Line 30: input() → input.bool()
- Line 38: input() → input.bool()
- Line 88: input() → input.int()
- Line 89: input() → input.int()
4 more edits
- Line 90: input() → input.int()
- Line 91: input() → input.int()
- Line 92: input() → input.int()
- Line 93: input() → input.int()
⋯baseQty = input.float(defval=1, title="Base Quantity", minval=1)-useSessions = input(defval=true, title="Limit Signals to Trading Sessions?")+useSessions = input.bool(defval=true, title="Limit Signals to Trading Sessions?")sess1_startHour = input.int(defval=8, title="Session 1: Start Hour", minval=0, maxval=23)⋯sess2_stopMinute = input.int(defval=55, title="Session 2: Stop Minute", minval=0, maxval=59)-sess1_closeAll = input(defval=false, title="Close All at End of Session 1")+sess1_closeAll = input.bool(defval=false, title="Close All at End of Session 1")-sess2_closeAll = input(defval=true, title="Close All at End of Session 2")+sess2_closeAll = input.bool(defval=true, title="Close All at End of Session 2")//==============================================================================⋯// check if volume is available for this equity-useVolume = input(+useVolume = input.bool( title="VWMA: Use Volume (uncheck if equity does not have volume)",⋯plotWaveTrend = not(overlay)-n1 = input(10, "Wave Trend: Channel Length")+n1 = input.int(10, "Wave Trend: Channel Length")-n2 = input(21, "Wave Trend: Average Length")+n2 = input.int(21, "Wave Trend: Average Length")-obLevel1 = input(60, "Wave Trend: Over Bought Level 1")+obLevel1 = input.int(60, "Wave Trend: Over Bought Level 1")-obLevel2 = input(53, "Wave Trend: Over Bought Level 2")+obLevel2 = input.int(53, "Wave Trend: Over Bought Level 2")-osLevel1 = input(-60, "Wave Trend: Over Sold Level 1")+osLevel1 = input.int(-60, "Wave Trend: Over Sold Level 1")-osLevel2 = input(-53, "Wave Trend: Over Sold Level 2")+osLevel2 = input.int(-53, "Wave Trend: Over Sold Level 2")ap = hlc3 ⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯//-//@version=5+//@version=6//==============================================================================⋯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 |
|---|---|---|---|
| Base Quantity | 1 | float · min 1 | orderQty line 132 line 138 line 144 line 151 line 157 line 163 |
| Limit Signals to Trading Sessions? | true | bool | line 170 |
| Session 1: Start Hour | 8 | int (written input.integer) · min 0 · max 23 | line 171 line 173 |
| Session 1: Start Minute | 25 | int (written input.integer) · min 0 · max 59 | line 171 |
| Session 1: Stop Hour | 10 | int (written input.integer) · min 0 · max 23 | close_all line 173 line 175 line 194 |
| Session 1: Stop Minute | 25 | int (written input.integer) · min 0 · max 59 | close_all line 175 line 194 |
| Session 2: Start Hour | 12 | int (written input.integer) · min 0 · max 23 | line 177 line 179 |
| Session 2: Start Minute | 55 | int (written input.integer) · min 0 · max 59 | line 177 |
| Session 2: Stop Hour | 14 | int (written input.integer) · min 0 · max 23 | close_all line 179 line 181 line 198 |
| Session 2: Stop Minute | 55 | int (written input.integer) · min 0 · max 59 | close_all line 181 line 198 |
| Close All at End of Session 1 | false | bool | close_all line 194 |
| Close All at End of Session 2 | true | bool | close_all line 198 |
| VWMA: Use Volume (uncheck if equity does not have volume) | true | bool | line 54 |
| VWMA: Length | 21 | int (written input.integer) · min 1 · max 200 | vwma vwma_high vwma_low |
| Wave Trend: Channel Length | 10 | int | esa d |
| Wave Trend: Average Length | 21 | int | tci |
| Wave Trend: Over Bought Level 1 | 60 | int | plot |
| Wave Trend: Over Bought Level 2 | 53 | int | plot |
| Wave Trend: Over Sold Level 1 | -60 | int | plot |
| Wave Trend: Over Sold Level 2 | -53 | int | plot |
What it calculates
- VWMA / WMA (
vwma,ta.vwmain v5)close, VWMA: Length (21)vwma · line 51 - VWMA / WMA (
vwma,ta.vwmain v5)high, VWMA: Length (21)vwma_high · line 52 - VWMA / WMA (
vwma,ta.vwmain v5)low, VWMA: Length (21)vwma_low · line 53 - EMA (
ema,ta.emain v5)ap, Wave Trend: Channel Length (10)esa · line 105 - EMA (
ema,ta.emain v5)abs(ap - esa), Wave Trend: Channel Length (10)d · line 106 - EMA (
ema,ta.emain v5)ci, Wave Trend: Average Length (21)tci · line 108 - SMA (
sma,ta.smain v5)wt1, 4wt2 · line 111 - Crossover (
crossover,ta.crossoverin v5)wt1, wt2longCondition · line 126 - Crossunder (
crossunder,ta.crossunderin v5)wt1, wt2shortCondition · line 127
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 |
|---|---|---|---|
| order Buy long | ( longCondition and newTrades ) | On | 189 |
| order Sell short | ( shortCondition and newTrades ) | On | 192 |
| Close | (sess1_closeAll and hour == sess1_stopHour and minute >= sess1_stopMinute ) | On | 195 |
| Close | (sess2_closeAll and hour == sess2_stopHour and minute >= sess2_stopMinute ) | On | 199 |
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 | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 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.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 0.0% | 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 |
|---|---|---|---|---|---|
| Wave Trend w- VWMA overlay this page | — | v4 strategy | 0.0% | 0 | 0.0% |
| Forex SWING Trader by SoftKill21 | wma ema sma | v4 strategy | No trades on this market | ||
| tvbot Trend Following with Mean Reversion algo by tvbot- | ema vwma wma | v5 strategy | No trades on this market | ||
| DRSI DMA Scalping Strategy No Repaint by allenlk | sma wma ema | v4 strategy | −99.5% | 44 | 137.7% |
| High-Low Channel Multi averages Crypto Swing strategy by exlux99 | sma ema wma vwma | v4 strategy | No trades on this market | ||
| Open Close Cross Strategy plus Explorer by roses27 | sma ema wma vwma | v4 strategy | does not run in Zeal Terminal | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 43 ms | Yes 1,000 bars in 83 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
“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///// Created by jadamcraig // // This strategy benefits from extracts taken from the following// studies/authors. Thank you for developing and sharing your ideas in an open// way!// * Wave Trend Strategy by thomas.gigure// * cRSI + Waves Strategy with VWMA overlay by Dr_Roboto////@version=4//==============================================================================//==============================================================================overlay = true // plots VWMA (need to close and re-add)//overlay = false // plots Wave Trend (need to close and re-add)strategy("Wave Trend w/ VWMA overlay", overlay=overlay) baseQty = input(defval=1, title="Base Quantity", type=input.float, minval=1)useSessions = input(defval=true, title="Limit Signals to Trading Sessions?")sess1_startHour = input(defval=8, title="Session 1: Start Hour", type=input.integer, minval=0, maxval=23)sess1_startMinute = input(defval=25, title="Session 1: Start Minute", type=input.integer, minval=0, maxval=59)sess1_stopHour = input(defval=10, title="Session 1: Stop Hour", type=input.integer, minval=0, maxval=23)sess1_stopMinute = input(defval=25, title="Session 1: Stop Minute", type=input.integer, minval=0, maxval=59)sess2_startHour = input(defval=12, title="Session 2: Start Hour", type=input.integer, minval=0, maxval=23)sess2_startMinute = input(defval=55, title="Session 2: Start Minute", type=input.integer, minval=0, maxval=59)sess2_stopHour = input(defval=14, title="Session 2: Stop Hour", type=input.integer, minval=0, maxval=23)sess2_stopMinute = input(defval=55, title="Session 2: Stop Minute", type=input.integer, minval=0, maxval=59)sess1_closeAll = input(defval=false, title="Close All at End of Session 1")sess2_closeAll = input(defval=true, title="Close All at End of Session 2")//==============================================================================//==============================================================================// Volume Weighted Moving Average (VWMA)//==============================================================================//==============================================================================plotVWMA = overlay// check if volume is available for this equityuseVolume = input( title="VWMA: Use Volume (uncheck if equity does not have volume)", defval=true)vwmaLen = input(defval=21, title="VWMA: Length", type=input.integer, minval=1, maxval=200)vwma = vwma(close, vwmaLen)vwma_high = vwma(high, vwmaLen)vwma_low = vwma(low, vwmaLen)if not(useVolume) vwma := wma(close, vwmaLen) vwma_high := wma(high, vwmaLen) vwma_low := wma(low, vwmaLen)// +1 when above, -1 when below, 0 when insidevwmaSignal(priceOpen, priceClose, vwmaHigh, vwmaLow) => sig = 0 color = color.gray if priceClose > vwmaHigh sig := 1 color := color.green else if priceClose < vwmaLow sig := -1 color := color.red else sig := 0 color := color.gray [sig,color][vwma_sig, vwma_color] = vwmaSignal(open, close, vwma_high, vwma_low)priceAboveVWMA = vwma_sig == 1 ? true : falsepriceBelowVWMA = vwma_sig == -1 ? true : false// plot(priceAboveVWMA?2.0:0,color=color.blue)// plot(priceBelowVWMA?2.0:0,color=color.maroon)//bandTrans = input(defval=70, title="VWMA Band Transparancy (100 invisible)",// type=input.integer, minval=0, maxval=100)//fillTrans = input(defval=70, title="VWMA Fill Transparancy (100 invisible)",// type=input.integer, minval=0, maxval=100)bandTrans = 60fillTrans = 60// ***** Plot VWMA *****highband = plot(plotVWMA?fixnan(vwma_high):na, title='VWMA High band', color = vwma_color, linewidth=1, transp=bandTrans)lowband = plot(plotVWMA?fixnan(vwma_low):na, title='VWMA Low band', color = vwma_color, linewidth=1, transp=bandTrans)fill(lowband, highband, title='VWMA Band fill', color=vwma_color, transp=fillTrans)plot(plotVWMA?vwma:na, title='VWMA', color = vwma_color, linewidth=3, transp=bandTrans)//==============================================================================//==============================================================================// Wave Trend//==============================================================================//==============================================================================plotWaveTrend = not(overlay)n1 = input(10, "Wave Trend: Channel Length")n2 = input(21, "Wave Trend: Average Length")obLevel1 = input(60, "Wave Trend: Over Bought Level 1")obLevel2 = input(53, "Wave Trend: Over Bought Level 2")osLevel1 = input(-60, "Wave Trend: Over Sold Level 1")osLevel2 = input(-53, "Wave Trend: Over Sold Level 2")ap = hlc3 esa = ema(ap, n1)d = ema(abs(ap - esa), n1)ci = (ap - esa) / (0.015 * d)tci = ema(ci, n2) wt1 = tciwt2 = sma(wt1,4)plot(plotWaveTrend?0:na, color=color.gray)plot(plotWaveTrend?obLevel1:na, color=color.red)plot(plotWaveTrend?osLevel1:na, color=color.green)plot(plotWaveTrend?obLevel2:na, color=color.red, style=3)plot(plotWaveTrend?osLevel2:na, color=color.green, style=3)plot(plotWaveTrend?wt1:na, color=color.green)plot(plotWaveTrend?wt2:na, color=color.red, style=3)plot(plotWaveTrend?wt1-wt2:na, color=color.blue, transp=80)//==============================================================================//==============================================================================// Order Management//==============================================================================//==============================================================================// Define Long and Short ConditionslongCondition = crossover(wt1, wt2)shortCondition = crossunder(wt1, wt2)// Define QuantitiesorderQty = baseQty * 2if (longCondition) if (vwma_sig == 1) if ( strategy.position_size >= (baseQty * 4 * -1) and strategy.position_size < 0 ) orderQty := baseQty * 4 + abs(strategy.position_size) else orderQty := baseQty * 4 else if (vwma_sig == 0) if ( strategy.position_size >= (baseQty * 2 * -1) and strategy.position_size < 0 ) orderQty := baseQty * 2 + abs(strategy.position_size) else orderQty := baseQty * 2 else if (vwma_sig == -1) if ( strategy.position_size >= (baseQty * 1 * -1) and strategy.position_size < 0 ) orderQty := baseQty * 1 + abs(strategy.position_size) else orderQty := baseQty * 1else if (shortCondition) if (vwma_sig == -1) if ( strategy.position_size <= (baseQty * 4) and strategy.position_size > 0 ) orderQty := baseQty * 4 + strategy.position_size else orderQty := baseQty * 4 else if (vwma_sig == 0) if ( strategy.position_size <= (baseQty * 2) and strategy.position_size > 2 ) orderQty := baseQty * 2 + strategy.position_size else orderQty := baseQty * 2 else if (vwma_sig == 1) if ( strategy.position_size <= (baseQty * 1) and strategy.position_size > 0 ) orderQty := baseQty * 1 + strategy.position_size else orderQty := baseQty * 1// Determine if new trades are permittednewTrades = falseif (useSessions) if ( hour == sess1_startHour and minute >= sess1_startMinute ) newTrades := true else if ( hour > sess1_startHour and hour < sess1_stopHour ) newTrades := true else if ( hour == sess1_stopHour and minute < sess1_stopMinute ) newTrades := true else if ( hour == sess2_startHour and minute >= sess2_startMinute ) newTrades := true else if ( hour > sess2_startHour and hour < sess2_stopHour ) newTrades := true else if ( hour == sess2_stopHour and minute < sess2_stopMinute ) newTrades := true else newTrades := falseelse newTrades := true// Long Signalsif ( longCondition and newTrades ) strategy.order("Buy", strategy.long, orderQty)// Short Signalsif ( shortCondition and newTrades ) strategy.order("Sell", strategy.short, orderQty)// Close open position at end of Session 1, if enabledif (sess1_closeAll and hour == sess1_stopHour and minute >= sess1_stopMinute ) strategy.close_all() // Close open position at end of Session 2, if enabledif (sess2_closeAll and hour == sess2_stopHour and minute >= sess2_stopMinute ) strategy.close_all()