0bps

Strategy vault / Breakout

Moving Average Oscillation HODL Strategy

This strategy observes price oscillation around long-period moving averages (e.g. 200-day) to determine hold signals, trading breakouts for position entry and using break below as stop loss. It aims to minimize…

Author
ChaoZhang
Complexity
Intermediate · 48 lines
Parameters
8
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

This strategy observes price oscillation around long-period moving averages (e.g. 200-day) to determine hold signals, trading breakouts for position entry and using break below as stop loss. It aims to minimize trading frequency for long-term holding.

Strategy Logic:

  1. Calculate a long-period moving average, typically 200-day.

  2. Enter long when price breaks above the moving average.

  3. Exit long when price breaks back below the moving average.

  4. Hold long position until break below stop loss.

Advantages:

  1. Long-period MA effectively identifies mid-to-long term trends.

  2. Breakout trading captures long-term reversals in a timely manner.

  3. Lower trading frequency reduces costs and risks.

Risks:

  1. Longer MAs lag significantly, resulting in poor entry timing.

  2. No limit on post-breakout drawdown risks.

  3. Frequent minor breakouts bring sustained small losses.

In summary, this HODL strategy uses long MA oscillation to determine hold timing, minimizing trade frequency. But parameter optimization and stop loss placement could improve performance and risk control for steady long-term gains.

Parameters

NameDefaultWhat it controls
v_input_12017Backtest Start Year
v_input_2trueBacktest Start Month
v_input_3trueBacktest Start Day
v_input_42029Backtest Stop Year
v_input_5trueBacktest Stop Month
v_input_6trueBacktest Stop Day
v_input_7200MA Period
v_input_80smoothing: EMA | SMA

Source Pine Script

/*backtest
start: 2022-09-05 00:00:00
end: 2023-04-15 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("HODLBot", default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_every_tick=true, overlay=true)
    
//// Time limits 
testStartYear = input(2017, "Backtest Start Year")
testStartMonth = input(01, "Backtest Start Month")
testStartDay = input(01, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

testStopYear = input(2029, "Backtest Stop Year")
testStopMonth = input(1, "Backtest Stop Month")
testStopDay = input(1, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

testPeriod() => true

maPeriod = input(200, "MA Period")
smoothing = input(defval="EMA", options=["EMA", "SMA"])

ma(smoothing, src, length) => 
    if smoothing == "EMA"
        ema(src, length)
    else
        if smoothing == "SMA"
            sma(src, length)
        
//// Main ////

movingAverage = ma(smoothing, close, maPeriod)

plot(movingAverage, color=orange, style = line, linewidth = 4)
 
// very simple, price over MA? Buy and HODL 
if (testPeriod() and close > movingAverage)
    strategy.entry("HODL", strategy.long)

// Price under, close long
if (testPeriod() and close < movingAverage)
    strategy.close("HODL")

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-12. 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/Moving-Average-Oscillation-HODL-Strategy.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