Pine Script v5 · Strategy
MACD Willy Strategy
A Pine Script v5 strategy built on RMA (ta.tr, 14), SMA (volume, 50) and EMA (close, 200). 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. 29 settings; defaults include Start Year 2011, Start Month 1 and Start Day 1.
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 MACD Willy Strategy repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did MACD Willy Strategy 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 entry conditions never all held on this data. It closed no trades on the other markets either. A backtest, not investment advice.
- What alerts does MACD Willy Strategy have?
- 4
- Long Signal; Short Signal; Long Exit Signal; Short Exit Signal.
- Does MACD Willy Strategy 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: 33 before, 11 after on ETHUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does MACD Willy Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
BTCUSDT · 1D · default settings
- RMA
- SMA
- EMA
- SMA
- SMA
- SMA
- Highest
- Lowest
- WMA
- EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs VIX D data, not available: not a Binance spot market Values that depend on it are empty on this chart.
- 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, $10,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
7 settings do nothing
“VIX Threshold for entry”, “MACD Line ”, “Signal Line ”, “Above Grow”, “Fall”, “Below Grow”, “Fall” 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
1 setting has no label
In the settings dialog w_length (line 63) shows 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.
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 |
|---|---|---|---|
| Trading window | |||
| Start Year | 2011 | int | timestart |
| Start Month | 1 | int · min 1 · max 12 | timestart |
| Start Day | 1 | int · min 1 · max 31 | timestart |
| Finish Year | 2050 | int | timefinish |
| Finish Month | 12 | int · min 1 · max 12 | timefinish |
| Finish Day | 31 | int · min 1 · max 31 | timefinish |
| Trading Options | |||
| Leverage (if applicable) | 1 | float · step 0.1 | trade_amount |
| Reinvest profit | false | bool | line 77 |
| Reinvest percentage | 20 | float | trade_amount |
| Source | close | source | ema1 fast_ma slow_ma |
| Volume MA Period | 50 | int | avg_vol |
| Fast Length | 12 | int | fast_ma |
| Slow Length | 26 | int | slow_ma |
| Signal Smoothing | 9 | int · min 1 · max 50 | signal |
| Oscillator MA Type | EMA | string · options ["SMA", "EMA"] | fast_ma slow_ma |
| Signal Line MA Type | EMA | string · options ["SMA", "EMA"] | signal |
| W length (no label in the script) | 34 | int · min 1 | w_upper w_lower |
| Smoothed %R Length | 5 | int | w_fast_ma |
| Slow EMA Length | 13 | int | w_slow_ma |
| Daily ATR | |||
| ATR period | 14 | int · min 1 | datr |
| % ATR to use for SL / PT | 5 | float · min 1 · max 100 · step 0.1 | percentage |
| VIX Volatility Index | |||
| VIX Threshold for entry | 20.0 | float · step 0.5 | unused |
| Moving Averages | |||
| EMA | 200 | int · min 1 | ema1 |
| Color Settings | |||
| MACD Line | #2962FF | value | unused |
| Signal Line | #FF6D00 | value | unused |
| Histogram | |||
| Above Grow | #26A69A | value | unused |
| Fall | #B2DFDB | value | unused |
| Below Grow | #FFCDD2 | value | unused |
| Fall | #FF5252 | value | unused |
What it calculates
- RMAta.tr, ATR period (14)
datr · line 29 - SMAvolume, Volume MA Period (50)
avg_vol · line 38 - EMASource (close), EMA (200)
ema1 · line 41 - SMA / EMASource (close), Fast Length (12) · chosen by Oscillator MA Type
fast_ma · line 57 - SMA / EMASource (close), Slow Length (26) · chosen by Oscillator MA Type
slow_ma · line 58 - SMA / EMAmacd, Signal Smoothing (9) · chosen by Signal Line MA Type
signal · line 60 - HighestW length (34)
w_upper · line 64 - LowestW length (34)
w_lower · line 65 - WMAw_output, Smoothed %R Length (5)
w_fast_ma · line 69 - EMAw_output, Slow EMA Length (13)
w_slow_ma · line 70
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 | L_entry1 | On | 82 |
| Open Short short | S_entry1 | On | 85 |
| Close Long | L_exit1 | On | 92 |
| Close Short | S_exit1 | On | 96 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | Long Signal | 83 |
| (no title) | alert | Short Signal | 86 |
| (no title) | alert | Long Exit Signal | 93 |
| (no title) | alert | Short Exit Signal | 97 |
Does it repaint?
No
No repainting patterns in the source.
- ClearHigher-timeframe data2 request.security call(s), none with lookahead on.
- 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 VIX D, and that data is not available here (not a Binance spot market). Its results would rest on empty values.
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 |
|---|---|---|---|---|---|
| MACD Willy Strategy this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Bagheri IG Ether by Bagheri_IG | ema highest lowest rma sma | v4 strategy | +0.0% | 3 | 0.0% |
| Bagheri IG Ether v2 by Bagheri_IG | ema highest lowest rma sma | v4 strategy | −0.0% | 2 | 0.0% |
| Swing Multi Moving Averages Crypto and Stocks Strategy by exlux99 | ema wma highest lowest sma | v5 strategy | +60.2% | 22 | 13.1% |
| VCP pivot buy by perrycc007 | sma ema rma wma lowest highest | v4 strategy | does not run in Zeal Terminal | ||
| SPX Scalping Strategy by connor2279 | sma ema lowest wma rma | v5 strategy | +1.5% | 109 | 5.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.
- 14 settings use the untyped input() (line 6, 9, 23, 37, 44, 45, 50, 51, 52, 53, 54, 55, 67, 68). 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 33 trades and the same P&L on ETHUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.int()
- Line 9: input() → input.int()
- Line 23: input() → input.source()
- Line 37: input() → input.int()
- Line 44: input() → input.int()
- Line 45: input() → input.int()
8 more edits
- Line 50: input() → input.color()
- Line 51: input() → input.color()
- Line 52: input() → input.color()
- Line 53: input() → input.color()
- Line 54: input() → input.color()
- Line 55: input() → input.color()
- Line 67: input() → input.int()
- Line 68: input() → input.int()
⋯// ******************** Trade Period **************************************-startY = input(title='Start Year', defval=2011, group = "Trading window")+startY = input.int(title='Start Year', defval=2011, group = "Trading window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Trading window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Trading window")-finishY = input(title='Finish Year', defval=2050, group = "Trading window")+finishY = input.int(title='Finish Year', defval=2050, group = "Trading window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Trading window")⋯// -------------------------------------------- Data Source ---------------------------------------------src = input(title="Source", defval=close)+src = input.source(title="Source", defval=close)// ***************************************************************************************************** Daily ATR *****************************************************⋯// ************************************************ Volume ******************************************************-vol_len = input(50, 'Volume MA Period')+vol_len = input.int(50, 'Volume MA Period')avg_vol = ta.sma(volume, vol_len)⋯// Getting inputs-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)signal_length = input.int(title="Signal Smoothing", minval = 1, maxval = 50, defval = 9)⋯// Plot colors-col_macd = input(#2962FF, "MACD Line ", group="Color Settings", inline="MACD")+col_macd = input.color(#2962FF, "MACD Line ", group="Color Settings", inline="MACD")-col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal")+col_signal = input.color(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal")-col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")+col_grow_above = input.color(#26A69A, "Above Grow", group="Histogram", inline="Above")-col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")+col_fall_above = input.color(#B2DFDB, "Fall", group="Histogram", inline="Above")-col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")+col_grow_below = input.color(#FFCDD2, "Below Grow", group="Histogram", inline="Below")-col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")+col_fall_below = input.color(#FF5252, "Fall", group="Histogram", inline="Below")// Calculating⋯w_output = 100 * (close - w_upper) / (w_upper - w_lower)-fast_period = input(defval=5, title='Smoothed %R Length')+fast_period = input.int(defval=5, title='Smoothed %R Length')-slow_period = input(defval=13, title='Slow EMA Length')+slow_period = input.int(defval=13, title='Slow EMA Length')w_fast_ma = ta.wma(w_output,fast_period)⋯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: 33 before, 11 after on ETHUSDT 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.
⋯// © platsn-//@version=5+//@version=6strategy("MACD Willy Strategy", overlay=true, pyramiding=1, initial_capital=10000) ⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 23 ms | With a workaround 1,000 bars in 81 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/// © platsn//@version=5strategy("MACD Willy Strategy", overlay=true, pyramiding=1, initial_capital=10000) // ******************** Trade Period **************************************startY = input(title='Start Year', defval=2011, group = "Trading window")startM = input.int(title='Start Month', defval=1, minval=1, maxval=12, group = "Trading window")startD = input.int(title='Start Day', defval=1, minval=1, maxval=31, group = "Trading window")finishY = input(title='Finish Year', defval=2050, group = "Trading window")finishM = input.int(title='Finish Month', defval=12, minval=1, maxval=12, group = "Trading window")finishD = input.int(title='Finish Day', defval=31, minval=1, maxval=31, group = "Trading window")timestart = timestamp(startY, startM, startD, 00, 00)timefinish = timestamp(finishY, finishM, finishD, 23, 59)// t1 = time(timeframe.period, "0945-1545:23456") // window = time >= timestart and time <= timefinish and t1 ? true : false // t2 = time(timeframe.period, "0930-1555:23456")// window2 = time >= timestart and time <= timefinish and t2 ? true : false leverage = input.float(1, title="Leverage (if applicable)", step=0.1, group = "Trading Options")reinvest = input.bool(defval=false,title="Reinvest profit", group = "Trading Options")reinvest_percent = input.float(defval=20, title = "Reinvest percentage", group="Trading Options")// entry_lookback = input.int(defval=10, title="Lookback period for entry condition", group = "Trading Options")// -------------------------------------------- Data Source --------------------------------------------src = input(title="Source", defval=close)// ***************************************************************************************************** Daily ATR *****************************************************atrlen = input.int(14, minval=1, title="ATR period", group = "Daily ATR")iPercent = input.float(5, minval=1, maxval=100, step=0.1, title="% ATR to use for SL / PT", group = "Daily ATR") percentage = iPercent * 0.01datr = request.security(syminfo.tickerid, "1D", ta.rma(ta.tr, atrlen))datrp = datr * percentage// plot(datr,"Daily ATR")// plot(datrp, "Daily % ATR")//*********************************************************** VIX volatility index ****************************************VIX = request.security("VIX", timeframe.period, close)vix_thres = input.float(20.0, "VIX Threshold for entry", step=0.5, group="VIX Volatility Index")// ************************************************ Volume ******************************************************vol_len = input(50, 'Volume MA Period')avg_vol = ta.sma(volume, vol_len)//-------------------------------------------------------- Moving Average ------------------------------------emalen1 = input.int(200, minval=1, title='EMA', group= "Moving Averages")ema1 = ta.ema(src, emalen1)// ------------------------------------------ MACD ------------------------------------------// Getting inputsfast_length = input(title="Fast Length", defval=12)slow_length = input(title="Slow Length", defval=26)signal_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"])// Plot colorscol_macd = input(#2962FF, "MACD Line ", group="Color Settings", inline="MACD")col_signal = input(#FF6D00, "Signal Line ", group="Color Settings", inline="Signal")col_grow_above = input(#26A69A, "Above Grow", group="Histogram", inline="Above")col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")// 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// ---------------------------------------- William %R --------------------------------------w_length = input.int(defval=34, minval=1)w_upper = ta.highest(w_length)w_lower = ta.lowest(w_length)w_output = 100 * (close - w_upper) / (w_upper - w_lower)fast_period = input(defval=5, title='Smoothed %R Length')slow_period = input(defval=13, title='Slow EMA Length')w_fast_ma = ta.wma(w_output,fast_period)w_slow_ma = ta.ema(w_output,slow_period)// ------------------------------------------------ Entry Conditions ----------------------------------------L_entry1 = close > ema1 and hist > 0 and w_fast_ma > w_slow_ma S_entry1 = close < ema1 and hist < 0 and w_fast_ma < w_slow_ma // -------------------------------------------------- Entry -----------------------------------------------profit = strategy.netprofittrade_amount = math.floor(strategy.initial_capital*leverage / close) if strategy.netprofit > 0 and reinvest trade_amount := math.floor((strategy.initial_capital+(profit*reinvest_percent*0.01))*leverage / close) else trade_amount := math.floor(strategy.initial_capital*leverage/ close) if L_entry1 //and window strategy.entry("Long", strategy.long, trade_amount) alert(message= "Long Signal", freq= alert.freq_once_per_bar_close)if S_entry1 //and window strategy.entry("Short", strategy.short, trade_amount) alert(message= "Short Signal", freq= alert.freq_once_per_bar_close)// --------------------------------------------------- Exit Conditions -------------------------------------L_exit1 = hist < 0 and w_fast_ma < w_slow_ma and w_fast_ma < -20S_exit1 = hist > 0 and w_fast_ma > w_slow_ma and w_fast_ma > -80// ----------------------------------------------------- Exit ---------------------------------------------if L_exit1 //and window2 strategy.close("Long") alert(message= "Long Exit Signal", freq= alert.freq_once_per_bar_close) if S_exit1 //and window2 strategy.close("Short") alert(message= "Short Exit Signal", freq= alert.freq_once_per_bar_close)// if time(timeframe.period, "1530-1600:23456")// strategy.close_all()