Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Linear On MACD

A Pine Script v5 strategy built on CUM or Change, CUM (math.sign(chng) * volume) and SMA or EMA (src, 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. 7 settings; defaults include Fast Length 12, Slow Length 26 and Risk tolerance LOW.

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 Linear On MACD repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 8 of 8 trades.
How did Linear On MACD do on BTCUSDT 1D with default settings?
+1.47%
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 Linear On MACD 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, 66 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 Linear On MACD use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Linear On MACD run in Zeal Terminal?
Yes
It compiles in 45 ms and runs 1,000 bars in 51 ms, in the browser.

BTCUSDT · 1D · default settings

  • Predicted Stock Price
  • Predicted Stock Price
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,006,570$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
+1.47%
$14,704.50
Buy and hold
+102.5%
same period
Closed trades
16
6 won · 10 lost
Profitable
37.5%
of closed trades
Profit factor
1.25
gross profit ÷ gross loss
Max drawdown
5.57%
−$56,140.50

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.

  • 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.

SettingDefaultType and rangeFeeds
Fast Length12intfast_ma
Slow Length26intslow_ma
Risk toleranceLOWstring · options ["LOW", "HIGH"]line 73
Signal Smoothing9int · min 1 · max 50signal
Oscillator MA TypeEMAstring · options ["SMA", "EMA"]fast_ma slow_ma
Signal Line MA TypeEMAstring · options ["SMA", "EMA"]signal
Lookback21intybar xbar b a risklevel Predicted Stock Price

What it calculates

  • CUM / Changemath.sign(ta.change(close)) * volumeobv · line 9
  • CUMmath.sign(chng) * volumeobvalt · line 16
  • SMA / EMAsrc, Fast Length (12) · chosen by Oscillator MA Typefast_ma · line 23
  • SMA / EMAsrc, Slow Length (26) · chosen by Oscillator MA Typeslow_ma · line 24
  • SMA / EMAmacd, Signal Smoothing (9) · chosen by Signal Line MA Typesignal · line 26
  • MACDclose, 12, 26, 9macdLine · line 32
  • MACDclose, 12, 26, 9signalLine · line 32
  • MACDclose, 12, 26, 9histLine · line 32
  • Risingmacd, 2macdrise · line 57
  • Fallingmacd, 1macdfall · line 69
  • VWMApredicted_price, Lookback (21)risklevel · line 72

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.

closecloseprice datavolumevolumeprice datasma_sourceOscillator MA Typesetting · EMAfast_lengthFast Lengthsetting · 12slow_lengthSlow Lengthsetting · 26sma_signalSignal Line MA Typesetting · EMAsignal_lengthSignal Smoothingsetting · 9lenLookbacksetting · 21openopenprice dataobvCUM / Change→ obvobvaltCUM→ obvaltfast_maSMA / EMA→ fast_ma · by Oscillator MA …slow_maSMA / EMA→ slow_ma · by Oscillator MA …signalSMA / EMA→ signal · by Signal Line MA …macdLineMACD→ macdLinesignalLineMACD→ signalLinehistLineMACD→ histLinemacdriseRising→ macdrisemacdfallFalling→ macdfallrisklevelVWMA→ risklevelsrcsrcvaluemacdmacdvaluehisthistvaluevolvolvalueybar, xbarybar · xbar2 valuesb, ab · a2 valuespricepricevaluepredicted_pricepredicted_pricevalueis_betweenis_betweenconditionlincrossunder, lincrossoverlincrossunder · lincros…2 conditionsmacdvollong, macdsellmacdvollong · macdsell2 conditionsmacdlongmacdlongconditionentry:My Long Entry IdOpen My Long Entry Idstrategy.entryentry:My Short Entry IdOpen My Short Entry Idstrategy.entryplot:53Predicted Stock Priceplotplot:54Predicted Stock Priceplot

Order rules

OrderFires whenBy defaultLine
Open My Long Entry Id long(longCondition)On66
Open My Short Entry Id short(shortCondition)On78

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.

8/8trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+1.5%+102.5%1638%1.255.6%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+1.4%+5.5%1547%1.671.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.3%+9.8%1669%3.420.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%2133%1.900.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%2642%1.110.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%2532%0.640.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%1947%0.760.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%2941%1.610.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 barsTradesWonP&L
Rising market1100%$8,343.81
Sideways market650%$30,992.00
Falling market922%−$24,631.30

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

5.0%

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.8% to 5.0%; the tick is what actually happened, 3.1%. Order luck alone moves it this much.

0%6%
All 16 trades
SideEntryExitBarsP&L
short16 Mar 2024 69,499.8022 Aug 2024 61,156.00159$8,343.81
long22 Aug 2024 61,156.002 Sep 2024 57,301.8011−$3,854.26
short2 Sep 2024 57,301.802 Apr 2025 85,158.40212−$27,856.60
long2 Apr 2025 85,158.4031 May 2025 103,985.0059$18,827.10
short31 May 2025 103,985.0011 Sep 2025 113,960.00103−$9,974.53
long11 Sep 2025 113,960.0024 Sep 2025 111,999.0013−$1,961.20
short24 Sep 2025 111,999.003 Dec 2025 91,277.9070$20,720.90
long3 Dec 2025 91,277.9021 Jan 2026 88,427.7049−$2,850.22
short21 Jan 2026 88,427.7011 Mar 2026 69,948.6049$18,479.00
long11 Mar 2026 69,948.6028 Mar 2026 66,407.3017−$3,541.36
short28 Mar 2026 66,407.3027 Jul 2026 65,400.00121$1,007.28
long27 Jul 2026 65,400.0028 Jul 2026 63,755.901−$1,644.14
short28 Jul 2026 63,755.908 Aug 2026 64,923.2011−$1,167.34
long8 Aug 2026 64,923.2012 Aug 2026 63,600.004−$1,323.19
short12 Aug 2026 63,600.0020 Aug 2026 69,334.808−$5,734.77
long20 Aug 2026 69,334.8011 Sep 2026 76,568.7022$7,233.95

Similar scripts

Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.

ScriptSharesTypeNetTradesMax drawdown
Linear On MACD this page—v5 strategy+1.5%165.6%
Altered OBV On MACD by stocktechbotsma cum macd rising fallingv5 strategy+0.1%474.4%
Linear Cross Trading Strategy by stocktechbotsma macd rising fallingv5 strategy+9.7%142.7%
Accumulation Stage Identifier and Strategy around for Trading by stocktechbotsma cum macd rising fallingv5 strategy−0.0%164.1%
5min MACD scalp by Joel by Zippy111ema macd rising fallingv5 strategydoes not run in Zeal Terminal
cRSI + Waves Strategy with VWMA overlay by Dr_Robotovwma macd rising fallingv4 strategyNo trades on this market

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, 6, 45). 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.

