资源加载中... loading...

Price Channel and Moving Average Based Trend Following Strategy

Author: ChaoZhang, Date: 2024-02-06 09:46:23
Tags:

img

Overview

This strategy identifies and follows trends by constructing a Price Channel to calculate the deviation of price from the middle line and using moving averages to filter signals. Trading signals are generated when price breaks through the Channel. The strategy has both trend following and breakout characteristics.

Strategy Logic

  1. Build Price Channel
  • Calculate highest high and lowest low over the past len periods
  • Middle line is average of highest high and lowest low
  • Distance is absolute deviation of price from middle line
  • Smooth distance to get upper and lower bands
  1. Determine Trend Direction
  • When price is below lower band, define as downtrend
  • When price is above upper band, define as uptrend
  1. Generate Trading Signals
  • In uptrend, long when price is below open or breaks below upper band
  • In downtrend, short when price is above open or breaks above lower band

Advantage Analysis

  1. Captures mid- to long-term trends
  2. Combines with breakout signals to avoid ineffective trading in range-bound markets
  3. Customizable parameters suit different products

Risk Analysis

  1. More minor losses possible in oscillating trends
  2. Inappropriate parameter settings may miss trend reversals
  3. Monitor trade frequency to prevent overtrading

Optimization Directions

  1. Add other indicators to filter signals
  2. Dynamically adjust Price Channel parameters
  3. Incorporate stop loss to optimize risk management

Conclusion

The strategy is overall quite robust in tracking mid- to long-term trends effectively while generating trading signals through trend breakouts. Further improvements can be made through parameter optimization and signal filtering to adapt the strategy to more products and market environments.


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


//@version=2
strategy("Noro's Bands Strategy v1.1", shorttitle = "NoroBands str 1.1", overlay=true)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
len = input(20, defval = 20, minval = 2, maxval = 200, title = "Period")
color = input(true, "Color")
needbb = input(true, defval = false, title = "Show Bands")
needbg = input(true, defval = false, title = "Show Background")
src = close

//PriceChannel 1
lasthigh = highest(src, len)
lastlow = lowest(src, len)
center = (lasthigh + lastlow) / 2

//dist
dist = abs(src - center)
distsma = sma(dist, len)
hd = center + distsma
ld = center - distsma

//Trend
trend = close < ld and high < hd ? -1 : close > hd and low > ld ? 1 : trend[1]

//Lines
colo = needbb == false ? na : black
plot(hd, color = colo, linewidth = 1, transp = 0, title = "High band")
plot(center, color = colo, linewidth = 1, transp = 0, title = "center")
plot(ld, color = colo, linewidth = 1, transp = 0, title = "Low band")

//Background
col = needbg == false ? na : trend == 1 ? lime : red
bgcolor(col, transp = 90)

//Signals
up = trend == 1 and ((close < open or color == false) or close < hd) ? 1 : 0
dn = trend == -1 and ((close > open or color == false) or close > ld) ? 1 : 0 

longCondition = up == 1
if (longCondition)
    strategy.entry("Long", strategy.long, needlong == false ? 0 : na)

shortCondition = dn == 1
if (shortCondition)
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na)

More