Pine Script v4 · Strategy
Volume and Moving average,will this model working in real-trade-
A Pine Script v4 strategy built on SMA (close, 1), RSI (close, 14) and Stdev (close, 20). It has 9 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 0.1% commission. 15 settings; defaults include Length1 1, Length3 3 and Length7 7.
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 Volume and Moving average,will this model working in real-trade- repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
- How did Volume and Moving average,will this model working in real-trade- do on BTCUSDT 1D with default settings?
- −157,995.00%
- From 26 Jan 2024 to 21 Oct 2026, over 10 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Volume and Moving average,will this model working in real-trade- 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 Volume and Moving average,will this model working in real-trade- use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Volume and Moving average,will this model working in real-trade- run in Zeal Terminal?
- Yes
- It compiles in 30 ms and runs 1,000 bars in 65 ms, in the browser.
BTCUSDT · 1D · default settings
- Basis
- Upper
- Lower
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −157,995.00%
- −$1,579.95
- Buy and hold
- +102.5%
- same period
- Closed trades
- 10
- 7 won · 3 lost
- Profitable
- 70.0%
- of closed trades
- Profit factor
- 0.51
- gross profit ÷ gross loss
- Max drawdown
- 4,752.14%
- −$2,897.76
One run with the author's default settings, $1 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Note
8 settings have no label
In the settings dialog length1 (line 6), length3 (line 7), length7 (line 8), length14 (line 9), length20 (line 10), length60 (line 11), length120 (line 12), length (line 31) 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 iff(), which v5 removed line 22
iff() on line 22, 23, 24. v5 writes it as the ternary c ? a : b.
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, rsi → ta.rsi, stdev → ta.stdev, highest → ta.highest, valuewhen → ta.valuewhen, crossunder → ta.crossunder.
v4 → v5
VerifiedSame 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 13: sma → ta.sma
- Line 14: sma → ta.sma
- Line 15: sma → ta.sma
- Line 16: sma → ta.sma
- Line 17: sma → ta.sma
18 more edits
- Line 18: sma → ta.sma
- Line 19: sma → ta.sma
- Line 20: rsi → ta.rsi
- Line 22: iff(c, a, b) → (c ? a : b)
- Line 23: iff(c, a, b) → (c ? a : b)
- Line 24: iff(c, a, b) → (c ? a : b)
- Line 25: input(type = input.integer) → input.int()
- Line 26: input(type = input.integer) → input.int()
- Line 28: sma → ta.sma
- Line 29: sma → ta.sma
- Line 36: sma → ta.sma
- Line 37: stdev → ta.stdev
- Line 40: stdev → ta.stdev
- Line 43: stdev → ta.stdev
- Line 46: input(type = input.integer) → input.int()
- Line 57: highest → ta.highest
- Line 59: valuewhen → ta.valuewhen
- Line 77: crossunder → ta.crossunder
⋯// © KAIST291-//@version=4+//@version=5strategy("prototype",initial_capital=1,commission_type=strategy.commission.percent,commission_value=0.1, format=format.volume, precision=0,overlay=true)⋯length120=input(120)-ma1= sma(close,length1)+ma1= ta.sma(close,length1)-ma3= sma(close,length3)+ma3= ta.sma(close,length3)-ma7= sma(close,length7)+ma7= ta.sma(close,length7)-ma14=sma(close,length14)+ma14=ta.sma(close,length14)-ma20=sma(close,length20)+ma20=ta.sma(close,length20)-ma60=sma(close,length60)+ma60=ta.sma(close,length60)-ma120=sma(close,length120)+ma120=ta.sma(close,length120)-rsi=rsi(close,14)+rsi=ta.rsi(close,14)// BUYING VOLUME AND SELLING VOLUME //-BV = iff( (high==low), 0, volume*(close-low)/(high-low))+BV = ( (high==low) ? 0 : volume*(close-low)/(high-low))-SV = iff( (high==low), 0, volume*(high-close)/(high-low))+SV = ( (high==low) ? 0 : volume*(high-close)/(high-low))-vol = iff(volume > 0, volume, 1)+vol = (volume > 0 ? volume : 1)-dailyLength = input(title = "Daily MA length", type = input.integer, defval = 50, minval = 1, maxval = 100)+dailyLength = input.int(title = "Daily MA length", defval = 50, minval = 1, maxval = 100)-weeklyLength = input(title = "Weekly MA length", type = input.integer, defval = 10, minval = 1, maxval = 100)+weeklyLength = input.int(title = "Weekly MA length", defval = 10, minval = 1, maxval = 100)//------------------------------------------------------------Davgvol = sma(volume, dailyLength)+Davgvol = ta.sma(volume, dailyLength)-Wavgvol = sma(volume, weeklyLength)+Wavgvol = ta.sma(volume, weeklyLength)//-----------------------------------------------------------⋯mult3= input(1.0, minval=0.001, maxval=50, title="exp1")-basis = sma(src, length)+basis = ta.sma(src, length)-dev = mult * stdev(src, length)+dev = mult * ta.stdev(src, length)upper = basis + devlower = basis - dev-dev2= mult2 * stdev(src, length)+dev2= mult2 * ta.stdev(src, length)Supper= basis + dev2Slower= basis - dev2-dev3= mult3 * stdev(src, length)+dev3= mult3 * ta.stdev(src, length)upper1= basis + dev3lower1= basis - dev3-offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)+offset = input.int(0, "Offset", minval = -500, maxval = 500)plot(basis, "Basis", color=#FF6D00, offset = offset)⋯bear=(close<Slower and close<lower and SV>BV and SV>Wavgvol)-hi=highest(exit,10)+hi=ta.highest(exit,10)imInATrade = strategy.position_size != 0-highestPriceAfterEntry = valuewhen(imInATrade, high, 0)+highestPriceAfterEntry = ta.valuewhen(imInATrade, high, 0)// STRATEGY LONG //⋯//////////////////////////////////////////////////////////////////////////////////-if (bear and close<ma3 and crossunder(ma60,ma120))+if (bear and close<ma3 and ta.crossunder(ma60,ma120)) strategy.entry("Short",strategy.short,0.1)⋯Same 10 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 7: input() → input.int()
- Line 8: input() → input.int()
- Line 9: input() → input.int()
- Line 10: input() → input.int()
- Line 11: input() → input.int()
6 more edits
- Line 12: input() → input.int()
- Line 31: input() → input.int()
- Line 32: input() → input.source()
- Line 33: input() → input.float()
- Line 34: input() → input.float()
- Line 35: input() → input.float()
⋯// SETTING //-length1=input(1)+length1=input.int(1)-length3=input(3)+length3=input.int(3)-length7=input(7)+length7=input.int(7)-length14=input(14)+length14=input.int(14)-length20=input(20)+length20=input.int(20)-length60=input(60)+length60=input.int(60)-length120=input(120)+length120=input.int(120)ma1= ta.sma(close,length1)⋯//------------------------------------------------------------length = input(20, minval=1)+length = input.int(20, minval=1)-src = input(close, title="Source")+src = input.source(close, title="Source")-mult = input(2.0, minval=0.001, maxval=50, title="StdDev")+mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")-mult2= input(1.5, minval=0.001, maxval=50, title="exp")+mult2= input.float(1.5, minval=0.001, maxval=50, title="exp")-mult3= input(1.0, minval=0.001, maxval=50, title="exp1")+mult3= input.float(1.0, minval=0.001, maxval=50, title="exp1")basis = ta.sma(src, length)⋯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: 10 before, 0 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.
⋯// © KAIST291-//@version=5+//@version=6strategy("prototype",initial_capital=1,commission_type=strategy.commission.percent,commission_value=0.1, format=format.volume, precision=0,overlay=true)⋯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 |
|---|---|---|---|
| Length1 (no label in the script) | 1 | int | ma1 |
| Length3 (no label in the script) | 3 | int | ma3 |
| Length7 (no label in the script) | 7 | int | ma7 |
| Length14 (no label in the script) | 14 | int | ma14 |
| Length20 (no label in the script) | 20 | int | ma20 |
| Length60 (no label in the script) | 60 | int | ma60 |
| Length120 (no label in the script) | 120 | int | ma120 |
| Daily MA length | 50 | int (written input.integer) · min 1 · max 100 | Davgvol |
| Weekly MA length | 10 | int (written input.integer) · min 1 · max 100 | Wavgvol |
| Length (no label in the script) | 20 | int · min 1 | basis dev dev2 dev3 |
| Source | close | source | basis dev dev2 dev3 |
| StdDev | 2.0 | float · min 0.001 · max 50 | dev |
| exp | 1.5 | float · min 0.001 · max 50 | dev2 |
| exp1 | 1.0 | float · min 0.001 · max 50 | dev3 |
| Offset | 0 | int (written input.integer) · min -500 · max 500 | Upper Lower Basis |
What it calculates
- SMA (
sma,ta.smain v5)close, Length1 (1)ma1 · line 13 - SMA (
sma,ta.smain v5)close, Length3 (3)ma3 · line 14 - SMA (
sma,ta.smain v5)close, Length7 (7)ma7 · line 15 - SMA (
sma,ta.smain v5)close, Length14 (14)ma14 · line 16 - SMA (
sma,ta.smain v5)close, Length20 (20)ma20 · line 17 - SMA (
sma,ta.smain v5)close, Length60 (60)ma60 · line 18 - SMA (
sma,ta.smain v5)close, Length120 (120)ma120 · line 19 - RSI (
rsi,ta.rsiin v5)close, 14rsi · line 20 - SMA (
sma,ta.smain v5)volume, Daily MA length (50)Davgvol · line 28 - SMA (
sma,ta.smain v5)volume, Weekly MA length (10)Wavgvol · line 29 - SMA (
sma,ta.smain v5)Source (close), Length (20)basis · line 36 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (20)dev · line 37 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (20)dev2 · line 40 - Stdev (
stdev,ta.stdevin v5)Source (close), Length (20)dev3 · line 43 - Highest (
highest,ta.highestin v5)exit, 10hi · line 57 - Valuewhen (
valuewhen,ta.valuewhenin v5)imInATrade, high, 0highestPriceAfterEntry · line 59
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 | (bull and close>ma3 and ma20>ma60 and rsi<75) | On | 62 |
| Close Long | (strategy.position_avg_price*1.05<close) | On | 64 |
| Close Long | (highestPriceAfterEntry*0.999<close and close>strategy.position_avg_price*1.002) | On | 66 |
| Close Long | (highestPriceAfterEntry*0.997<close and close>strategy.position_avg_price*1.002) | On | 68 |
| Close Long | (highestPriceAfterEntry*0.995<close and close>strategy.position_avg_price*1.002) | On | 70 |
| Close Long | (strategy.openprofit < strategy.position_avg_price*0.9-close) | On | 72 |
| Close Long | (strategy.position_avg_price*0.9 > close) | On | 74 |
| Open Short short | (bear and close<ma3 and crossunder(ma60,ma120)) | On | 78 |
| Close Short | (strategy.position_avg_price*0.95>close) | On | 81 |
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 | −157,995.0% | +102.5% | 10 | 70% | 0.51 | 4,752.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −30,512.3% | +5.5% | 6 | 83% | 0.57 | 18,335.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −11,814.3% | +9.8% | 8 | 38% | 0.27 | 400.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −1,746.1% | +8.4% | 6 | 83% | 0.42 | 311.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +234.4% | +16.7% | 10 | 70% | 1.38 | 65.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +63.7% | +21.5% | 6 | 100% | — | 31.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +2,855.1% | +148.3% | 15 | 80% | 1.91 | 391.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −101.3% | +17.1% | 12 | 92% | 0.85 | 540.6% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Settings heatmap
Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (Daily MA length 25, Weekly MA length 5) made −108,534.0% before 26 Dec 2025 and −14,640.1% after it, against −16,361.2% for the defaults. 0% of the 64 combinations made money in-sample and 25% out-of-sample.
| Weekly MA length ↓ · Daily MA length → | 25 | 30 | 35 | 43 | 50 | 60 | 70 | 85 |
|---|---|---|---|---|---|---|---|---|
| 5 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| 6 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| 7 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| 9 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| 10 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| 12 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| 14 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| 17 | −108,534% | −108,534% | −108,534% | −140,768% | −140,768% | −140,768% | −140,768% | −140,768% |
| Weekly MA length ↓ · Daily MA length → | 25 | 30 | 35 | 43 | 50 | 60 | 70 | 85 |
|---|---|---|---|---|---|---|---|---|
| 5 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
| 6 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
| 7 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
| 9 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
| 10 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
| 12 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
| 14 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
| 17 | −14,640% | −14,640% | −14,640% | −14,640% | −16,361% | −16,361% | +36,820% | +36,820% |
Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. 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 | 3 | 67% | −$692.80 |
| Sideways market | 6 | 67% | −$1,239.25 |
| Falling market | 1 | 100% | $360.76 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
217,089.0%
The 95th percentile of the worst drawdown when the same 10 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 168.9% to 217,089.0%; the tick is what actually happened, 578.8%. Order luck alone moves it this much.
All 10 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 16 Oct 2024 67,074.10 | 20 Oct 2024 68,378.00 | 4 | $116.84 |
| long | 30 Oct 2024 72,736.40 | 9 Nov 2024 76,509.80 | 10 | $362.41 |
| long | 22 Jan 2025 106,144.00 | 9 Feb 2025 96,444.80 | 18 | −$990.17 |
| long | 11 Jul 2025 116,010.00 | 14 Jul 2025 119,087.00 | 3 | $284.15 |
| long | 14 Aug 2025 123,306.00 | 26 Aug 2025 110,112.00 | 12 | −$1,342.79 |
| long | 3 Oct 2025 120,529.00 | 5 Oct 2025 122,391.00 | 2 | $161.87 |
| long | 14 Jan 2026 95,414.00 | 26 Jan 2026 86,670.40 | 12 | −$892.57 |
| long | 14 Apr 2026 74,418.00 | 23 Apr 2026 78,178.20 | 9 | $360.76 |
| long | 20 Aug 2026 69,334.80 | 21 Aug 2026 73,027.00 | 1 | $354.99 |
| long | 19 Sep 2026 80,883.90 | 21 Sep 2026 81,178.00 | 2 | $13.21 |
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 |
|---|---|---|---|---|---|
| Volume and Moving average,will this model working in real-trade- this page | — | v4 strategy | −157,995.0% | 10 | 4,752.1% |
| Vix FIX - StochRSI Strategy by timj | sma rsi highest stdev | v5 strategy | +1.0% | 21 | 10.7% |
| Bollinger band & Volume based strategy V2 by Ayden_C | sma rsi stdev valuewhen | v4 strategy | −0.1% | 5 | 0.2% |
| Bottom catch strategy by footlz | sma stdev rsi | v4 strategy | +3.9% | 3 | 7.1% |
| Bull Trend Filtered StochRSI (BTFS) by SnarkyPuppy | highest rsi sma | v5 strategy | +36.9% | 21 | 21.5% |
| Madri by Mdemoio | rsi sma stdev | v4 strategy | +25.0% | 4 | 36.4% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 30 ms | Yes 1,000 bars in 65 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/// © KAIST291//@version=4strategy("prototype",initial_capital=1,commission_type=strategy.commission.percent,commission_value=0.1, format=format.volume, precision=0,overlay=true)// SETTING //length1=input(1)length3=input(3)length7=input(7)length14=input(14)length20=input(20)length60=input(60)length120=input(120)ma1= sma(close,length1)ma3= sma(close,length3)ma7= sma(close,length7)ma14=sma(close,length14)ma20=sma(close,length20)ma60=sma(close,length60)ma120=sma(close,length120)rsi=rsi(close,14)// BUYING VOLUME AND SELLING VOLUME //BV = iff( (high==low), 0, volume*(close-low)/(high-low))SV = iff( (high==low), 0, volume*(high-close)/(high-low))vol = iff(volume > 0, volume, 1)dailyLength = input(title = "Daily MA length", type = input.integer, defval = 50, minval = 1, maxval = 100)weeklyLength = input(title = "Weekly MA length", type = input.integer, defval = 10, minval = 1, maxval = 100)//-----------------------------------------------------------Davgvol = sma(volume, dailyLength)Wavgvol = sma(volume, weeklyLength)//-----------------------------------------------------------length = input(20, minval=1)src = input(close, title="Source")mult = input(2.0, minval=0.001, maxval=50, title="StdDev")mult2= input(1.5, minval=0.001, maxval=50, title="exp")mult3= input(1.0, minval=0.001, maxval=50, title="exp1")basis = sma(src, length)dev = mult * stdev(src, length)upper = basis + devlower = basis - devdev2= mult2 * stdev(src, length)Supper= basis + dev2Slower= basis - dev2dev3= mult3 * stdev(src, length)upper1= basis + dev3lower1= basis - dev3offset = input(0, "Offset", type = input.integer, minval = -500, maxval = 500)plot(basis, "Basis", color=#FF6D00, offset = offset)p1 = plot(upper, "Upper", color=#2962FF, offset = offset)p2 = plot(lower, "Lower", color=#2962FF, offset = offset)fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))//----------------------------------------------------exit=(close-strategy.position_avg_price / strategy.position_avg_price*100)bull=(close>Supper and high > upper and BV>SV and BV>Davgvol)bull2=(BV>SV and BV>Davgvol)bux =(close<Supper and close>Slower and volume<Wavgvol)bear=(close<Slower and close<lower and SV>BV and SV>Wavgvol)hi=highest(exit,10)imInATrade = strategy.position_size != 0highestPriceAfterEntry = valuewhen(imInATrade, high, 0)// STRATEGY LONG //if (bull and close>ma3 and ma20>ma60 and rsi<75) strategy.entry("Long",strategy.long,0.1)if (strategy.position_avg_price*1.05<close) strategy.close("Long",1)else if (highestPriceAfterEntry*0.999<close and close>strategy.position_avg_price*1.002) strategy.close("Long",1)else if (highestPriceAfterEntry*0.997<close and close>strategy.position_avg_price*1.002) strategy.close("Long",1)else if (highestPriceAfterEntry*0.995<close and close>strategy.position_avg_price*1.002) strategy.close("Long",1)else if (strategy.openprofit < strategy.position_avg_price*0.9-close) strategy.close("Long",1)else if (strategy.position_avg_price*0.9 > close) strategy.close("Long",1)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////if (bear and close<ma3 and crossunder(ma60,ma120)) strategy.entry("Short",strategy.short,0.1) if (strategy.position_avg_price*0.95>close) strategy.close("Short",1)