strategy · own pane · open source
Momentum Time-Series strategy
Momentum Time-Series is a free open-source strategy by @deepwick. Time-series momentum: long when the return over the lookback is positive, out when it turns… Deepwick Script runs a subset of Pine Script.
Running…
Loading chart…
What Momentum Time-Series does
Time-series momentum: long when the return over the lookback is positive, out when it turns negative. Hurst, Ooi and Pedersen document it across 67 markets since 1880; it is also the only anomaly in the corpus that worked in 8 of the 10 worst crises of the last century.
- The lookback is the whole strategy. Measured on XAUUSD H1 with 27.3 M real Dukascopy ticks (Jan-Jul 2016, spread 2.94 bps): a 250-bar lookback gave Sharpe 1.60 (CAGR 1.6 %, max drawdown −9.7 %, 84 trades) and 120 bars gave Sharpe 1.47 (max drawdown −8.3 %, 87 trades).
- 🚨 It is not monotonic, and the research says so. A 60-bar lookback lost money (Sharpe −0.69) and a 20-bar one was mostly noise (Sharpe 0.72, CAGR −3.6 %). 250 and 120 work; 60 and 20 do not. Do not shorten it because it feels slow.
- 🚨 One asset, not a basket. This is time-series momentum on the instrument you are looking at. The cross-sectional version — buying the coins that went up — has Sharpe 0.67 with 96.5 % of its return in 20 of 2,360 days, and its 2025-26 holdout is Sharpe −1.20. It is a regime strategy dressed as an edge.
- Run it on daily or 4h. A 120-bar lookback is five months on the hourly chart and five days on the daily one. On five-minute bars it is noise.
- The costs are Dukascopy's, which is tighter than a real broker: add 1-2 bps for yours before reading the numbers as yours.
- The default stop (0.75 %) and target (1.5 %) are the ones the measurement used. The research's own next step was to widen the stop and narrow the target to 1:1 — it was not re-measured, so it is not the default here.
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("Momentum Time-Series", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
lookback = input.int(120, "Momentum lookback (bars)", minval=20, maxval=500, step=10)
stopPct = input.float(0.75, "Stop Loss %", minval=0.25, maxval=5, step=0.05)
tpPct = input.float(1.5, "Take Profit %", minval=0, maxval=10, step=0.1)
colorLine = input.color("color.blue", "Color Line")
colorUp = input.color("color.green", "Color Up")
mom = (close - close[lookback]) / close[lookback]
longSignal = strategy.position_size == 0 and mom > 0
exitSignal = strategy.position_size > 0 and mom < 0
if longSignal
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
strategy.close("Long", comment="Momentum out")
p_Momentum = plot(mom, "Momentum", color=colorLine, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
alertcondition(longSignal, "Momentum long entry", "The return over the lookback turned positive")
No comments yet.
Sign in to comment.