Pine Script v4 · Strategy
Jim's MACD
A Pine Script v4 strategy built on MACD (close, 12) and WMA (src, hlength, floor(sqrt(hlength))). It has 4 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. 5 settings; defaults include Mlength 12, Signal Length 9 and Hlength 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 Jim's MACD repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Jim's MACD do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a session window, which can leave these candles out. On BTCUSDT 4h it did trade; that row of the markets table below has its figures. A backtest, not investment advice.
- Can Jim's MACD 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.
- Does Jim's MACD use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Jim's MACD run in Zeal Terminal?
- Yes
- It compiles in 15 ms and runs 1,000 bars in 37 ms, in the browser.
BTCUSDT · 1D · default settings
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
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.
-
Check
1 setting does nothing
“Check here for tendies” is 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
3 settings have no label
In the settings dialog mlength (line 7), signalLength (line 15), hlength (line 18) 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 30, 32, 35, 36. 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 macd → ta.macd, wma → ta.wma, floor → math.floor, sqrt → math.sqrt.
- 4 strategy calls use the when = argument (line 30, 32, 35, 36). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 32 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 16: macd → ta.macd
- Line 20: wma → ta.wma
- Line 20: wma → ta.wma
- Line 20: wma → ta.wma
- Line 20: floor → math.floor
- Line 20: sqrt → math.sqrt
⋯// © melihtuna-//@version=4+//@version=5strategy("Jim's MACD v8", overlay=true)⋯signalLength=input(9)-[macdLine, signalLine, histLine] = macd(close, 12, 26, signalLength)+[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, signalLength)//Hullema⋯src = input(close, title="Source")-hullma = wma(2*wma(src, hlength/2)-wma(src, hlength), floor(sqrt(hlength)))+hullma = ta.wma(2*ta.wma(src, hlength/2)-ta.wma(src, hlength), math.floor(math.sqrt(hlength)))//Time⋯Same 32 trades and the same P&L on BTCUSDT 4h, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.bool()
- Line 7: input() → input.int()
- Line 15: input() → input.int()
- Line 18: input() → input.int()
- Line 19: input() → input.source()
- Line 30: when = b == 1 → if block
3 more edits
- Line 32: when = b == 1 → if block
- Line 35: when = histLine < 0 or c == 0 → if block
- Line 36: when = histLine > 0 or c == 0 → if block
⋯strategy("Jim's MACD v8", overlay=true)-Tendies = input(true, title="Check here for tendies")+Tendies = input.bool(true, title="Check here for tendies")//Momentum Logic-mlength = input(12)+mlength = input.int(12)price = close⋯//MACD Setup -signalLength=input(9)+signalLength=input.int(9)[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, signalLength)//Hullema-hlength = input(9, minval=1)+hlength = input.int(9, minval=1)-src = input(close, title="Source")+src = input.source(close, title="Source")hullma = ta.wma(2*ta.wma(src, hlength/2)-ta.wma(src, hlength), math.floor(math.sqrt(hlength)))⋯if( mom0 > 0 and mom1 > 0 and histLine > 0 and signalLine < 0 and close > hullma ) - strategy.entry( "BUY", strategy.long, when = b == 1 )+ if b == 1+ strategy.entry( "BUY", strategy.long )if( mom0 < 0 and mom1 < 0 and histLine < -0.1 and signalLine > 0 and close < hullma )- strategy.entry( "SELL", strategy.short, when = b == 1 )+ if b == 1+ strategy.entry( "SELL", strategy.short ) //Exit -strategy.close("BUY", when = histLine < 0 or c == 0)+if histLine < 0 or c == 0+ strategy.close("BUY")-strategy.close("SELL", when = histLine > 0 or c == 0)+if histLine > 0 or c == 0+ strategy.close("SELL")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: 32 before, 24 after on BTCUSDT 4h, 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.
⋯// © melihtuna-//@version=5+//@version=6strategy("Jim's MACD v8", 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 |
|---|---|---|---|
| Check here for tendies | true | bool | unused |
| Mlength (no label in the script) | 12 | int | mom mom0 |
| Signal Length (no label in the script) | 9 | int | macdLine signalLine histLine |
| Hlength (no label in the script) | 9 | int · min 1 | hullma |
| Source | close | source | hullma |
What it calculates
- MACD (
macd,ta.macdin v5)close, 12, 26, Signal Length (9)macdLine · line 16 - MACD (
macd,ta.macdin v5)close, 12, 26, Signal Length (9)signalLine · line 16 - MACD (
macd,ta.macdin v5)close, 12, 26, Signal Length (9)histLine · line 16 - WMA (
wma,ta.wmain v5)2*wma(src, hlength/2)-wma(src, hlength), floor(sqrt(hlength))hullma · line 20
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 BUY long | b == 1 | On | 30 |
| Open SELL short | b == 1 | On | 32 |
| Close BUY | histLine < 0 or c == 0 | On | 35 |
| Close SELL | histLine > 0 or c == 0 | On | 36 |
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.
- 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% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +1.8% | +5.5% | 32 | 50% | 1.37 | 2.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 34 | 38% | 1.09 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 26 | 46% | 1.12 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 36 | 47% | 1.38 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 15 ms | With a workaround 1,000 bars in 37 ms | Not measured |
| PineTS | No v5 and v6 only | — | 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. 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/// © melihtuna//@version=4strategy("Jim's MACD v8", overlay=true)Tendies = input(true, title="Check here for tendies")//Momentum Logicmlength = input(12)price = closemomentum(seria, mlength) => mom = seria - seria[mlength] mommom0 = momentum(price, mlength)mom1 = momentum( mom0, 1)//MACD Setup signalLength=input(9)[macdLine, signalLine, histLine] = macd(close, 12, 26, signalLength)//Hullemahlength = input(9, minval=1)src = input(close, title="Source")hullma = wma(2*wma(src, hlength/2)-wma(src, hlength), floor(sqrt(hlength)))//Timeentryt = time(timeframe.period, "0955-1430,1755-2030") //Ensures no new trades in last 30 minutes exitt = time(timeframe.period, "0955-1500,1755-2100") //Trading times : 11AM-4PM , 7PM-10PM EST b = (na(entryt) ? 0 : 1)c = (na(exitt) ? 0 : 1)//Bar coloringbarcolor((strategy.position_size>0)?color.green:(strategy.position_size<0)?color.red:color.white)//Entryif( mom0 > 0 and mom1 > 0 and histLine > 0 and signalLine < 0 and close > hullma ) strategy.entry( "BUY", strategy.long, when = b == 1 )if( mom0 < 0 and mom1 < 0 and histLine < -0.1 and signalLine > 0 and close < hullma ) strategy.entry( "SELL", strategy.short, when = b == 1 ) //Exit strategy.close("BUY", when = histLine < 0 or c == 0)strategy.close("SELL", when = histLine > 0 or c == 0)