0bps

Strategy vault / Momentum

Momentum Moving Average Persistent Long Trading Strategy

This strategy trades long during sustained momentum by observing persistent moving average uptrends, aiming to continuously ride the momentum of bull runs. It is a trend-following strategy focused on capturing upside…

Author
ChaoZhang
Complexity
Starter · 36 lines
Parameters
1
Backtest bar
3d · position
Tested on
BTC/USDT · futures

This strategy trades long during sustained momentum by observing persistent moving average uptrends, aiming to continuously ride the momentum of bull runs. It is a trend-following strategy focused on capturing upside momentum.

Strategy Logic:

  1. Calculate weighted moving average to reflect price momentum.

  2. Enter long when weighted moving average rises persistently for 5 days.

  3. Exit long when weighted moving average falls for 4 consecutive days.

  4. Persistent uptrend days filter out short-term reversals.

  5. Set maximum stop loss to limit maximum daily loss.

Advantages:

  1. Tracking upside momentum allows holding hot trends.

  2. Persistence filter skips short consolidations.

  3. Maximum stop loss defends tail risks.

Risks:

  1. No limit on pullback losses after persistent uptrends.

  2. Deep corrections can bring large losses.

  3. Overly wide stops bring risk of outsized losses.

In summary, this strategy persists in trading the momentum after identifying sustained uptrends, benefiting from hot trends. But deep pullback risks remain, requiring calibrated stops and prudent risk management.

Parameters

NameDefaultWhat it controls
v_input_125risk

Source Pine Script

/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-11 00:00:00
period: 3d
basePeriod: 1d
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/
// © SoftKill21

//@version=4
// strategy("My Script", initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent , commission_value=0.1 )


var candela = 0.0


candela := (high+low+open+close)/4

long = candela > candela[1] and candela[1] > candela[2] and candela[2] > candela[3] and candela[3] > candela[4] and candela[4] > candela[5]
short = candela< candela[1] and candela[1] < candela[2] and candela[2] < candela[3] and candela[3] < candela[4] //and candela[4] < candela[5] 

plot(candela, color=long? color.green : short? color.red : color.white ,linewidth=4)



strategy.entry("long",1,when=long)
//strategy.entry('short',0,when=short)
    
strategy.close("long", when = short)

risk= input(25)
// strategy.risk.max_intraday_loss(risk, strategy.percent_of_equity)
//strategy.close("short", when = not long or short)

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/Momentum-Moving-Average-Persistent-Long-Trading-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