Pine Script v5 · Strategy
Accumulation Stage Identifier and Strategy around for Trading
A Pine Script v5 strategy built on SMA (close, 200), CUM or Change and MACD (ta.pvt, 12). 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 is one contract and pays no commission. 4 settings; defaults include Lookback 21, Offset 0 and Entry Line 21.
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 Accumulation Stage Identifier and Strategy around for Trading repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did Accumulation Stage Identifier and Strategy around for Trading do on BTCUSDT 1D with default settings?
- −0.02%
- From 26 Jan 2024 to 21 Oct 2026, over 16 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Accumulation Stage Identifier and Strategy around for Trading 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: 16 before, 41 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 Accumulation Stage Identifier and Strategy around for Trading use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Accumulation Stage Identifier and Strategy around for Trading run in Zeal Terminal?
- Yes
- It compiles in 23 ms and runs 1,000 bars in 79 ms, in the browser.
BTCUSDT · 1D · default settings
- MA200
- MA50
- MA90
- MA21
- Buy Signal
- Sell Signal
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −0.02%
- −$246.24
- Buy and hold
- +102.5%
- same period
- Closed trades
- 16
- 5 won · 11 lost
- Profitable
- 31.3%
- of closed trades
- Profit factor
- 1.00
- gross profit ÷ gross loss
- Max drawdown
- 4.07%
- −$41,145.90
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
2 settings do nothing
“Entry Line”, “Exit Line” are declared but never read.
-
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.
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 |
|---|---|---|---|
| Lookback | 21 | int | fourlow fourhig |
| Offset | 0 | int · min -500 · max 500 | MA200 MA50 MA90 MA21 |
| Entry Line | 21 | int | unused |
| Exit Line | 21 | int | unused |
What it calculates
- SMAclose, 200
out · line 8 - SMAclose, 50
outf · line 9 - SMAclose, 90
outn · line 10 - SMAclose, 21
outt · line 11 - CUM / Changemath.sign(ta.change(close)) * volume
obv · line 35 - SMAobv, 5
smoothingLine · line 37 - MACDta.pvt, 12, 26, 9
macdLine · line 38 - MACDta.pvt, 12, 26, 9
signalLine · line 38 - MACDta.pvt, 12, 26, 9
histLine · line 38 - Risinghigh, 2
higheshigh · line 45 - Risinglow, 2
higheslow · line 46 - Risingout, 2
twohunraise · line 47 - Risingvolume, 2
highvol · line 49 - Lowestclose, Lookback (21)
fourlow · line 50 - Highestclose, Lookback (21)
fourhig · line 51 - Fallinghigh, 3
lowesthigh · line 68 - Fallinglow, 2
lowestlow · line 69 - Fallingout, 3
twohunfall · line 70 - Fallingoutt, 2
twentyfall · line 71 - Crossover / SMAvolume, ta.sma(volume, 5)
highvole · line 72 - ATR14
atr · line 77 - Crossover / SMAta.sma(close, 14), ta.sma(close, 28)
longCondition · line 91 - Crossunder / SMAta.sma(close, 14), ta.sma(close, 28)
shortCondition · line 94
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 My Long Entry Id long | (allup) | On | 93 |
| Open My Short Entry Id short | (alldwn) | On | 96 |
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 | −0.0% | +102.5% | 16 | 31% | 1.00 | 4.1% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.5% | +5.5% | 24 | 33% | 0.64 | 3.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −0.2% | +9.8% | 14 | 29% | 0.47 | 0.5% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 22 | 36% | 1.46 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 18 | 39% | 0.96 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 18 | 17% | 0.54 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 22 | 32% | 0.92 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 18 | 33% | 1.19 | 0.0% | 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 | 9 | 22% | −$13,315.30 |
| Sideways market | 7 | 43% | $13,069.00 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
4.9%
The 95th percentile of the worst drawdown when the same 16 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 2.1% to 4.9%; the tick is what actually happened, 3.5%. Order luck alone moves it this much.
All 16 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Mar 2024 69,499.80 | 7 Nov 2024 75,572.00 | 236 | −$6,072.15 |
| long | 7 Nov 2024 75,572.00 | 26 Nov 2024 93,010.00 | 19 | $17,438.00 |
| short | 26 Nov 2024 93,010.00 | 7 Jan 2025 102,236.00 | 42 | −$9,225.59 |
| long | 7 Jan 2025 102,236.00 | 9 Jan 2025 95,060.60 | 2 | −$7,174.99 |
| short | 9 Jan 2025 95,060.60 | 16 Jan 2025 100,497.00 | 7 | −$5,436.74 |
| long | 16 Jan 2025 100,497.00 | 3 Feb 2025 97,700.60 | 18 | −$2,796.76 |
| short | 3 Feb 2025 97,700.60 | 26 Jun 2025 107,341.00 | 143 | −$9,640.00 |
| long | 26 Jun 2025 107,341.00 | 26 Jul 2025 117,614.00 | 30 | $10,273.70 |
| short | 26 Jul 2025 117,614.00 | 15 Aug 2025 118,295.00 | 20 | −$680.78 |
| long | 15 Aug 2025 118,295.00 | 16 Aug 2025 117,342.00 | 1 | −$953.05 |
| short | 16 Aug 2025 117,342.00 | 9 Sep 2025 112,065.00 | 24 | $5,276.81 |
| long | 9 Sep 2025 112,065.00 | 24 Sep 2025 111,999.00 | 15 | −$66.43 |
| short | 24 Sep 2025 111,999.00 | 28 Oct 2025 114,108.00 | 34 | −$2,108.85 |
| long | 28 Oct 2025 114,108.00 | 5 Nov 2025 101,497.00 | 8 | −$12,610.40 |
| short | 5 Nov 2025 101,497.00 | 26 Aug 2026 78,539.10 | 294 | $22,958.10 |
| long | 26 Aug 2026 78,539.10 | 8 Sep 2026 79,112.00 | 13 | $572.87 |
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 |
|---|---|---|---|---|---|
| Accumulation Stage Identifier and Strategy around for Trading this page | — | v5 strategy | −0.0% | 16 | 4.1% |
| ICHIMOKU Crypto Swing Strategy by exlux99 | highest lowest sma rising falling | v4 strategy | does not run in Zeal Terminal | ||
| Altered OBV On MACD by stocktechbot | sma cum macd rising falling | v5 strategy | +0.1% | 47 | 4.4% |
| Linear On MACD by stocktechbot | cum sma macd rising falling | v5 strategy | +1.5% | 16 | 5.6% |
| DC Breakout Strategy - This is simplicity at its finest. by Robrecht99 | sma highest lowest atr | v5 strategy | +10.8% | 57 | 8.3% |
| Linear Cross Trading Strategy by stocktechbot | sma macd rising falling | v5 strategy | +9.7% | 14 | 2.7% |
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.
- 3 settings use the untyped input() (line 5, 55, 67). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 16 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
- Line 55: input() → input.int()
- Line 67: input() → input.int()
⋯strategy("Accumulate", overlay = true)-lookback = input(defval = 21, title = 'Lookback')+lookback = input.int(defval = 21, title = 'Lookback')offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)⋯allup = false-lineabove = ta.cross(close, ta.sma(close, input(defval = 21, title = 'Entry Line')))+lineabove = ta.cross(close, ta.sma(close, input.int(defval = 21, title = 'Entry Line')))if matwohun and mafentry and higheshigh and twohunraise and buyvolhigh⋯matwohund = close < ta.sma(close, 200)-linebreak = ta.sma(close, input(defval = 21, title = 'Exit Line')) > close+linebreak = ta.sma(close, input.int(defval = 21, title = 'Exit Line')) > closelowesthigh = ta.falling(high, 3)⋯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: 16 before, 41 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.
⋯// © stocktechbot-//@version=5+//@version=6strategy("Accumulate", overlay = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 23 ms | Yes 1,000 bars in 79 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © stocktechbot//@version=5strategy("Accumulate", overlay = true)lookback = input(defval = 21, title = 'Lookback')offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)//SMA Tredlineout = ta.sma(close, 200)outf = ta.sma(close, 50)outn = ta.sma(close, 90)outt = ta.sma(close, 21)//sma plotplot(out, color=color.blue, title="MA200", offset=offset)plot(outf, color=color.maroon, title="MA50", offset=offset)plot(outn, color=color.orange, title="MA90", offset=offset)plot(outt, color=color.olive, title="MA21", offset=offset)//MarketCap Calculation//MarketCap = 0.0//TSO = request.financial(syminfo.tickerid, "TOTAL_SHARES_OUTSTANDING", "FQ", ignore_invalid_symbol = true)//if str.tostring(TSO) != 'na'// if ta.barssince(TSO != TSO[1] and TSO > TSO[1])==0// MarketCap := TSO * close// // if barstate.islast and MarketCap == 0// runtime.error("No MarketCap is provided by the data vendor.")// //momlen = 100//msrc = MarketCap//mom = msrc - msrc[momlen]//plotmom = if (mom > mom[1])// true//else// false//OBV with sma on macdobv = ta.cum(math.sign(ta.change(close)) * volume)smoothingLength = 5smoothingLine = ta.sma(obv,5)[macdLine, signalLine, histLine] = ta.macd(ta.pvt, 12, 26, 9)sellvolhigh = macdLine < signalLinebuyvolhigh = macdLine > signalLine//Buy Signalmafentry =ta.sma(close, 50) > ta.sma(close, 90)//matentry = ta.sma(close, 21) > ta.sma(close, 50)matwohun = close > ta.sma(close, 200)higheshigh = ta.rising(high, 2)higheslow = ta.rising(low, 2 )twohunraise = ta.rising(out, 2)//highvol = ta.crossover(volume, ta.sma(volume, lookback))highvol = ta.rising(volume,2)fourlow = ta.lowest(close, lookback)fourhig = ta.highest(close, lookback)change = (((fourhig - fourlow) / fourlow) * 100) <= 30green = close > openallup = falselineabove = ta.cross(close, ta.sma(close, input(defval = 21, title = 'Entry Line')))if matwohun and mafentry and higheshigh and twohunraise and buyvolhigh//if higheshigh and higheslow and highvol allup := trueplotshape(allup, style=shape.arrowup,location=location.belowbar, color=color.green, title = "Buy Signal")barsSinceLastEntry() => strategy.opentrades > 0 ? bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades - 1) : na //Sell Signalmafexit =ta.sma(close, 50) < ta.sma(close, 90)matexit = ta.sma(close, 21) < ta.sma(close, 50)matwohund = close < ta.sma(close, 200)linebreak = ta.sma(close, input(defval = 21, title = 'Exit Line')) > closelowesthigh = ta.falling(high, 3)lowestlow = ta.falling(low, 2 )twohunfall = ta.falling(out, 3)twentyfall = ta.falling(outt, 2)highvole = ta.crossover(volume, ta.sma(volume, 5))//fourlow = ta.lowest(close, lookback)//fourhig = ta.highest(close, lookback)changed = (((fourhig - close) / close) * 100) >= 10red = close < openatr = ta.atr(14)//atrsmalen = int(bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades - 1) )atrsmalen = barsSinceLastEntry()atrsma = falseatrlen = 5if str.tostring(atrsmalen) != 'NaN' and atrsmalen > 0 atrlen := atrsmalen atrsma := atr > ta.sma(atr,50)alldwn = falseif sellvolhigh and lowestlow and (close < close[1] and close < open)//if higheshigh and higheslow and highvol alldwn := trueplotshape(alldwn, style=shape.arrowdown,location=location.abovebar, color=color.red, title = "Sell Signal")longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))if (allup) strategy.entry("My Long Entry Id", strategy.long)shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))if (alldwn) strategy.entry("My Short Entry Id", strategy.short)