Pine Script v4 · Strategy
Lawyers Trend Pro Strategy
A Pine Script v4 strategy built on SMA (src, 20), Stdev (src, 20) and Lowest (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 is one contract and pays no commission. It has no settings.
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 Lawyers Trend Pro Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 27 of 27 trades.
- How did Lawyers Trend Pro Strategy do on BTCUSDT 1D with default settings?
- +12.06%
- From 26 Jan 2024 to 21 Oct 2026, over 102 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Lawyers Trend Pro Strategy 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 Lawyers Trend Pro Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Lawyers Trend Pro Strategy run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 22 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +12.06%
- $12,063.60
- Buy and hold
- +102.5%
- same period
- Closed trades
- 102
- 26 won · 76 lost
- Profitable
- 25.5%
- of closed trades
- Profit factor
- 1.08
- gross profit ÷ gross loss
- Max drawdown
- 41.74%
- −$46,338.60
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short 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.
-
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 37, 38, 40, 41. The upgraded version below moves each call inside an if block.
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 sma → ta.sma, stdev → ta.stdev, lowest → ta.lowest, highest → ta.highest, avg → math.avg, crossover → ta.crossover.
- 4 strategy calls use the when = argument (line 37, 38, 40, 41). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 102 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 7: sma → ta.sma
- Line 8: stdev → ta.stdev
- Line 12: lowest → ta.lowest
- Line 13: highest → ta.highest
- Line 14: avg → math.avg
4 more edits
- Line 27: crossover → ta.crossover
- Line 29: crossover → ta.crossover
- Line 37: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 40: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// © ErdemDemir-//@version=4+//@version=5strategy("Lawyers Trend Pro Strategy", shorttitle="Lawyers Trend Pro Strategy", overlay=true)⋯mult = 2.0-basis = sma(src, 20)+basis = ta.sma(src, 20)-dev = mult * stdev(src, 20)+dev = mult * ta.stdev(src, 20)upper = basis + dev⋯offset = 0-lower2 = lowest(20)+lower2 = ta.lowest(20)-upper2 = highest(20)+upper2 = ta.highest(20)-basis2 = avg(upper2, lower2)+basis2 = math.avg(upper2, lower2)MB= (basis+basis2)/2⋯// Buy only if the buy signal is triggered and we are not already long-buySignal = not isLong and crossover(close,MB)+buySignal = not isLong and ta.crossover(close,MB)// Sell only if the sell signal is triggered and we are not already short-sellSignal= not isShort and crossover(MB,close)+sellSignal= not isShort and ta.crossover(MB,close)if (buySignal)⋯/// LONG-strategy.entry("long", true , when = buySignal, comment="Open Long")+strategy.entry("long", strategy.long , when = buySignal, comment="Open Long")strategy.close("long", when=sellSignal, comment = "Close Long")/// SHORT-strategy.entry("short", false, when = sellSignal, comment="Open Short")+strategy.entry("short", strategy.short, when = sellSignal, comment="Open Short")strategy.close("short", when=buySignal, comment = "Close Short")Same 102 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 37: when = buySignal → if block
- Line 38: when = sellSignal → if block
- Line 40: when = sellSignal → if block
- Line 41: when = buySignal → if block
⋯/// LONG-strategy.entry("long", strategy.long , when = buySignal, comment="Open Long")+if buySignal+ strategy.entry("long", strategy.long , comment="Open Long")-strategy.close("long", when=sellSignal, comment = "Close Long")+if sellSignal+ strategy.close("long", comment = "Close Long")/// SHORT-strategy.entry("short", strategy.short, when = sellSignal, comment="Open Short")+if sellSignal+ strategy.entry("short", strategy.short, comment="Open Short")-strategy.close("short", when=buySignal, comment = "Close Short")+if buySignal+ strategy.close("short", comment = "Close Short")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: 102 before, 64 after on BTCUSDT 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.
⋯// © ErdemDemir-//@version=5+//@version=6strategy("Lawyers Trend Pro Strategy", shorttitle="Lawyers Trend Pro Strategy", overlay=true)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
The script declares no settings.
What it calculates
- SMA (
sma,ta.smain v5)src, 20basis · line 7 - Stdev (
stdev,ta.stdevin v5)src, 20dev · line 8 - Lowest (
lowest,ta.lowestin v5)20lower2 · line 12 - Highest (
highest,ta.highestin v5)20upper2 · line 13
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 | buySignalnot isLong and crossover(close,MB) | On | 37 |
| Close long | sellSignalnot isShort and crossover(MB,close) | On | 38 |
| Open short short | sellSignalnot isShort and crossover(MB,close) | On | 40 |
| Close short | buySignalnot isLong and crossover(close,MB) | On | 41 |
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, and the live replay matched history.
- 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 | +12.1% | +102.5% | 102 | 25% | 1.08 | 41.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +3.8% | +5.5% | 105 | 25% | 1.07 | 13.8% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +1.2% | +9.8% | 98 | 27% | 1.14 | 1.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.7% | +8.4% | 147 | 18% | 0.73 | 1.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.1% | +16.7% | 106 | 32% | 1.18 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 121 | 22% | 1.09 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 106 | 25% | 1.01 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.1% | +17.1% | 137 | 24% | 0.78 | 0.2% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 36 | 25% | −$21,448.00 |
| Sideways market | 41 | 32% | $22,570.20 |
| Falling market | 25 | 16% | $10,941.40 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
57.5%
The 95th percentile of the worst drawdown when the same 102 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 30.9% to 57.5%; the tick is what actually happened, 40.9%. Order luck alone moves it this much.
All 102 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 20 Mar 2024 61,937.40 | 21 Mar 2024 67,840.50 | 1 | −$5,903.10 |
| long | 21 Mar 2024 67,840.50 | 22 Mar 2024 65,501.30 | 1 | −$2,339.23 |
| short | 22 Mar 2024 65,501.30 | 25 Mar 2024 67,210.00 | 3 | −$1,708.72 |
| long | 25 Mar 2024 67,210.00 | 3 Apr 2024 65,464.00 | 9 | −$1,746.01 |
| short | 3 Apr 2024 65,464.00 | 5 Apr 2024 68,487.80 | 2 | −$3,023.81 |
| long | 5 Apr 2024 68,487.80 | 13 Apr 2024 67,116.50 | 8 | −$1,371.28 |
| short | 13 Apr 2024 67,116.50 | 23 Apr 2024 66,819.30 | 10 | $297.20 |
| long | 23 Apr 2024 66,819.30 | 25 Apr 2024 64,289.60 | 2 | −$2,529.74 |
| short | 25 Apr 2024 64,289.60 | 4 May 2024 62,882.00 | 9 | $1,407.57 |
| long | 4 May 2024 62,882.00 | 8 May 2024 62,312.10 | 4 | −$569.94 |
| short | 8 May 2024 62,312.10 | 10 May 2024 63,074.00 | 2 | −$761.93 |
| long | 10 May 2024 63,074.00 | 11 May 2024 60,800.00 | 1 | −$2,274.01 |
| short | 11 May 2024 60,800.00 | 14 May 2024 62,940.10 | 3 | −$2,140.10 |
| long | 14 May 2024 62,940.10 | 15 May 2024 61,577.50 | 1 | −$1,362.60 |
| short | 15 May 2024 61,577.50 | 16 May 2024 66,206.50 | 1 | −$4,629.02 |
| long | 16 May 2024 66,206.50 | 12 Jun 2024 67,314.20 | 27 | $1,107.72 |
| short | 12 Jun 2024 67,314.20 | 14 Jul 2024 59,204.00 | 32 | $8,110.22 |
| long | 14 Jul 2024 59,204.00 | 3 Aug 2024 61,498.30 | 20 | $2,294.33 |
| short | 3 Aug 2024 61,498.30 | 9 Aug 2024 61,686.00 | 6 | −$187.66 |
| long | 9 Aug 2024 61,686.00 | 10 Aug 2024 60,838.00 | 1 | −$848.01 |
| short | 10 Aug 2024 60,838.00 | 20 Aug 2024 59,438.50 | 10 | $1,399.49 |
| long | 20 Aug 2024 59,438.50 | 28 Aug 2024 59,415.00 | 8 | −$23.50 |
| short | 28 Aug 2024 59,415.00 | 14 Sep 2024 60,498.00 | 17 | −$1,082.99 |
| long | 14 Sep 2024 60,498.00 | 2 Oct 2024 60,804.90 | 18 | $306.93 |
| short | 2 Oct 2024 60,804.90 | 7 Oct 2024 62,819.90 | 5 | −$2,014.99 |
| long | 7 Oct 2024 62,819.90 | 8 Oct 2024 62,224.00 | 1 | −$595.90 |
| short | 8 Oct 2024 62,224.00 | 13 Oct 2024 63,206.20 | 5 | −$982.22 |
| long | 13 Oct 2024 63,206.20 | 4 Nov 2024 68,776.00 | 22 | $5,569.76 |
| short | 4 Nov 2024 68,776.00 | 6 Nov 2024 69,372.00 | 2 | −$596.02 |
| long | 6 Nov 2024 69,372.00 | 11 Dec 2024 96,593.00 | 35 | $27,221.00 |
| short | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | −$4,532.00 |
| long | 12 Dec 2024 101,125.00 | 20 Dec 2024 97,461.90 | 8 | −$3,663.14 |
| short | 20 Dec 2024 97,461.90 | 7 Jan 2025 102,236.00 | 18 | −$4,773.74 |
| long | 7 Jan 2025 102,236.00 | 9 Jan 2025 95,060.60 | 2 | −$7,174.99 |
| short | 9 Jan 2025 95,060.60 | 15 Jan 2025 96,560.90 | 6 | −$1,500.24 |
| long | 15 Jan 2025 96,560.90 | 2 Feb 2025 100,636.00 | 18 | $4,074.81 |
| short | 2 Feb 2025 100,636.00 | 21 Feb 2025 98,305.00 | 19 | $2,330.65 |
| long | 21 Feb 2025 98,305.00 | 22 Feb 2025 96,182.00 | 1 | −$2,123.02 |
| short | 22 Feb 2025 96,182.00 | 3 Mar 2025 94,270.00 | 9 | $1,912.00 |
| long | 3 Mar 2025 94,270.00 | 4 Mar 2025 86,221.20 | 1 | −$8,048.83 |
| short | 4 Mar 2025 86,221.20 | 6 Mar 2025 90,606.00 | 2 | −$4,384.84 |
| long | 6 Mar 2025 90,606.00 | 7 Mar 2025 89,931.90 | 1 | −$674.12 |
| short | 7 Mar 2025 89,931.90 | 20 Mar 2025 86,845.90 | 13 | $3,085.95 |
| long | 20 Mar 2025 86,845.90 | 21 Mar 2025 84,223.40 | 1 | −$2,622.55 |
| short | 21 Mar 2025 84,223.40 | 24 Mar 2025 86,082.50 | 3 | −$1,859.12 |
| long | 24 Mar 2025 86,082.50 | 30 Mar 2025 82,648.50 | 6 | −$3,433.97 |
| short | 30 Mar 2025 82,648.50 | 2 Apr 2025 85,158.40 | 3 | −$2,509.82 |
| long | 2 Apr 2025 85,158.40 | 3 Apr 2025 82,516.30 | 1 | −$2,642.07 |
| short | 3 Apr 2025 82,516.30 | 10 Apr 2025 82,615.20 | 7 | −$98.94 |
| long | 10 Apr 2025 82,615.20 | 11 Apr 2025 79,607.30 | 1 | −$3,007.92 |
| short | 11 Apr 2025 79,607.30 | 12 Apr 2025 83,423.80 | 1 | −$3,816.53 |
| long | 12 Apr 2025 83,423.80 | 30 May 2025 105,590.00 | 48 | $22,165.90 |
| short | 30 May 2025 105,590.00 | 10 Jun 2025 110,263.00 | 11 | −$4,673.27 |
| long | 10 Jun 2025 110,263.00 | 13 Jun 2025 105,672.00 | 3 | −$4,591.28 |
| short | 13 Jun 2025 105,672.00 | 14 Jun 2025 106,067.00 | 1 | −$394.85 |
| long | 14 Jun 2025 106,067.00 | 15 Jun 2025 105,415.00 | 1 | −$651.96 |
| short | 15 Jun 2025 105,415.00 | 17 Jun 2025 106,795.00 | 2 | −$1,379.90 |
| long | 17 Jun 2025 106,795.00 | 18 Jun 2025 104,551.00 | 1 | −$2,243.36 |
| short | 18 Jun 2025 104,551.00 | 24 Jun 2025 105,334.00 | 6 | −$782.77 |
| long | 24 Jun 2025 105,334.00 | 31 Jul 2025 117,840.00 | 37 | $12,506.30 |
| short | 31 Jul 2025 117,840.00 | 8 Aug 2025 117,472.00 | 8 | $368.27 |
| long | 8 Aug 2025 117,472.00 | 16 Aug 2025 117,342.00 | 8 | −$129.98 |
| short | 16 Aug 2025 117,342.00 | 9 Sep 2025 112,065.00 | 24 | $5,276.81 |
| long | 9 Sep 2025 112,065.00 | 10 Sep 2025 111,546.00 | 1 | −$518.85 |
| short | 10 Sep 2025 111,546.00 | 11 Sep 2025 113,960.00 | 1 | −$2,413.62 |
| long | 11 Sep 2025 113,960.00 | 23 Sep 2025 112,651.00 | 12 | −$1,309.01 |
| short | 23 Sep 2025 112,651.00 | 30 Sep 2025 114,312.00 | 7 | −$1,660.98 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$1,537.48 |
| short | 11 Oct 2025 112,774.00 | 27 Oct 2025 114,559.00 | 16 | −$1,784.92 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 110,021.00 | 3 | −$4,538.11 |
| short | 30 Oct 2025 110,021.00 | 3 Nov 2025 110,541.00 | 4 | −$519.39 |
| long | 3 Nov 2025 110,541.00 | 4 Nov 2025 106,583.00 | 1 | −$3,957.64 |
| short | 4 Nov 2025 106,583.00 | 4 Dec 2025 93,429.90 | 30 | $13,153.10 |
| long | 4 Dec 2025 93,429.90 | 15 Dec 2025 88,172.20 | 11 | −$5,257.79 |
| short | 15 Dec 2025 88,172.20 | 2 Jan 2026 88,839.10 | 18 | −$666.89 |
| long | 2 Jan 2026 88,839.10 | 21 Jan 2026 88,427.70 | 19 | −$411.39 |
| short | 21 Jan 2026 88,427.70 | 26 Feb 2026 67,988.00 | 36 | $20,439.60 |
| long | 26 Feb 2026 67,988.00 | 27 Feb 2026 67,485.20 | 1 | −$502.85 |
| short | 27 Feb 2026 67,485.20 | 3 Mar 2026 68,830.10 | 4 | −$1,344.87 |
| long | 3 Mar 2026 68,830.10 | 8 Mar 2026 67,262.90 | 5 | −$1,567.15 |
| short | 8 Mar 2026 67,262.90 | 10 Mar 2026 68,432.20 | 2 | −$1,169.25 |
| long | 10 Mar 2026 68,432.20 | 22 Mar 2026 68,918.10 | 12 | $485.96 |
| short | 22 Mar 2026 68,918.10 | 24 Mar 2026 70,906.40 | 2 | −$1,988.33 |
| long | 24 Mar 2026 70,906.40 | 27 Mar 2026 68,820.30 | 3 | −$2,086.14 |
| short | 27 Mar 2026 68,820.30 | 8 Apr 2026 71,924.20 | 12 | −$3,103.91 |
| long | 8 Apr 2026 71,924.20 | 16 May 2026 79,113.20 | 38 | $7,188.98 |
| short | 16 May 2026 79,113.20 | 23 Jun 2026 64,020.00 | 38 | $15,093.20 |
| long | 23 Jun 2026 64,020.00 | 24 Jun 2026 62,734.60 | 1 | −$1,285.44 |
| short | 24 Jun 2026 62,734.60 | 4 Jul 2026 62,583.30 | 10 | $151.31 |
| long | 4 Jul 2026 62,583.30 | 25 Jul 2026 64,140.00 | 21 | $1,556.74 |
| short | 25 Jul 2026 64,140.00 | 26 Jul 2026 64,375.00 | 1 | −$235.01 |
| long | 26 Jul 2026 64,375.00 | 28 Jul 2026 63,755.90 | 2 | −$619.15 |
| short | 28 Jul 2026 63,755.90 | 31 Jul 2026 64,780.00 | 3 | −$1,024.17 |
| long | 31 Jul 2026 64,780.00 | 1 Aug 2026 62,887.90 | 1 | −$1,892.15 |
| short | 1 Aug 2026 62,887.90 | 6 Aug 2026 64,665.20 | 5 | −$1,777.36 |
| long | 6 Aug 2026 64,665.20 | 7 Aug 2026 64,323.60 | 1 | −$341.63 |
| short | 7 Aug 2026 64,323.60 | 8 Aug 2026 64,923.20 | 1 | −$599.59 |
| long | 8 Aug 2026 64,923.20 | 11 Aug 2026 63,970.00 | 3 | −$953.19 |
| short | 11 Aug 2026 63,970.00 | 18 Aug 2026 64,532.10 | 7 | −$562.10 |
| long | 18 Aug 2026 64,532.10 | 11 Sep 2026 76,568.70 | 24 | $12,036.60 |
| short | 11 Sep 2026 76,568.70 | 19 Sep 2026 80,883.90 | 8 | −$4,315.13 |
| long | 19 Sep 2026 80,883.90 | 9 Oct 2026 81,754.50 | 20 | $870.60 |
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 |
|---|---|---|---|---|---|
| Lawyers Trend Pro Strategy this page | — | v4 strategy | +12.1% | 102 | 41.7% |
| BTC Volatility Band Strategy by gary_trades | sma stdev lowest highest | v4 strategy | −33.5% | 80 | 45.0% |
| MACandles-LinearRegression-Strategy by Trendoscope | stdev sma highest lowest | v5 strategy | +26.7% | 3 | 46.7% |
| VixFixLinReg-Strategy by Trendoscope | highest stdev sma lowest | v4 strategy | −49.3% | 12 | 51.1% |
| Chandelier + BB + EMAS by juanchez | highest lowest sma stdev | v4 strategy | −20.6% | 10 | 38.6% |
| Crunchster's Turtle and Trend System by Crunchster1 | lowest highest stdev sma | v5 strategy | +18.0% | 31 | 16.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | With a workaround 1,000 bars in 22 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 37, 40) 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/// © ErdemDemir//@version=4strategy("Lawyers Trend Pro Strategy", shorttitle="Lawyers Trend Pro Strategy", overlay=true)src = closemult = 2.0basis = sma(src, 20)dev = mult * stdev(src, 20)upper = basis + devlower = basis - devoffset = 0lower2 = lowest(20)upper2 = highest(20)basis2 = avg(upper2, lower2)MB= (basis+basis2)/2col1=close>MBcol3=MB>closecolorE = col1 ? color.blue : col3 ? color.red : color.yellowp3=plot(MB, color=colorE, linewidth=3)// Deternine if we are currently LONGisLong = falseisLong := nz(isLong[1], false)// Determine if we are currently SHORTisShort = falseisShort := nz(isShort[1], false)// Buy only if the buy signal is triggered and we are not already longbuySignal = not isLong and crossover(close,MB)// Sell only if the sell signal is triggered and we are not already shortsellSignal= not isShort and crossover(MB,close)if (buySignal) isLong := true isShort := falseif (sellSignal) isLong := false isShort := true/// LONGstrategy.entry("long", true , when = buySignal, comment="Open Long")strategy.close("long", when=sellSignal, comment = "Close Long")/// SHORTstrategy.entry("short", false, when = sellSignal, comment="Open Short")strategy.close("short", when=buySignal, comment = "Close Short")