0bps

Strategy vault / Trend following

Trend Following Strategy Based on Dynamic Support and Resistance

This article explains in detail a trend following strategy that utilizes dynamic support and resistance levels. It forms upper and lower bands using moving averages and ATR to track trends. I. Strategy Logic The main…

Author
ChaoZhang
Complexity
Starter · 30 lines
Parameters
4
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

This article explains in detail a trend following strategy that utilizes dynamic support and resistance levels. It forms upper and lower bands using moving averages and ATR to track trends.

I. Strategy Logic

The main indicators and logic include:

  1. Calculating highest high moving average over a period as the upper band.

  2. Using ATR to compute buffer distance for stop loss.

  3. Upper band minus buffer sets the lower band.

  4. Take long when price breaks above upper band; exit when price breaks below lower band.

The upper and lower bands construct dynamic support and resistance zones. By trend riding breakouts and quick stops, trading risks can be controlled.

II. Advantages of the Strategy

The main advantages are:

  1. Dynamic bands can capture trend opportunities.

  2. ATR stop loss sets stops based on market volatility.

  3. Larger profit target than stop loss benefits profits.

  4. Simple rules make it easy to implement.

III. Potential Risks

However, some potential issues exist:

  1. Moving averages and ATR have lagging issues.

  2. Larger drawdowns need to be endured.

  3. No limit on number of entries.

  4. Parameters need optimization for different products.

IV. Summary

In summary, this article has explained a trend following strategy using moving averages and ATR to form dynamic bands. It can set stop loss and take profit based on volatility to ride trends. But risks like indicator lag and drawdown control need attention. Overall it provides a simple trend tracking method.

Parameters

NameDefaultWhat it controls
v_input_1200Highest Length
v_input_210Highest Average
v_input_314ATR Length
v_input_42ATR Multiplier

Source Pine Script

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

//@version=4
strategy("I Like Winners And Hate Loosers!", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

highest_length = input(200, type=input.integer, minval=1, title="Highest Length")
highest_average = input(10, type=input.integer, minval=1, title="Highest Average")

atr_length = input(14, type=input.integer, minval=1, title="ATR Length")
atr_multiplier = input(2, type=input.integer, minval=1, title="ATR Multiplier")

a = atr(atr_length) * atr_multiplier
h = sma(highest(high, highest_length), highest_average)
l = h - a

buy_signal = crossover(close, h)
sell_signal = crossunder(close, l)

strategy.entry("Buy", strategy.long, when=buy_signal)
strategy.close("Buy", when=sell_signal)

plot(h, title="H", color=color.green, transp=50, linewidth=2)
plot(l, title="L", color=color.red, transp=50, linewidth=2)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-15. 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/Trend-Following-Strategy-Based-on-Dynamic-Support-and-Resistance.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