0bps

Strategy vault / Trend following

HMA Daily Crossover Trading Strategy

This strategy enters trades based on HMA line and daily candlestick crosses and manages positions using stop loss and take profit logic. It combines different timeframe indicators for trend trading.

Author
ChaoZhang
Complexity
Starter · 31 lines
Parameters
4
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

Overview

This strategy enters trades based on HMA line and daily candlestick crosses and manages positions using stop loss and take profit logic. It combines different timeframe indicators for trend trading.

Strategy Logic

The main signals and rules:

  • HMA line: Calculates Hull Moving Average to determine medium-long term trend.

  • Daily close price: Judges short-term price action.

  • Entry signal: HMA crossing above previous daily close, with price higher than previous day's price for long. Reverse for short.

  • Stop loss/take profit: Fixed levels to close positions when hit.

Advantages

  • Adjustable HMA parameters for adaptability.

  • Considers multi-timeframe indicators for higher quality signals.

  • Stop loss/take profit facilitates risk management.

  • Clear entry rules and position management.

  • Backtest parameters can be optimized for different markets.

Risks

  • HMA lag may miss best entry timing.

  • Fixed stop loss/take profit may be too aggressive or conservative.

  • Lacks trend strength filter, risks countertrend trades.

  • Simple rules prone to false signals.

Improvements:

  1. Optimize HMA parameters for lag.

  2. Use trailing stop loss instead of fixed.

  3. Add volume or momentum indicators to judge trend strength.

  4. Incorporate other indicators like MACD for signal confirmation.

Optimization

Potential ways to optimize the strategy:

  1. Optimize HMA parameters for ideal combo.

  2. Add trend strength filter to avoid countertrends.

  3. Use dynamic stops instead of fixed levels.

  4. Incorporate machine learning for auto parameter optimization.

  5. Add simulated trading to test real-world performance.

Summary

The strategy logic is clear but has room for improvement. Adding trend filters, dynamic stops can improve stability. Overall provides a reasonable framework for catching medium-long term trends.

Parameters

NameDefaultWhat it controls
v_input_1-0.05StopLoss $
v_input_20.05TargetPoint $
v_input_3_open0Source: open | high | low | close | hl2 | hlc3 | hlcc4 | ohlc4
v_input_414Period

Source Pine Script

/*backtest
start: 2023-08-22 00:00:00
end: 2023-09-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// created by SeaSide420       Enters on crossovers, exits Basket when profit $ = TP
// strategy(title="HMA & D1 crossover", overlay=true, currency="BTC", initial_capital=1, default_qty_type=strategy.percent_of_equity, default_qty_value=1, commission_type=strategy.commission.percent,commission_value=0.25,slippage=1)
SL=input(defval=-0.05,title="StopLoss $",type=input.float,step=0.01, maxval=-0.01)
TP=input(defval=0.05,title="TargetPoint $",type=input.float,step=0.01, minval=0.01)
price=input(title="Source",type=input.source,defval=open)
Period=input(14, minval=1)
hma = wma(2*wma(price, Period/2)-wma(price, Period), round(sqrt(Period)))
s1=security(syminfo.tickerid, timeframe.period, price, barmerge.gaps_off, barmerge.lookahead_off)
s2=security(syminfo.tickerid, "D", price, barmerge.gaps_off, barmerge.lookahead_off)
cp=s2<price?color.lime:color.red
cp1=plot((s2),color=color.black,title="DailyCandle1",linewidth=2,transp=0)
cp2=plot((s2[1]),color=color.black,title="DailyCandle2",linewidth=2,transp=0)
cp3=plot(hma,title="HMA",color=color.black)
fill(cp1,cp2,color=cp,transp=1)
fill(cp1,cp3,color=cp,transp=75)
closeall=strategy.openprofit<SL or strategy.openprofit>TP
if closeall
    strategy.close_all(comment = "Close All")
if (hma>hma[1] and s1>s2 and s2[1]>s2[2] and s1>s2[1])
    strategy.order("Buy", strategy.long)
if (hma<hma[1] and s1<s2 and s2[1]<s2[2] and s1<s2[1])
    strategy.order("Sell", strategy.short)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-22. 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/HMA-Daily-Crossover-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