The resource loading... loading...

Moving Average Channel Breakout Strategy

Author: ChaoZhang, Date: 2023-12-12 17:38:19
Tags:

img

Overview

This is a moving average channel breakout strategy based on moving averages and range channels. It uses moving average lines and upper/lower channel lines to determine breakouts for trading signals.

Strategy Logic

The core logic of this strategy is:

  1. Set a moving average line of certain period as the middle line.

  2. Set upper and lower channel lines by multiplying the middle line by certain percentages. The upper line is middle line * (100% + preset percentage). The lower line is middle line * (100% - preset percentage).

  3. When price breaks out above the upper line, go short. When price breaks out below the lower line, go long.

  4. Set order prices at the corresponding upper/lower lines.

  5. Close positions when price comes back to the middle line.

So it trades based on the breakouts of the moving average channel.

Advantage Analysis

The advantages of this strategy are:

  1. Simple and clear concept, easy to understand and implement.

  2. Adjustable parameters fitting different market conditions.

  3. Middle line and channel range can filter market noise and catch trends.

  4. Limit orders control risks.

  5. Cut losses when price comes back to middle line.

Risk Analysis

There are also some risks:

  1. Improper parameter settings may cause over/insufficient trading.

  2. High probability of false breakouts and stop loss.

  3. Failure of the middle and channel lines under huge market swings.

  4. Premature exit when forced to close on middle line.

Solutions:

  1. Optimize parameters like MA period and channel percentage.

  2. Add other indicators like volume to avoid false breakouts.

  3. Increase manual intervention.

  4. Use longer MA period and wider channel range.

Optimization

The strategy can be improved from the following aspects:

  1. Add stop loss methods like trailing stop to limit losses.

  2. Add filtering indicators like MACD to reduce false signals.

  3. Enable automatic parameter optimization.

  4. Add more open position criteria beyond breakout.

  5. Optimize MA and channel parameters.

Conclusion

In conclusion, this is a practical MA channel breakout strategy. It has a simple logic for easy use, while the channel range can filter noise. It performs well in trending markets. But risks exist and parameters together with additional filters need optimization for actual trading. The strategy has certain practical and development value.


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

//Noro
//2018

//@version=3
strategy(title = "Robot WhiteBox ShiftMA", shorttitle = "Robot WhiteBox ShiftMA", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)

//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
per = input(3, title = "Length")
src = input(ohlc4, title = "Source")
shortlevel = input(10.0, title = "Short line (red)")
longlevel = input(-5.0, title = "Long line (lime)")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")

//SMAs
sma = sma(src, per) 
shortline = sma * ((100 + shortlevel) / 100)
longline = sma * ((100 + longlevel) / 100)
plot(shortline, linewidth = 2, color = red, title = "Short line")
plot(sma, linewidth = 2, color = blue, title = "SMA line")
plot(longline, linewidth = 2, color = lime, title = "Long line")

//Trading
size = strategy.position_size
lot = 0.0
lot := size == 0 ? strategy.equity / close * capital / 100 : lot[1]

if (not na(close[per])) and size == 0 and needlong
    strategy.entry("L", strategy.long, lot, limit = longline)
    
if (not na(close[per])) and size == 0 and needshort
    strategy.entry("S", strategy.short, lot, limit = shortline)
    
if (not na(close[per])) and size > 0 
    strategy.entry("Close", strategy.short, 0, limit = sma)
    
if (not na(close[per])) and size < 0 
    strategy.entry("Close", strategy.long, 0, limit = sma)

if time > timestamp(toyear, tomonth, today, 23, 59)
    strategy.close_all()

More