Clean v5

VerifiedDownload the v5 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 6: input() → input.int()
  • Line 45: input() → input.int()
⋯strategy("Linear On MACD", overlay=true, margin_long=100, margin_short=100)-fast_length = input(title="Fast Length", defval=12)+fast_length = input.int(title="Fast Length", defval=12)-slow_length = input(title="Slow Length", defval=26)+slow_length = input.int(title="Slow Length", defval=26)tolerance = input.string(title="Risk tolerance", defval = "LOW", options=["LOW", "HIGH"])⋯// Length of linear regression-len = input(defval = 21, title = 'Lookback')+len = input.int(defval = 21, title = 'Lookback')// Calculate linear regression for stock price based on volume⋯

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, 66 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("Linear On MACD", overlay=true, margin_long=100, margin_short=100)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 45 msYes 1,000 bars in 51 msNot measured
PineTSNot testedNot testedNot 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("Linear On MACD", overlay=true, margin_long=100, margin_short=100)fast_length = input(title="Fast Length", defval=12)slow_length = input(title="Slow Length", defval=26)tolerance = input.string(title="Risk tolerance", defval = "LOW", options=["LOW", "HIGH"])chng = 0obv = ta.cum(math.sign(ta.change(close)) * volume)if close < close[1] and (open < close)    chng := 1else if close > close[1]    chng := 1else    chng := -1obvalt = ta.cum(math.sign(chng) * volume)//src = input(title="Source", defval=close)src = obvaltsignal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9)sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])// Calculatingfast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)macd = fast_ma - slow_masignal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)hist = macd - signal//hline(0, "Zero Line", color=color.new(#787B86, 50))//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))//plot(macd, title="MACD", color=col_macd)//plot(signal, title="Signal", color=col_signal)[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)//Linear Regressionvol = volume// Function to calculate linear regressionlinregs(y, x, len) =>    ybar = math.sum(y, len)/len    xbar = math.sum(x, len)/len    b = math.sum((x - xbar)*(y - ybar),len)/math.sum((x - xbar)*(x - xbar),len)    a = ybar - b*xbar    [a, b]// Historical stock price dataprice = close// Length of linear regressionlen = input(defval = 21, title = 'Lookback')// Calculate linear regression for stock price based on volume[a, b] = linregs(price, vol, len)// Predicted stock price based on volumepredicted_price = a + b*vol// Check if predicted price is between open and closeis_between = open < predicted_price and predicted_price < close// Plot predicted stock priceplot(predicted_price, color=color.rgb(218, 27, 132), linewidth=2, title="Predicted Stock Price")plot(ta.vwma(predicted_price,len), color=color.rgb(199, 43, 64), linewidth=2, title="Predicted Stock Price")//BUY Signallincrossunder = close > predicted_pricemacdrise = ta.rising(macd,2)//macdvollong = ta.crossover(macd, signal)//macdlong = ta.crossover(macdLine, signalLine)macdvollong = macd > signalmacdlong = macdLine > signalLinelongCondition=falseif macdlong and macdvollong and is_between and ta.rising(predicted_price,1)    longCondition := trueif (longCondition)    strategy.entry("My Long Entry Id", strategy.long)//Sell Signallincrossover = close < predicted_pricemacdfall = ta.falling(macd,1)macdsell = macd < signalshortCondition = falserisklevel = predicted_priceif (tolerance == "HIGH")    risklevel := ta.vwma(predicted_price,len)if macdfall and macdsell and (macdLine < signalLine) and (close < risklevel)    shortCondition := trueif (shortCondition)    strategy.entry("My Short Entry Id", strategy.short)