Pine Script v5 · Strategy
My five in one strategy for ETHUSD 700x v4 --smooth code
A Pine Script v5 strategy built on MOM (close, 6), Barssince or Change and SMA (close, 365). It has 2 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 commits 1% of equity and pays no commission. 12 settings; defaults include Resolution for Funding Interval 480, Resolution for TWAP Interval 240 and Momentum 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 My five in one strategy for ETHUSD 700x v4 --smooth code repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did My five in one strategy for ETHUSD 700x v4 --smooth code do on BTCUSDT 1D with default settings?
- +1.02%
- From 26 Jan 2024 to 21 Oct 2026, over 87 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does My five in one strategy for ETHUSD 700x v4 --smooth code 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: 87 before, 79 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does My five in one strategy for ETHUSD 700x v4 --smooth code use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does My five in one strategy for ETHUSD 700x v4 --smooth code run in Zeal Terminal?
- Yes
- It compiles in 21 ms and runs 1,000 bars in 67 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BITMEX:XBTUSD 480 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs BITMEX:XBT 480 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs BITMEX:XBTUSD 240 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Needs QUANDL:BCHAIN/MIREV D data, not available: not a Binance spot market Values that depend on it are empty on this chart.
- Net profit
- +1.02%
- $10,167.40
- Buy and hold
- +102.5%
- same period
- Closed trades
- 87
- 33 won · 54 lost
- Profitable
- 37.9%
- of closed trades
- Profit factor
- 1.56
- gross profit ÷ gross loss
- Max drawdown
- 0.70%
- −$7,042.58
One run with the author's default settings, $1,000,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.
-
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
2 settings have no label
In the settings dialog top (line 31), bottom (line 32) 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 an argument v6 removed
when = on line 122, 127. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| Resolution for Funding Interval | 480 | timeframe | res |
| Resolution for TWAP Interval | 240 | timeframe | res_1 |
| Momentum Source | close | source | mom |
| Momentum Length | 6 | int | mom |
| Aroon Length | 7 | int · min 1 · max 1000 | upper lower |
| From Year | 2018 | int · min 1900 · max 2100 | entry long entry short line 119 line 125 |
| To Year | 2100 | int · min 1900 · max 2100 | entry long entry short line 119 line 125 |
| Perp Ticker | BITMEX:XBTUSD | symbol | typicalPrice_fut weight |
| Spot Ticker | BITMEX:XBT | symbol | typicalPrice_idx |
| Top (no label in the script) | 0.7 | float · step 0.1 | yas1 smonadnu |
| Bottom (no label in the script) | 3.4 | float · step 0.1 | no1 smonavrhu |
| Select Strategy | macd | string · options ['rsi', 'macd', 'bb', 'rsi + macd', 'tt','pm','aroon', 'aroon1 + pm'] | _buy _sell |
What it calculates
- MOMMomentum Source (close), Momentum Length (6)
mom · line 36 - Barssince / Changeta.change(request.security(perp_ticker, res_1, time, lookahead=barmerge.lookahead_on))
weight · line 43 - SMAclose, 365
ma365 · line 79 - Highestbarshigh, length+1
upper · line 82 - Lowestbarslow, length+1
lower · line 83 - MACDclose, 12, 26, 9
macdLine · line 91 - MACDclose, 12, 26, 9
signalLine · line 91 - MACDclose, 12, 26, 9
histLine · line 91
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 | _buy | On | 122 |
| Open short short | _sell | On | 127 |
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.
- CheckHigher-timeframe data3 request.security call(s) use lookahead_on (line 43, 78, 79). Without a [1] offset this reads future bars in history.
- 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
Not run on other markets: the script requests BITMEX:XBTUSD 480, BITMEX:XBT 480, BITMEX:XBTUSD 240, QUANDL:BCHAIN/MIREV D, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data; a lower timeframe than the chart; the engine does not evaluate intrabar data; a lower timeframe than the chart; the engine does not evaluate intrabar data; not a Binance spot market). Its results would rest on empty values.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 22 | 32% | −$2,210.24 |
| Sideways market | 43 | 37% | $7,436.02 |
| Falling market | 22 | 45% | $4,941.63 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.8%
The 95th percentile of the worst drawdown when the same 87 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.3% to 0.8%; the tick is what actually happened, 0.7%. Order luck alone moves it this much.
All 87 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 3 Feb 2024 43,200.00 | 7 Feb 2024 43,099.00 | 4 | −$23.39 |
| short | 7 Feb 2024 43,099.00 | 8 Feb 2024 44,349.60 | 1 | −$290.17 |
| long | 8 Feb 2024 44,349.60 | 16 Mar 2024 69,499.80 | 37 | $5,669.13 |
| short | 16 Mar 2024 69,499.80 | 26 Mar 2024 69,880.00 | 10 | −$54.99 |
| long | 26 Mar 2024 69,880.00 | 22 Apr 2024 64,941.20 | 27 | −$710.51 |
| short | 22 Apr 2024 64,941.20 | 23 Apr 2024 66,819.30 | 1 | −$290.54 |
| long | 23 Apr 2024 66,819.30 | 5 May 2024 63,892.00 | 12 | −$439.97 |
| short | 5 May 2024 63,892.00 | 7 May 2024 63,165.20 | 2 | $114.20 |
| long | 7 May 2024 63,165.20 | 14 May 2024 62,940.10 | 7 | −$35.78 |
| short | 14 May 2024 62,940.10 | 16 May 2024 66,206.50 | 2 | −$521.02 |
| long | 16 May 2024 66,206.50 | 4 Jun 2024 68,809.90 | 19 | $394.56 |
| short | 4 Jun 2024 68,809.90 | 5 Jun 2024 70,537.80 | 1 | −$252.07 |
| long | 5 Jun 2024 70,537.80 | 14 Jun 2024 66,773.00 | 9 | −$535.63 |
| short | 14 Jun 2024 66,773.00 | 2 Jul 2024 62,900.00 | 18 | $581.78 |
| long | 2 Jul 2024 62,900.00 | 11 Jul 2024 57,725.80 | 9 | −$825.57 |
| short | 11 Jul 2024 57,725.80 | 14 Jul 2024 59,204.00 | 3 | −$256.78 |
| long | 14 Jul 2024 59,204.00 | 6 Aug 2024 54,018.80 | 23 | −$878.03 |
| short | 6 Aug 2024 54,018.80 | 11 Aug 2024 60,923.50 | 5 | −$1,280.30 |
| long | 11 Aug 2024 60,923.50 | 18 Aug 2024 59,492.00 | 7 | −$235.06 |
| short | 18 Aug 2024 59,492.00 | 20 Aug 2024 59,438.50 | 2 | $8.99 |
| long | 20 Aug 2024 59,438.50 | 21 Aug 2024 59,013.80 | 1 | −$71.46 |
| short | 21 Aug 2024 59,013.80 | 22 Aug 2024 61,156.00 | 1 | −$363.03 |
| long | 22 Aug 2024 61,156.00 | 6 Sep 2024 56,180.00 | 15 | −$813.42 |
| short | 6 Sep 2024 56,180.00 | 13 Sep 2024 58,132.30 | 7 | −$347.12 |
| long | 13 Sep 2024 58,132.30 | 8 Oct 2024 62,224.00 | 25 | $702.84 |
| short | 8 Oct 2024 62,224.00 | 9 Oct 2024 62,160.50 | 1 | $10.20 |
| long | 9 Oct 2024 62,160.50 | 12 Oct 2024 62,540.00 | 3 | $61.00 |
| short | 12 Oct 2024 62,540.00 | 15 Oct 2024 66,084.00 | 3 | −$566.29 |
| long | 15 Oct 2024 66,084.00 | 28 Oct 2024 68,021.70 | 13 | $292.85 |
| short | 28 Oct 2024 68,021.70 | 29 Oct 2024 69,962.20 | 1 | −$285.01 |
| long | 29 Oct 2024 69,962.20 | 2 Dec 2024 97,185.20 | 34 | $3,886.27 |
| short | 2 Dec 2024 97,185.20 | 5 Dec 2024 98,587.30 | 3 | −$144.66 |
| long | 5 Dec 2024 98,587.30 | 24 Dec 2024 94,881.50 | 19 | −$376.83 |
| short | 24 Dec 2024 94,881.50 | 29 Dec 2024 95,300.00 | 5 | −$44.20 |
| long | 29 Dec 2024 95,300.00 | 3 Jan 2025 96,984.80 | 5 | $177.16 |
| short | 3 Jan 2025 96,984.80 | 4 Jan 2025 98,174.20 | 1 | −$122.91 |
| long | 4 Jan 2025 98,174.20 | 15 Jan 2025 96,560.90 | 11 | −$164.68 |
| short | 15 Jan 2025 96,560.90 | 16 Jan 2025 100,497.00 | 1 | −$408.47 |
| long | 16 Jan 2025 100,497.00 | 2 Feb 2025 100,636.00 | 17 | $13.78 |
| short | 2 Feb 2025 100,636.00 | 16 Feb 2025 97,569.70 | 14 | $305.14 |
| long | 16 Feb 2025 97,569.70 | 20 Feb 2025 96,644.40 | 4 | −$95.01 |
| short | 20 Feb 2025 96,644.40 | 23 Feb 2025 96,551.00 | 3 | $9.68 |
| long | 23 Feb 2025 96,551.00 | 3 Mar 2025 94,270.00 | 8 | −$236.67 |
| short | 3 Mar 2025 94,270.00 | 5 Mar 2025 87,282.00 | 2 | $742.43 |
| long | 5 Mar 2025 87,282.00 | 16 Mar 2025 84,338.40 | 11 | −$338.02 |
| short | 16 Mar 2025 84,338.40 | 18 Mar 2025 84,010.00 | 2 | $39.02 |
| long | 18 Mar 2025 84,010.00 | 5 Apr 2025 83,889.90 | 18 | −$14.33 |
| short | 5 Apr 2025 83,889.90 | 10 Apr 2025 82,615.20 | 5 | $152.25 |
| long | 10 Apr 2025 82,615.20 | 9 Jun 2025 105,734.00 | 60 | $2,804.36 |
| short | 9 Jun 2025 105,734.00 | 10 Jun 2025 110,263.00 | 1 | −$430.46 |
| long | 10 Jun 2025 110,263.00 | 24 Jun 2025 105,334.00 | 14 | −$449.05 |
| short | 24 Jun 2025 105,334.00 | 26 Jun 2025 107,341.00 | 2 | −$191.28 |
| long | 26 Jun 2025 107,341.00 | 25 Jul 2025 118,341.00 | 29 | $1,028.78 |
| short | 25 Jul 2025 118,341.00 | 9 Aug 2025 116,675.00 | 15 | $141.49 |
| long | 9 Aug 2025 116,675.00 | 5 Sep 2025 110,731.00 | 27 | −$512.01 |
| short | 5 Sep 2025 110,731.00 | 6 Sep 2025 110,660.00 | 1 | $6.43 |
| long | 6 Sep 2025 110,660.00 | 26 Sep 2025 108,994.00 | 20 | −$151.19 |
| short | 26 Sep 2025 108,994.00 | 1 Oct 2025 114,049.00 | 5 | −$465.77 |
| long | 1 Oct 2025 114,049.00 | 16 Oct 2025 110,763.00 | 15 | −$289.22 |
| short | 16 Oct 2025 110,763.00 | 24 Oct 2025 110,078.00 | 8 | $62.08 |
| long | 24 Oct 2025 110,078.00 | 4 Nov 2025 106,583.00 | 11 | −$318.69 |
| short | 4 Nov 2025 106,583.00 | 13 Nov 2025 101,654.00 | 9 | $463.99 |
| long | 13 Nov 2025 101,654.00 | 27 Nov 2025 90,484.00 | 14 | −$1,103.08 |
| short | 27 Nov 2025 90,484.00 | 29 Nov 2025 90,890.70 | 2 | −$45.07 |
| long | 29 Nov 2025 90,890.70 | 3 Dec 2025 91,277.90 | 4 | $42.71 |
| short | 3 Dec 2025 91,277.90 | 4 Dec 2025 93,429.90 | 1 | −$236.42 |
| long | 4 Dec 2025 93,429.90 | 21 Dec 2025 88,360.90 | 17 | −$543.90 |
| short | 21 Dec 2025 88,360.90 | 23 Dec 2025 88,620.80 | 2 | −$29.47 |
| long | 23 Dec 2025 88,620.80 | 30 Jan 2026 84,650.20 | 38 | −$448.91 |
| short | 30 Jan 2026 84,650.20 | 18 Feb 2026 67,503.50 | 19 | $2,028.58 |
| long | 18 Feb 2026 67,503.50 | 13 Mar 2026 70,541.30 | 23 | $451.60 |
| short | 13 Mar 2026 70,541.30 | 14 Mar 2026 70,930.00 | 1 | −$55.32 |
| long | 14 Mar 2026 70,930.00 | 26 Mar 2026 71,336.50 | 12 | $57.54 |
| short | 26 Mar 2026 71,336.50 | 4 Apr 2026 66,964.30 | 9 | $615.33 |
| long | 4 Apr 2026 66,964.30 | 2 May 2026 78,231.10 | 28 | $1,690.21 |
| short | 2 May 2026 78,231.10 | 5 May 2026 79,861.00 | 3 | −$209.65 |
| long | 5 May 2026 79,861.00 | 15 May 2026 81,090.00 | 10 | $154.82 |
| short | 15 May 2026 81,090.00 | 13 Jun 2026 63,580.00 | 29 | $2,172.73 |
| long | 13 Jun 2026 63,580.00 | 26 Jun 2026 59,794.60 | 13 | −$600.36 |
| short | 26 Jun 2026 59,794.60 | 30 Jun 2026 60,260.20 | 4 | −$78.47 |
| long | 30 Jun 2026 60,260.20 | 1 Jul 2026 58,624.70 | 1 | −$273.50 |
| short | 1 Jul 2026 58,624.70 | 3 Jul 2026 61,560.00 | 2 | −$504.41 |
| long | 3 Jul 2026 61,560.00 | 31 Jul 2026 64,780.00 | 28 | $526.69 |
| short | 31 Jul 2026 64,780.00 | 9 Aug 2026 64,962.60 | 9 | −$28.39 |
| long | 9 Aug 2026 64,962.60 | 18 Aug 2026 64,532.10 | 9 | −$66.76 |
| short | 18 Aug 2026 64,532.10 | 19 Aug 2026 64,725.40 | 1 | −$30.18 |
| long | 19 Aug 2026 64,725.40 | 11 Oct 2026 82,988.40 | 53 | $2,842.27 |
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 |
|---|---|---|---|---|---|
| My five in one strategy for ETHUSD 700x v4 --smooth code this page | — | v5 strategy | +1.0% | 87 | 0.7% |
| Bollinger Bands And Aroon Scalping (by Coinrule) by Coinrule | sma highestbars lowestbars | v4 strategy | −5.4% | 8 | 10.0% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 2 strategy calls use the when = argument (line 122, 127). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Same 87 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 122: when = _buy → if block
- Line 127: when = _sell → if block
⋯ /// LONG- strategy.entry("long", strategy.long, when = _buy)+ if _buy+ strategy.entry("long", strategy.long) // strategy.exit("short", when=_buy, stop=close, limit=close, comment = "EXIT-SHORT_FTX_XRP-PERP_scalper_1M_8eafb86c43a4915e")⋯ //strategy.entry('sell', strategy.short)- strategy.entry("short", strategy.short, when = _sell)+ if _sell+ strategy.entry("short", strategy.short) //strategy.exit("long", when=_sell, stop=close, limit=close, comment = "EXIT-LONG_FTX_XRP-PERP_scalper_1M_8eafb86c43a4915e")⋯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: 87 before, 79 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.
⋯// © Gammapips-//@version=5+//@version=6strategy('My five in one strategy for ETHUSD 700x v4 //smooth code', overlay=true, default_qty_type = strategy.percent_of_equity)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 21 ms | With a workaround 1,000 bars in 67 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
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.
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/// © Gammapips//@version=5strategy('My five in one strategy for ETHUSD 700x v4 //smooth code', overlay=true, default_qty_type = strategy.percent_of_equity)// xrpusd BEST OF THE BEST IS LENGHT 10 20 4 HOURS 1 day pm 0.7 / 3.3.// xrpusd BEST OF THE BEST IS LENGHT 10 18 4 HOURS 1 WEEK pm 0.7 / 3.3// ETHUSD 27% dropdoen 500x length 8 17 swap 8HOURS 1 week , pm 0.7 / 3.3 sortino 2.7 sharp 0.29//BNBUSD 49% dropdown 350x length 6 33 swap 8 hours 1 week , pm 0.9 / 6 sortino 3.4 sharp 0.25//DOGEUSD 24% dropdown 2000x length 5 34 swap 8 hours 1 week , pm 0.7 / 4 sortino 10.7 sharp 0.38//ADAUSD 30% dropdown 4000x length 6 27 swap 8 hours 1 week , pm 0.7 / 4 sortino 4.2 sharp 0.32//NEMUSD 30% dropdown 60x length 2 25 swap 4 hours 1 week , pm 0.8 / 2.3 sortino 1.6 sharp 0.45//ETHUSD 55% dropdown 900x length 6 26 swap 4 hours 1 week , pm 0.7 / 3.4 sortino 2.6 sharp 0.34//ETHUSD 48% dropdown 700x length 6 26 swap 8 hours 1 week , pm 0.7 / 3.4 sortino 2.33 sharp 0.33//ETH USD 45% dropdown 500x length 6 26 swap 1 week 1 week , pm 0.7 / 3.4 sortino 2.4 sharp 0.32//LTCUSD length 10 35 swap 4 hours 1 week , pm 0.7 / 3.1// BTCUSD length 8 36 swap 4 hours 1 week , pm 0.6 / 3.1// xrpusd BEST OF THE BEST IS LENGHT 2 (or 11) 19 4 HOURS 1 WEEK pm 0.7 / 3.3// 1h trading ... length 5 .. 14 swap 15 min 1 hour//InputsresIn_0 = input.timeframe(title='Resolution for Funding Interval', defval="480") // 480 is 8 hours timeframeres = resIn_0 == '0' ? timeframe.period : resIn_0resIn_1 = input.timeframe(title='Resolution for TWAP Interval', defval='240')res_1 = resIn_1 == '0' ? timeframe.period : resIn_1source = input.source(close, title="Momentum Source")_length = input.int(6, title="Momentum Length")length = input.int(26, defval = 7, minval = 1, maxval = 1000, title="Aroon Length")fromyear = input.int(2018, defval = 2018, minval = 1900, maxval = 2100, title = "From Year")toyear = input.int(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")perp_ticker = input.symbol(title='Perp Ticker', defval='BITMEX:XBTUSD')spot_ticker = input.symbol(title='Spot Ticker', defval='BITMEX:XBT')top = input.float(0.7, step=0.1)bottom = input.float(3.4, step=0.1)// Inputsi_stratSelect = input.string(defval='macd', title='Select Strategy', options=['rsi', 'macd', 'bb', 'rsi + macd', 'tt','pm','aroon', 'aroon1 + pm'])//Momentummom = ta.mom(source, _length)//Buy/Sell Momentumsell = mom < 0buy = mom > 0// Takes an average of prices for each ticker, for use in TWAP calctypicalPrice_fut = (request.security(perp_ticker, res, open) + request.security(perp_ticker, res, high) + request.security(perp_ticker, res, low) + request.security(perp_ticker, res, close)) / 4typicalPrice_idx = (request.security(spot_ticker, res, open) + request.security(spot_ticker, res, high) + request.security(spot_ticker, res, low) + request.security(spot_ticker, res, close)) / 4weight = ta.barssince(ta.change(request.security(perp_ticker, res_1, time, lookahead=barmerge.lookahead_on)))// calculate basic funding rate ratioratio = typicalPrice_fut / typicalPrice_idx - 1// initialize priceprice = 0.0// calc TWAP and 8hr funding rate price := weight == 0 ? ratio : ratio + nz(price[1])twap = price / (weight + 1)funding_1hr = twap * (1.0 / 24.0) * 100.0funding_8hr = twap * (8.0 / 24.0) * 100.0count_up = 0 // Declare the global count variablecount_up := nz(count_up[1], 0) // Reassign the count variable to the previous value. If it was na then change it to 0Counter_up() => if funding_8hr > 0.0098 count_up + 1 else 0count_up := Counter_up() count_down = 0 // Declare the global count variablecount_down := nz(count_down[1], 0) // Reassign the count variable to the previous value. If it was na then change it to 0Counter_down() => if funding_8hr < -0.0098 count_down + 1 else 0count_down := Counter_down() // Modify the global variable in the global scope.nn=0funding_up = falseif count_up > nn funding_up := true funding_down = falseif count_down > nn funding_down := true miningRevenue = request.security('QUANDL:BCHAIN/MIREV', 'D', close[1], barmerge.gaps_off, barmerge.lookahead_on)ma365 = request.security('QUANDL:BCHAIN/MIREV', 'D', ta.sma(close, 365)[1], barmerge.gaps_off, barmerge.lookahead_on)puellMultiple = miningRevenue / ma365//Aroonupper = 200 * (ta.highestbars(high, length+1) + length)/lengthlower = 200 * (ta.lowestbars(low, length+1) + length)/length//////////plot(upper, color=#FF6A00)//////////plot(lower, color=#0094FF)i_stratSelect := 'macd'if buy i_stratSelect := 'aroon1 + pm'f_strategySelector(_strat) => if _strat == 'macd' [macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9) macdbuyCondition = histLine > 0 and ta.crossover(macdLine, signalLine) macdsellCondition = histLine < 0 and ta.crossunder(macdLine, signalLine) [macdbuyCondition, macdsellCondition] else if _strat == 'aroon1 + pm' //Signals yas1 = puellMultiple < top no1 = puellMultiple > bottom up1 = upper > lower dn1 = upper < lower [up1 or yas1, dn1 or no1] else if _strat == 'aroon' //Signals up = upper > lower dn = upper < lower [up, dn] else [na, na] [_buy, _sell] = f_strategySelector(i_stratSelect)smonadnu = puellMultiple < top smonavrhu = puellMultiple > bottomif _buy and year >= fromyear and year <= toyear and (month > 1 or dayofmonth > 6 or true) and strategy.equity > 0 and ( not funding_up or false ) and not smonavrhu //strategy.entry('buy', strategy.long) /// LONG strategy.entry("long", strategy.long, when = _buy) // strategy.exit("short", when=_buy, stop=close, limit=close, comment = "EXIT-SHORT_FTX_XRP-PERP_scalper_1M_8eafb86c43a4915e") if _sell and year >= fromyear and year <= toyear and strategy.equity > 0 and ( not funding_down or false ) and not smonadnu //strategy.entry('sell', strategy.short) strategy.entry("short", strategy.short, when = _sell) //strategy.exit("long", when=_sell, stop=close, limit=close, comment = "EXIT-LONG_FTX_XRP-PERP_scalper_1M_8eafb86c43a4915e")//if sell and year >= fromyear and year <= fromyear and strategy.equity > 0 and ( funding_up or false ) and not smonadnu // and na //strategy.close('buy', when = sell) //if time > timestamp(toyear, tomonth, today, 23, 59) //strategy.close_all()