0bps

Strategy vault / Mean reversion

jma dwma by multigrain

This crossover system was originally conceptualized by Jurik Research and made public to the world on their website. The indicator consists of the faster Jurik Moving Average ( JMA ) and the slower Double Weighted…

Author
ChaoZhang
Complexity
Intermediate · 60 lines
Parameters
8
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

This crossover system was originally conceptualized by Jurik Research and made public to the world on their website.

The indicator consists of the faster Jurik Moving Average ( JMA ) and the slower Double Weighted Moving Average (DWMA). A long signal is shown when the JMA line crosses above the DWMA line (indicating a possible reversal in trend). A short signal is shown when the JMA line crosses below the DWMA line. Take profit signals are shown when the JMA line reverses directions. Alerts for signals are included in this indicator.

The default settings are not optimized for any timeframe. Both JMA and DWMA lines are defaulted to hidden.

Credit to @everget for the re-creation of the Jurik Moving Average in pinecsript.

backtest

IMG

Parameters

NameDefaultWhat it controls
v_input_bool_1trueEnable longs?
v_input_bool_2trueEnable shorts?
v_input_source_1_close0(?JMA)JMA Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_int_17JMA Length
v_input_int_250JMA Phase
v_input_float_1trueJMA Power
v_input_source_2_close0(?DWMA)DWMA Source: close | high | low | open | hl2 | hlc3 | hlcc4 | ohlc4
v_input_int_310DWMA Length

Source Pine Script

/*backtest
start: 2022-04-07 00:00:00
end: 2022-05-06 23:59:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © multigrain
// @version=5

indicator('jma + dwma by multigrain', 'jma + dwma', overlay=true)

//NAME            TYPE               DEFVAL     TITLE               MIN     MAX         GROUP       
longs           = input.bool        (true,      'Enable longs?')
shorts          = input.bool        (true,     'Enable shorts?')

jmaSrc          = input.source      (close,     'JMA Source',                           group='JMA')
jmaLen          = input.int         (7,         'JMA Length',       0,      100,        group='JMA')
jmaPhs          = input.int         (50,        'JMA Phase',        -100,   100,        group='JMA')
jmaPwr          = input.float       (1,         'JMA Power',        0.1,                group='JMA')

dwmaSrc         = input.source      (close,     'DWMA Source',                          group='DWMA')
dwmaLen         = input.int         (10,        'DWMA Length',      1,      100,        group='DWMA')

// Jurik Moving Average
f_jma(_src, _length, _phase, _power) =>
    phaseRatio  = _phase < -100 ? 0.5 : _phase > 100 ? 2.5 : _phase / 100 + 1.5
    beta        = 0.45 * (_length - 1) / (0.45 * (_length - 1) + 2)
    alpha       = math.pow(beta, _power)
    jma         = 0.0
    e0          = 0.0
    e0          := (1 - alpha) * _src + alpha * nz(e0[1])
    e1          = 0.0
    e1          := (_src - e0) * (1 - beta) + beta * nz(e1[1])
    e2          = 0.0
    e2          := (e0 + phaseRatio * e1 - nz(jma[1])) * math.pow(1 - alpha, 2) + math.pow(alpha, 2) * nz(e2[1])
    jma         := e2 + nz(jma[1])
    jma

// Double Weighted Moving Average
f_dwma(_src, _length) =>
    ta.wma(ta.wma(_src, _length), _length)


// Calculations
jma             = f_jma             (jmaSrc,    jmaLen,     jmaPhs,     jmaPwr)
dwma            = f_dwma            (dwmaSrc,   dwmaLen)
long            = ta.crossover      (jma,       dwma) 
long_tp         = ta.pivothigh      (jma,       1,          1)              and jma > dwma
short_tp        = ta.pivotlow       (jma,       1,          1)              and jma < dwma
short           = ta.crossunder     (jma,       dwma)
if longs
    strategy.entry("Buy", strategy.long, when=long)
    strategy.close("Buy", when=long_tp)
if shorts
    strategy.entry("Sell", strategy.short, when=short)
    strategy.close("Sell", when=short_tp)

Published by ChaoZhang on the FMZ strategy square · last modified 2022-05-09. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/jma-dwma-by-multigrain.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open