Pine Script v4 · Strategy
Infiten Slope Strategy
A Pine Script v4 strategy built on SMA (clh, daysback), SMA or EMA (close, 12) and RMA or Change (max(change(src), 0), 14). It has 6 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 commits 100% of equity and pays no commission. 7 settings; defaults include Fast Length 12, Slow Length 26 and Source close.
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 Infiten Slope Strategy repaint?
- Yes
- At least one pattern in the source can repaint: intrabar recalculation.
- How did Infiten Slope Strategy do on BTCUSDT 1D with default settings?
- +47.18%
- From 26 Jan 2024 to 21 Oct 2026, over 26 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Infiten Slope Strategy be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Infiten Slope Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Infiten Slope Strategy run in Zeal Terminal?
- Yes
- It compiles in 14 ms and runs 1,000 bars in 48 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +47.18%
- $47,177.50
- Buy and hold
- +102.5%
- same period
- Closed trades
- 26
- 3 won · 7 lost
- Profitable
- 11.5%
- of closed trades
- Profit factor
- 1.89
- gross profit ÷ gross loss
- Max drawdown
- 35.46%
- −$67,232.20
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Likely bug
sma(close, 300) ignores the settings line 20
Line 20 hard-codes close where line 35 uses “Source” and 300 where line 35 uses “Fast Length”. Changing those settings moves one band but not this one.
sma(close,300)sma(src, fast_length) -
Likely bug
sma(close, 150) ignores the settings line 21
Line 21 hard-codes close where line 35 uses “Source” and 150 where line 35 uses “Fast Length”. Changing those settings moves one band but not this one.
sma(close,150)sma(src, fast_length) -
Likely bug
sma(close, 50) ignores the settings line 22
Line 22 hard-codes close where line 35 uses “Source” and 50 where line 35 uses “Fast Length”. Changing those settings moves one band but not this one.
sma(close,50)sma(src, fast_length) -
Likely bug
sma(close, 500) ignores the settings line 42
Line 42 hard-codes close where line 35 uses “Source” and 500 where line 35 uses “Fast Length”. Changing those settings moves one band but not this one.
sma(close,500)sma(src, fast_length) -
Likely bug
sma(volume, 30) ignores the settings line 52
Line 52 hard-codes volume where line 35 uses “Source” and 30 where line 35 uses “Fast Length”. Changing those settings moves one band but not this one.
sma(volume,30)sma(src, fast_length) -
Likely bug
change(close) ignores the settings line 47
Line 47 hard-codes close where line 46 uses “Source”. Changing those settings moves one band but not this one.
change(close)change(src) -
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
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 63, 64, 65, 66, 67, 68. 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, ema → ta.ema, rma → ta.rma, max → math.max, change → ta.change, min → math.min, crossunder → ta.crossunder, crossover → ta.crossover.
- 6 strategy calls use the when = argument (line 63, 64, 65, 66, 67, 68). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 26 before, 26 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 16: sma → ta.sma
- Line 16: sma → ta.sma
- Line 17: sma → ta.sma
- Line 20: sma → ta.sma
- Line 21: sma → ta.sma
28 more edits
- Line 22: sma → ta.sma
- Line 28: input(type = input.integer) → input.int()
- Line 29: input(type = input.integer) → input.int()
- Line 30: input(type = input.source) → input.source()
- Line 31: input(type = input.integer) → input.int()
- Line 32: input(type = input.bool) → input.bool()
- Line 33: input(type = input.bool) → input.bool()
- Line 35: sma → ta.sma
- Line 35: ema → ta.ema
- Line 36: sma → ta.sma
- Line 36: ema → ta.ema
- Line 38: sma → ta.sma
- Line 38: ema → ta.ema
- Line 42: sma → ta.sma
- Line 46: rma → ta.rma
- Line 46: max → math.max
- Line 46: change → ta.change
- Line 47: rma → ta.rma
- Line 47: min → math.min
- Line 47: change → ta.change
- Line 52: sma → ta.sma
- Line 53: crossunder → ta.crossunder
- Line 54: crossunder → ta.crossunder
- Line 55: crossunder → ta.crossunder
- Line 58: crossover → ta.crossover
- Line 60: crossover → ta.crossover
- Line 63: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 64: strategy.entry(…, true) → strategy.entry(…, strategy.long)
⋯// © spiritualhealer117-//@version=4+//@version=5strategy("Infiten Slope Strategy", overlay=false,calc_on_every_tick = true, default_qty_type=strategy.percent_of_equity, default_qty_value = 100)⋯clh = close+low+high-exhaustion = (clh-sma(clh,daysback))/sma(clh,daysback)+exhaustion = (clh-ta.sma(clh,daysback))/ta.sma(clh,daysback)-exhaustionSma = sma(exhaustion,daysback)+exhaustionSma = ta.sma(exhaustion,daysback)//}//Long Term Moving Averages for sell signals {-red = sma(close,300)+red = ta.sma(close,300)-white = sma(close,150)+white = ta.sma(close,150)-blue = sma(close,50)+blue = ta.sma(close,50)plot(red,color=color.red)⋯//MACD Calculation {-fast_length = input(title="Fast Length", type=input.integer, defval=12)+fast_length = input.int(title="Fast Length", defval=12)-slow_length = input(title="Slow Length", type=input.integer, defval=26)+slow_length = input.int(title="Slow Length", defval=26)-src = input(title="Source", type=input.source, defval=close)+src = input.source(title="Source", defval=close)-signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)+signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)-sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)+sma_source = input.bool(title="Simple MA (Oscillator)", defval=false)-sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)+sma_signal = input.bool(title="Simple MA (Signal Line)", defval=false)// Calculating-fast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)+fast_ma = sma_source ? ta.sma(src, fast_length) : ta.ema(src, fast_length)-slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)+slow_ma = sma_source ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_ma-signal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)+signal = sma_signal ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal⋯//SIGMOID Bottom {-timeAdjust = 300/sma(close,500)+timeAdjust = 300/ta.sma(close,500)//}⋯len = input(14, minval=1, title="Length")-up = rma(max(change(src), 0), len)+up = ta.rma(math.max(ta.change(src), 0), len)-down = rma(-min(change(close), 0), len)+down = ta.rma(-math.min(ta.change(close), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))⋯//Sell conditions-bigVolume = sma(volume,30)*volumesens+bigVolume = ta.sma(volume,30)*volumesens-sellcond1 = crossunder(exhaustion,exhaustionSma) and volume > bigVolume+sellcond1 = ta.crossunder(exhaustion,exhaustionSma) and volume > bigVolume-sellcond2 = crossunder(macd,signal) and volume > bigVolume+sellcond2 = ta.crossunder(macd,signal) and volume > bigVolume-midtermsellcond1 = crossunder(blue,white)+midtermsellcond1 = ta.crossunder(blue,white)longtermsellcond1 = white < red//Buy conditions-buycond = crossover(exhaustion,exhaustionSma) and not longtermsellcond1+buycond = ta.crossover(exhaustion,exhaustionSma) and not longtermsellcond1buycond2 = rsi < 30-buycond3 = crossover(blue,white) and longtermsellcond1+buycond3 = ta.crossover(blue,white) and longtermsellcond1//}//Backtest Run Buy/Sell Commands {-strategy.entry("buycond",true, when=buycond and bigVolume)+strategy.entry("buycond",strategy.long, when=buycond and bigVolume)-strategy.entry("buycond2",true, when=buycond2 and bigVolume)+strategy.entry("buycond2",strategy.long, when=buycond2 and bigVolume)strategy.close_all(when=sellcond1,comment="short term sell signal 1")⋯Clean v5
VerifiedSame 26 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 45: input() → input.int()
- Line 63: when = buycond and bigVolume → if block
- Line 64: when = buycond2 and bigVolume → if block
- Line 65: when = sellcond1 → if block
- Line 66: when = midtermsellcond1 → if block
- Line 67: when = longtermsellcond1 → if block
- Line 68: when = sellcond2 → if block
⋯//RSI bottom {-len = input(14, minval=1, title="Length")+len = input.int(14, minval=1, title="Length")up = ta.rma(math.max(ta.change(src), 0), len)⋯//Backtest Run Buy/Sell Commands {-strategy.entry("buycond",strategy.long, when=buycond and bigVolume)+if buycond and bigVolume+ strategy.entry("buycond",strategy.long)-strategy.entry("buycond2",strategy.long, when=buycond2 and bigVolume)+if buycond2 and bigVolume+ strategy.entry("buycond2",strategy.long)-strategy.close_all(when=sellcond1,comment="short term sell signal 1")+if sellcond1+ strategy.close_all(comment="short term sell signal 1")-strategy.close_all(when=midtermsellcond1, comment="mid term sell signal 1")+if midtermsellcond1+ strategy.close_all(comment="mid term sell signal 1")-strategy.close_all(when=longtermsellcond1, comment="long term sell signal 1")+if longtermsellcond1+ strategy.close_all(comment="long term sell signal 1")-strategy.close_all(when=sellcond2, comment="short term sell signal 2")+if sellcond2+ strategy.close_all(comment="short term sell signal 2")plot(strategy.position_size)⋯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, 18 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.
⋯// © spiritualhealer117-//@version=5+//@version=6strategy("Infiten Slope Strategy", overlay=false,calc_on_every_tick = true, default_qty_type=strategy.percent_of_equity, default_qty_value = 100)⋯Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Fast Length | 12 | int (written input.integer) | fast_ma |
| Slow Length | 26 | int (written input.integer) | slow_ma |
| Source | close | source | fast_ma slow_ma up |
| Signal Smoothing | 9 | int (written input.integer) · min 1 · max 50 | signal |
| Simple MA (Oscillator) | false | bool | fast_ma slow_ma |
| Simple MA (Signal Line) | false | bool | signal |
| Length | 14 | int · min 1 | up down |
What it calculates
- SMA (
sma,ta.smain v5)clh, daysbackexhaustion · line 16 - SMA (
sma,ta.smain v5)exhaustion, daysbackexhaustionSma · line 17 - SMA (
sma,ta.smain v5)close, 300red · line 20 - SMA (
sma,ta.smain v5)close, 150white · line 21 - SMA (
sma,ta.smain v5)close, 50blue · line 22 - SMA / EMA (
sma,ta.smain v5)Source (close), Fast Length (12)fast_ma · line 35 - SMA / EMA (
sma,ta.smain v5)Source (close), Slow Length (26)slow_ma · line 36 - SMA / EMA (
sma,ta.smain v5)macd, Signal Smoothing (9)signal · line 38 - SMA (
sma,ta.smain v5)close, 500timeAdjust · line 42 - RMA / Change (
rma,ta.rmain v5)max(change(src), 0), Length (14)up · line 46 - RMA / Change (
rma,ta.rmain v5)-min(change(close), 0), Length (14)down · line 47 - SMA (
sma,ta.smain v5)volume, 30bigVolume · line 52 - Crossunder (
crossunder,ta.crossunderin v5)blue, whitemidtermsellcond1 · line 55
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 buycond long | buycond and bigVolume | On | 63 |
| Open buycond2 long | buycond2 and bigVolume | On | 64 |
| Close | sellcond1crossunder(exhaustion,exhaustionSma) and volume > bigVolume | On | 65 |
| Close | midtermsellcond1 | On | 66 |
| Close | longtermsellcond1white < red | On | 67 |
| Close | sellcond2crossunder(macd,signal) and volume > bigVolume | On | 68 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- CheckIntrabar recalculationcalc_on_every_tick = true. Live values can differ from history.
- 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 | +47.2% | +102.5% | 26 | 12% | 1.89 | 35.5% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +20.3% | +5.5% | 12 | 42% | 2.55 | 18.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −64.2% | +9.8% | 18 | 17% | 0.29 | 67.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −33.9% | +8.4% | 15 | 13% | 0.12 | 35.4% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −59.0% | +16.7% | 28 | 7% | 0.36 | 62.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −21.6% | +21.5% | 9 | 22% | 0.31 | 30.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −12.8% | +148.3% | 12 | 75% | 0.86 | 56.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +25.0% | +17.1% | 9 | 78% | 2.54 | 18.1% | 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 | 1 | 0% | −$4,842.73 |
| Sideways market | 16 | 19% | $65,955.40 |
| Falling market | 9 | 0% | −$13,935.20 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
28.4%
The 95th percentile of the worst drawdown when the same 26 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 12.6% to 28.4%; the tick is what actually happened, 22.4%. Order luck alone moves it this much.
All 26 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 May 2024 63,892.00 | 15 Jul 2024 60,797.90 | 71 | −$4,842.73 |
| long | 6 Aug 2024 54,018.80 | 2 Oct 2024 60,804.90 | 57 | $11,954.10 |
| long | 15 Oct 2024 66,084.00 | 4 Mar 2025 86,221.20 | 140 | $32,639.10 |
| long | 6 Mar 2025 90,606.00 | 8 Mar 2025 86,801.70 | 2 | −$5,867.68 |
| long | 16 Mar 2025 84,338.40 | 21 Mar 2025 84,223.40 | 5 | −$182.65 |
| long | 12 Apr 2025 83,423.80 | 15 Aug 2025 118,295.00 | 125 | $55,886.80 |
| long | 9 Sep 2025 112,065.00 | 26 Sep 2025 108,994.00 | 17 | −$5,194.94 |
| long | 30 Sep 2025 114,312.00 | 11 Oct 2025 112,774.00 | 11 | −$2,480.05 |
| long | 27 Oct 2025 114,559.00 | 7 Nov 2025 101,346.00 | 11 | −$20,981.90 |
| long | 11 Nov 2025 106,011.00 | 15 Jan 2026 96,951.80 | 65 | −$13,752.50 |
| long | 1 Feb 2026 78,741.10 | 1 Feb 2026 78,741.10 | 0 | $0.00 |
| long | 2 Feb 2026 76,968.20 | 2 Feb 2026 76,968.20 | 0 | $0.00 |
| long | 3 Feb 2026 78,738.60 | 3 Feb 2026 78,738.60 | 0 | $0.00 |
| long | 4 Feb 2026 75,770.20 | 4 Feb 2026 75,770.20 | 0 | $0.00 |
| long | 5 Feb 2026 73,165.80 | 5 Feb 2026 73,165.80 | 0 | $0.00 |
| long | 6 Feb 2026 62,909.90 | 6 Feb 2026 62,909.90 | 0 | $0.00 |
| long | 13 Feb 2026 66,272.20 | 13 Feb 2026 66,272.20 | 0 | $0.00 |
| long | 3 Jun 2026 66,760.80 | 3 Jun 2026 66,760.80 | 0 | $0.00 |
| long | 4 Jun 2026 64,142.80 | 4 Jun 2026 64,142.80 | 0 | $0.00 |
| long | 5 Jun 2026 63,886.00 | 5 Jun 2026 63,886.00 | 0 | $0.00 |
| long | 6 Jun 2026 61,056.50 | 6 Jun 2026 61,056.50 | 0 | $0.00 |
| long | 7 Jun 2026 60,884.60 | 7 Jun 2026 60,884.60 | 0 | $0.00 |
| long | 8 Jun 2026 63,332.00 | 8 Jun 2026 63,332.00 | 0 | $0.00 |
| long | 9 Jun 2026 63,086.00 | 9 Jun 2026 63,086.00 | 0 | $0.00 |
| long | 10 Jun 2026 61,730.00 | 10 Jun 2026 61,730.00 | 0 | $0.00 |
| long | 11 Jun 2026 61,511.00 | 11 Jun 2026 61,511.00 | 0 | $0.00 |
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 |
|---|---|---|---|---|---|
| Infiten Slope Strategy this page | — | v4 strategy | +47.2% | 26 | 35.5% |
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy | −19.4% | 36 | 70.0% |
| Soheil PKO's 5 min Hitman Scalp - 3MA + Laguerre RSI + ADX [Pt] by PtGambler | ema sma rma | v5 strategy | No trades on this market | ||
| EMA-ADX-VOL-CRYPTO KILLER [15M] by Babehdyo | rma sma ema | v4 strategy | +4.5% | 22 | 5.3% |
| Contrarian Scalping Counter Trend Bb Envelope Adx and Stochastic by exlux99 | sma ema rma | v5 strategy | +1.9% | 15 | 3.2% |
| CCI + EMA with RSI Cross Strategy by rwestbrookjr | ema rma sma | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 14 ms | With a workaround 1,000 bars in 48 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 63, 64) 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/// © spiritualhealer117//@version=4strategy("Infiten Slope Strategy", overlay=false,calc_on_every_tick = true, default_qty_type=strategy.percent_of_equity, default_qty_value = 100)// //TIME RESTRICT FOR BACKTESTING {// inDateRange = (time >= timestamp(syminfo.timezone, 2003,// 1, 1, 0, 0)) and// (time < timestamp(syminfo.timezone, 2021, 5, 25, 0, 0))// //}//OPTIMAL PARAMETERS {daysback = 30volumesens = 1.618//}//Calculating Exhaustion and Exhaustion Moving Average {clh = close+low+highexhaustion = (clh-sma(clh,daysback))/sma(clh,daysback)exhaustionSma = sma(exhaustion,daysback)//}//Long Term Moving Averages for sell signals {red = sma(close,300)white = sma(close,150)blue = sma(close,50)plot(red,color=color.red)plot(white,color=color.white)plot(blue,color=color.blue)//}//MACD Calculation {fast_length = input(title="Fast Length", type=input.integer, defval=12)slow_length = input(title="Slow Length", type=input.integer, defval=26)src = input(title="Source", type=input.source, defval=close)signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)sma_source = input(title="Simple MA (Oscillator)", type=input.bool, defval=false)sma_signal = input(title="Simple MA (Signal Line)", type=input.bool, defval=false)// Calculatingfast_ma = sma_source ? sma(src, fast_length) : ema(src, fast_length)slow_ma = sma_source ? sma(src, slow_length) : ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal ? sma(macd, signal_length) : ema(macd, signal_length)hist = macd - signal//}//SIGMOID Bottom {timeAdjust = 300/sma(close,500)//}//RSI bottom {len = input(14, minval=1, title="Length")up = rma(max(change(src), 0), len)down = rma(-min(change(close), 0), len)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))//}//Entry and exit conditions {//Sell conditionsbigVolume = sma(volume,30)*volumesenssellcond1 = crossunder(exhaustion,exhaustionSma) and volume > bigVolumesellcond2 = crossunder(macd,signal) and volume > bigVolumemidtermsellcond1 = crossunder(blue,white)longtermsellcond1 = white < red//Buy conditionsbuycond = crossover(exhaustion,exhaustionSma) and not longtermsellcond1buycond2 = rsi < 30buycond3 = crossover(blue,white) and longtermsellcond1//}//Backtest Run Buy/Sell Commands {strategy.entry("buycond",true, when=buycond and bigVolume)strategy.entry("buycond2",true, when=buycond2 and bigVolume)strategy.close_all(when=sellcond1,comment="short term sell signal 1")strategy.close_all(when=midtermsellcond1, comment="mid term sell signal 1")strategy.close_all(when=longtermsellcond1, comment="long term sell signal 1")strategy.close_all(when=sellcond2, comment="short term sell signal 2")plot(strategy.position_size)//Sell on last tested day (only for data collection)//strategy.close_all(when=not inDateRange)//}