Pine Script v4 · Strategy
Atrend by OTS
A Pine Script v4 strategy built on EMA (close, 12), RSI (price, 18) and Crossover (vrsi, 30). It has 4 order rules, 4 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. 14 settings; defaults include Fast Length 12, Slowlength 26 and MACDLength 9.
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 Atrend by OTS repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 22 of 22 trades.
- How did Atrend by OTS do on BTCUSDT 1D with default settings?
- +12.10%
- From 26 Jan 2024 to 21 Oct 2026, over 76 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Atrend by OTS 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.
- What alerts does Atrend by OTS have?
- 3
- ATrend Buy; ATrend Sell; ATrend Direction Change.
- Does Atrend by OTS use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- Up Trend
- UpTrend Begins
- Down Trend
- DownTrend Begins
- DEMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +12.10%
- $12,097.30
- Buy and hold
- +102.5%
- same period
- Closed trades
- 76
- 28 won · 48 lost
- Profitable
- 36.8%
- of closed trades
- Profit factor
- 1.07
- gross profit ÷ gross loss
- Max drawdown
- 34.37%
- −$45,701.70
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.
-
Likely bug
crossover(delta, 0) ignores the settings line 12
Line 12 hard-codes 0 where line 22 uses “Over Sold”. Changing those settings moves one band but not this one.
crossover(delta, 0)crossover(delta, overSold) -
Likely bug
crossunder(delta, 0) ignores the settings line 14
Line 14 hard-codes 0 where line 23 uses “Over Bought”. Changing those settings moves one band but not this one.
crossunder(delta, 0)crossunder(delta, overBought) -
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
7 settings have no label
In the settings dialog fastLength (line 6), slowlength (line 7), MACDLength (line 8), length (line 17), overSold (line 18), overBought (line 19), length1 (line 64) 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 transp =, which v5 removed line 49
transp = on line 49, 50, 53, 54. v5 folds the transparency into the colour with color.new(c, transp).
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 ema → ta.ema, crossover → ta.crossover, crossunder → ta.crossunder, rsi → ta.rsi, sma → ta.sma, atr → ta.atr, max → math.max, min → math.min.
v4 → v5
VerifiedSame 76 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 9: ema → ta.ema
- Line 9: ema → ta.ema
- Line 10: ema → ta.ema
- Line 12: crossover → ta.crossover
- Line 14: crossunder → ta.crossunder
19 more edits
- Line 21: rsi → ta.rsi
- Line 22: crossover → ta.crossover
- Line 23: crossunder → ta.crossunder
- Line 30: input(type = input.integer) → input.int()
- Line 32: input(type = input.float) → input.float()
- Line 33: input(type = input.bool) → input.bool()
- Line 34: input(type = input.bool) → input.bool()
- Line 35: input(type = input.bool) → input.bool()
- Line 36: sma → ta.sma
- Line 36: tr → ta.tr
- Line 37: atr → ta.atr
- Line 40: max → math.max
- Line 43: min → math.min
- Line 49: transp = 0 → color.new(color.green, 0)
- Line 50: transp = 0 → color.new(color.white, 0)
- Line 53: transp = 0 → color.new(color.red, 0)
- Line 54: transp = 0 → color.new(color.red, 0)
- Line 66: ema → ta.ema
- Line 67: ema → ta.ema
⋯// © OTS Music-//@version=4+//@version=5strategy("Atrend by OTS", overlay=true)⋯MACDLength = input(9)-MACD = ema(close, fastLength) - ema(close, slowlength)+MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)-aMACD = ema(MACD, MACDLength)+aMACD = ta.ema(MACD, MACDLength)delta = MACD - aMACD-if (crossover(delta, 0))+if (ta.crossover(delta, 0)) strategy.entry("MACD buy", strategy.long, comment="MACD buy")-if (crossunder(delta, 0))+if (ta.crossunder(delta, 0)) strategy.entry("MACD sell", strategy.short, comment="MACD sell")⋯price = close-vrsi = rsi(price, length)+vrsi = ta.rsi(price, length)-co = crossover(vrsi, overSold)+co = ta.crossover(vrsi, overSold)-cu = crossunder(vrsi, overBought)+cu = ta.crossunder(vrsi, overBought)if (not na(vrsi))⋯//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)-Periods = input(title="ATR Period", type=input.integer, defval=10)+Periods = input.int(title="ATR Period", defval=10)src = input(hl2, title="Source")-Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)+Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)-changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)+changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true)-showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=false)+showsignals = input.bool(title="Show Buy/Sell Signals ?", defval=false)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=false)+highlighting = input.bool(title="Highlighter On/Off ?", defval=false)-atr2 = sma(tr, Periods)+atr2 = ta.sma(ta.tr, Periods)-atr= changeATR ? atr(Periods) : atr2+atr= changeATR ? ta.atr(Periods) : atr2up=src-(Multiplier*atr)up1 = nz(up[1],up)-up := close[1] > up1 ? max(up,up1) : up+up := close[1] > up1 ? math.max(up,up1) : updn=src+(Multiplier*atr)dn1 = nz(dn[1], dn)-dn := close[1] < dn1 ? min(dn, dn1) : dn+dn := close[1] < dn1 ? math.min(dn, dn1) : dntrend = 1⋯buySignal = trend == 1 and trend[1] == -1-plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)+plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.green, 0))-plotshape(buySignal and showsignals ? up : na, title="", text="", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.white, textcolor=color.white, transp=0)+plotshape(buySignal and showsignals ? up : na, title="", text="", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.white, 0), textcolor=color.white)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_line, linewidth=2, color=color.gray)sellSignal = trend == -1 and trend[1] == 1-plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)+plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(color.red, 0))-plotshape(sellSignal and showsignals ? dn : na, title="", text="", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignal and showsignals ? dn : na, title="", text="", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)⋯srcb = input(close, title="Source")-e1 = ema(srcb, length1)+e1 = ta.ema(srcb, length1)-e2 = ema(e1, length)+e2 = ta.ema(e1, length)dema = 2 * e1 - e2⋯Same 76 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 17: input() → input.int()
- Line 18: input() → input.int()
- Line 19: input() → input.int()
3 more edits
- Line 31: input() → input.source()
- Line 64: input() → input.int()
- Line 65: input() → input.source()
⋯strategy("Atrend by OTS", overlay=true)-fastLength = input(12)+fastLength = input.int(12)-slowlength = input(26)+slowlength = input.int(26)-MACDLength = input(9)+MACDLength = input.int(9)MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)⋯//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)-length = input( 18 )+length = input.int( 18 )-overSold = input( 30 )+overSold = input.int( 30 )-overBought = input( 70 )+overBought = input.int( 70 )price = close⋯Periods = input.int(title="ATR Period", defval=10)-src = input(hl2, title="Source")+src = input.source(hl2, title="Source")Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)⋯alertcondition(changeCond, title="ATrend Direction Change", message="ATrend has changed direction!")-length1 = input(25, minval=1)+length1 = input.int(25, minval=1)-srcb = input(close, title="Source")+srcb = input.source(close, title="Source")e1 = ta.ema(srcb, length1)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L55:C56: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © OTS Music-//@version=5+//@version=6strategy("Atrend by OTS", 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 |
|---|---|---|---|
| Fast Length (no label in the script) | 12 | int | MACD |
| Slowlength (no label in the script) | 26 | int | MACD |
| MACDLength (no label in the script) | 9 | int | aMACD |
| Length (no label in the script) | 18 | int | vrsi e2 |
| Over Sold (no label in the script) | 30 | int | co |
| Over Bought (no label in the script) | 70 | int | cu |
| ATR Period | 10 | int (written input.integer) | atr2 atr |
| Source | hl2 | source | up dn |
| ATR Multiplier | 3.0 | float · step 0.1 | up dn |
| Change ATR Calculation Method ? | true | bool | atr |
| Show Buy/Sell Signals ? | false | bool | plotshape |
| Highlighter On/Off ? | false | bool | longFillColor shortFillColor |
| Length1 (no label in the script) | 25 | int · min 1 | e1 |
| Source | close | source | e1 |
What it calculates
- EMA (
ema,ta.emain v5)close, Fast Length (12)MACD · line 9 - EMA (
ema,ta.emain v5)MACD, MACDLength (9)aMACD · line 10 - RSI (
rsi,ta.rsiin v5)price, Length (18)vrsi · line 21 - Crossover (
crossover,ta.crossoverin v5)vrsi, Over Sold (30)co · line 22 - Crossunder (
crossunder,ta.crossunderin v5)vrsi, Over Bought (70)cu · line 23 - SMA (
sma,ta.smain v5)tr, ATR Period (10)atr2 · line 36 - ATR (
atr,ta.atrin v5)ATR Period (10)atr · line 37 - EMA (
ema,ta.emain v5)Source (close), Length1 (25)e1 · line 66 - EMA (
ema,ta.emain v5)e1, Length (18)e2 · line 67
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 MACD buy long | (crossover(delta, 0)) | On | 13 |
| Open MACD sell short | (crossunder(delta, 0)) | On | 15 |
| Open RSI buy long | (co) | On | 26 |
| Open RSI sell short | (cu) | On | 28 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| ATrend Buy | alertcondition | ATrend Buy! | 60 |
| ATrend Sell | alertcondition | ATrend Sell! | 61 |
| ATrend Direction Change | alertcondition | ATrend has changed direction! | 63 |
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% | 76 | 37% | 1.07 | 34.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +7.5% | +5.5% | 68 | 41% | 1.15 | 15.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −1.3% | +9.8% | 72 | 33% | 0.88 | 3.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.4% | +8.4% | 76 | 33% | 0.83 | 0.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 64 | 45% | 1.02 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 71 | 34% | 0.92 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.3% | +148.3% | 68 | 49% | 1.26 | 0.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.1% | +17.1% | 77 | 31% | 1.22 | 0.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 | 25 | 36% | −$3,707.36 |
| Sideways market | 36 | 42% | $30,805.00 |
| Falling market | 15 | 27% | −$15,000.40 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
50.5%
The 95th percentile of the worst drawdown when the same 76 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 25.7% to 50.5%; the tick is what actually happened, 33.4%. Order luck alone moves it this much.
All 76 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Mar 2024 69,499.80 | 6 May 2024 64,012.00 | 51 | $5,487.84 |
| long | 6 May 2024 64,012.00 | 12 May 2024 60,826.00 | 6 | −$3,186.01 |
| short | 12 May 2024 60,826.00 | 13 May 2024 61,484.00 | 1 | −$658.01 |
| long | 13 May 2024 61,484.00 | 31 May 2024 68,352.20 | 18 | $6,868.17 |
| short | 31 May 2024 68,352.20 | 6 Jun 2024 71,108.00 | 6 | −$2,755.83 |
| long | 6 Jun 2024 71,108.00 | 9 Jun 2024 69,310.50 | 3 | −$1,797.54 |
| short | 9 Jun 2024 69,310.50 | 13 Jul 2024 57,889.10 | 34 | $11,421.40 |
| long | 13 Jul 2024 57,889.10 | 1 Aug 2024 64,628.00 | 19 | $6,738.92 |
| short | 1 Aug 2024 64,628.00 | 20 Aug 2024 59,438.50 | 19 | $5,189.51 |
| long | 20 Aug 2024 59,438.50 | 31 Aug 2024 59,124.00 | 11 | −$314.51 |
| short | 31 Aug 2024 59,124.00 | 13 Sep 2024 58,132.30 | 13 | $991.68 |
| long | 13 Sep 2024 58,132.30 | 2 Oct 2024 60,804.90 | 19 | $2,672.61 |
| short | 2 Oct 2024 60,804.90 | 15 Oct 2024 66,084.00 | 13 | −$5,279.08 |
| long | 15 Oct 2024 66,084.00 | 27 Oct 2024 67,092.80 | 12 | $1,008.76 |
| short | 27 Oct 2024 67,092.80 | 29 Oct 2024 69,962.20 | 2 | −$2,869.45 |
| long | 29 Oct 2024 69,962.20 | 4 Nov 2024 68,776.00 | 6 | −$1,186.22 |
| short | 4 Nov 2024 68,776.00 | 7 Nov 2024 75,572.00 | 3 | −$6,796.00 |
| long | 7 Nov 2024 75,572.00 | 26 Nov 2024 93,010.00 | 19 | $17,438.00 |
| short | 26 Nov 2024 93,010.00 | 17 Dec 2024 106,059.00 | 21 | −$13,048.60 |
| long | 17 Dec 2024 106,059.00 | 19 Dec 2024 100,204.00 | 2 | −$5,854.64 |
| short | 19 Dec 2024 100,204.00 | 6 Jan 2025 98,363.60 | 18 | $1,840.40 |
| long | 6 Jan 2025 98,363.60 | 10 Jan 2025 92,552.50 | 4 | −$5,811.12 |
| short | 10 Jan 2025 92,552.50 | 16 Jan 2025 100,497.00 | 6 | −$7,944.86 |
| long | 16 Jan 2025 100,497.00 | 29 Jan 2025 101,336.00 | 13 | $838.17 |
| short | 29 Jan 2025 101,336.00 | 21 Feb 2025 98,305.00 | 23 | $3,030.51 |
| long | 21 Feb 2025 98,305.00 | 25 Feb 2025 91,552.90 | 4 | −$6,752.13 |
| short | 25 Feb 2025 91,552.90 | 2 Mar 2025 86,064.50 | 5 | $5,488.34 |
| long | 2 Mar 2025 86,064.50 | 9 Mar 2025 86,222.50 | 7 | $157.92 |
| short | 9 Mar 2025 86,222.50 | 16 Mar 2025 84,338.40 | 7 | $1,884.02 |
| long | 16 Mar 2025 84,338.40 | 7 Apr 2025 78,430.00 | 22 | −$5,908.44 |
| short | 7 Apr 2025 78,430.00 | 12 Apr 2025 83,423.80 | 5 | −$4,993.83 |
| long | 12 Apr 2025 83,423.80 | 13 May 2025 102,791.00 | 31 | $19,367.50 |
| short | 13 May 2025 102,791.00 | 19 May 2025 106,454.00 | 6 | −$3,662.95 |
| long | 19 May 2025 106,454.00 | 20 May 2025 105,574.00 | 1 | −$880.54 |
| short | 20 May 2025 105,574.00 | 22 May 2025 109,644.00 | 2 | −$4,070.26 |
| long | 22 May 2025 109,644.00 | 24 May 2025 107,318.00 | 2 | −$2,325.69 |
| short | 24 May 2025 107,318.00 | 11 Jun 2025 110,274.00 | 18 | −$2,956.09 |
| long | 11 Jun 2025 110,274.00 | 13 Jun 2025 105,672.00 | 2 | −$4,602.65 |
| short | 13 Jun 2025 105,672.00 | 27 Jun 2025 106,947.00 | 14 | −$1,275.32 |
| long | 27 Jun 2025 106,947.00 | 16 Jul 2025 117,758.00 | 19 | $10,811.00 |
| short | 16 Jul 2025 117,758.00 | 23 Jul 2025 119,954.00 | 7 | −$2,196.35 |
| long | 23 Jul 2025 119,954.00 | 24 Jul 2025 118,756.00 | 1 | −$1,198.43 |
| short | 24 Jul 2025 118,756.00 | 12 Aug 2025 118,686.00 | 19 | $70.00 |
| long | 12 Aug 2025 118,686.00 | 18 Aug 2025 117,405.00 | 6 | −$1,280.99 |
| short | 18 Aug 2025 117,405.00 | 7 Sep 2025 110,188.00 | 20 | $7,217.03 |
| long | 7 Sep 2025 110,188.00 | 24 Sep 2025 111,999.00 | 17 | $1,810.82 |
| short | 24 Sep 2025 111,999.00 | 2 Oct 2025 118,595.00 | 8 | −$6,596.19 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$5,820.50 |
| short | 11 Oct 2025 112,774.00 | 27 Oct 2025 114,559.00 | 16 | −$1,784.92 |
| long | 27 Oct 2025 114,559.00 | 4 Nov 2025 106,583.00 | 8 | −$7,976.36 |
| short | 4 Nov 2025 106,583.00 | 24 Nov 2025 86,830.00 | 20 | $19,753.10 |
| long | 24 Nov 2025 86,830.00 | 18 Dec 2025 86,243.20 | 24 | −$586.77 |
| short | 18 Dec 2025 86,243.20 | 21 Dec 2025 88,360.90 | 3 | −$2,117.68 |
| long | 21 Dec 2025 88,360.90 | 21 Jan 2026 88,427.70 | 31 | $66.75 |
| short | 21 Jan 2026 88,427.70 | 3 Feb 2026 78,738.60 | 13 | $9,689.06 |
| long | 3 Feb 2026 78,738.60 | 23 Mar 2026 67,859.00 | 48 | −$10,879.60 |
| short | 23 Mar 2026 67,859.00 | 26 Mar 2026 71,336.50 | 3 | −$3,477.53 |
| long | 26 Mar 2026 71,336.50 | 27 Mar 2026 68,820.30 | 1 | −$2,516.22 |
| short | 27 Mar 2026 68,820.30 | 7 Apr 2026 68,853.70 | 11 | −$33.35 |
| long | 7 Apr 2026 68,853.70 | 29 Apr 2026 76,342.80 | 22 | $7,489.12 |
| short | 29 Apr 2026 76,342.80 | 5 May 2026 79,861.00 | 6 | −$3,518.23 |
| long | 5 May 2026 79,861.00 | 13 May 2026 80,504.50 | 8 | $643.46 |
| short | 13 May 2026 80,504.50 | 12 Jun 2026 63,626.00 | 30 | $16,878.50 |
| long | 12 Jun 2026 63,626.00 | 28 Jun 2026 60,029.00 | 16 | −$3,596.99 |
| short | 28 Jun 2026 60,029.00 | 30 Jun 2026 60,260.20 | 2 | −$231.19 |
| long | 30 Jun 2026 60,260.20 | 1 Jul 2026 58,624.70 | 1 | −$1,635.49 |
| short | 1 Jul 2026 58,624.70 | 2 Jul 2026 60,024.00 | 1 | −$1,399.29 |
| long | 2 Jul 2026 60,024.00 | 28 Jul 2026 63,755.90 | 26 | $3,731.86 |
| short | 28 Jul 2026 63,755.90 | 8 Aug 2026 64,923.20 | 11 | −$1,167.34 |
| long | 8 Aug 2026 64,923.20 | 12 Aug 2026 63,600.00 | 4 | −$1,323.19 |
| short | 12 Aug 2026 63,600.00 | 19 Aug 2026 64,725.40 | 7 | −$1,125.41 |
| long | 19 Aug 2026 64,725.40 | 29 Aug 2026 77,845.90 | 10 | $13,120.50 |
| short | 29 Aug 2026 77,845.90 | 4 Sep 2026 81,270.40 | 6 | −$3,424.49 |
| long | 4 Sep 2026 81,270.40 | 5 Sep 2026 79,660.80 | 1 | −$1,609.60 |
| short | 5 Sep 2026 79,660.80 | 22 Sep 2026 86,620.00 | 17 | −$6,959.24 |
| long | 22 Sep 2026 86,620.00 | 24 Sep 2026 84,397.60 | 2 | −$2,222.41 |
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 |
|---|---|---|---|---|---|
| Atrend by OTS this page | — | v4 strategy | +12.1% | 76 | 34.4% |
| 3 x EMA + Stochastic RSI + ATR by tomimarson | ema rsi sma atr | v4 strategy | −42.3% | 18 | 44.8% |
| EMA crossover (daily TF) by tradeswithashish | ema sma rsi atr | v5 strategy | +11.0% | 12 | 11.6% |
| Delta-RSI Strategy (with filters) by tbiktag | rsi ema atr sma | v4 strategy | −28.8% | 71 | 83.8% |
| [KL] Bollinger bands + RSI Strategy by DojiEmoji | sma atr ema rsi | v4 strategy | +28.2% | 30 | 14.7% |
| 3x Supertrend and Stoch RSI by M3RZI | rsi sma ema atr | v4 strategy | −128.7% | 24 | 207.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 25 ms | Yes 1,000 bars in 83 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/// © prim722// © OTS Music//@version=4strategy("Atrend by OTS", overlay=true)fastLength = input(12)slowlength = input(26)MACDLength = input(9)MACD = ema(close, fastLength) - ema(close, slowlength)aMACD = ema(MACD, MACDLength)delta = MACD - aMACDif (crossover(delta, 0)) strategy.entry("MACD buy", strategy.long, comment="MACD buy")if (crossunder(delta, 0)) strategy.entry("MACD sell", strategy.short, comment="MACD sell")//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)length = input( 18 )overSold = input( 30 )overBought = input( 70 )price = closevrsi = rsi(price, length)co = crossover(vrsi, overSold)cu = crossunder(vrsi, overBought)if (not na(vrsi)) if (co) strategy.entry("RSI buy", strategy.long, comment="RSI buy") if (cu) strategy.entry("RSI sell", strategy.short, comment="RSI sell")//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)Periods = input(title="ATR Period", type=input.integer, defval=10)src = input(hl2, title="Source")Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=false)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=false)atr2 = sma(tr, Periods)atr= changeATR ? atr(Periods) : atr2up=src-(Multiplier*atr)up1 = nz(up[1],up)up := close[1] > up1 ? max(up,up1) : updn=src+(Multiplier*atr)dn1 = nz(dn[1], dn)dn := close[1] < dn1 ? min(dn, dn1) : dntrend = 1trend := nz(trend[1], trend)trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trendupPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_line, linewidth=2, color=color.white)buySignal = trend == 1 and trend[1] == -1plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)plotshape(buySignal and showsignals ? up : na, title="", text="", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.white, textcolor=color.white, transp=0)dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_line, linewidth=2, color=color.gray)sellSignal = trend == -1 and trend[1] == 1plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)plotshape(sellSignal and showsignals ? dn : na, title="", text="", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)longFillColor = highlighting ? (trend == 1 ? color.white : color.white) : color.whiteshortFillColor = highlighting ? (trend == -1 ? color.gray : color.white) : color.whitefill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)alertcondition(buySignal, title="ATrend Buy", message="ATrend Buy!")alertcondition(sellSignal, title="ATrend Sell", message="ATrend Sell!")changeCond = trend != trend[1]alertcondition(changeCond, title="ATrend Direction Change", message="ATrend has changed direction!")length1 = input(25, minval=1)srcb = input(close, title="Source")e1 = ema(srcb, length1)e2 = ema(e1, length)dema = 2 * e1 - e2plot(dema, "DEMA", color.red)