0bps

Strategy vault / Breakout

Moving Average Channel Breakout Strategy 435159

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.

Author
ChaoZhang
Complexity
Intermediate · 56 lines
Parameters
13
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

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.

Parameters

NameDefaultWhat it controls
v_input_1trueLong
v_input_2trueShort
v_input_3100Lot, %
v_input_43Length
v_input_5_ohlc40Source: ohlc4 | high | low | open | hl2 | hlc3 | hlcc4 | close
v_input_610Short line (red)
v_input_7-5Long line (lime)
v_input_81900From Year
v_input_92100To Year
v_input_10trueFrom Month
v_input_1112To Month
v_input_12trueFrom day
v_input_1331To day

Source Pine Script

/*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()

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-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/Moving-Average-Channel-Breakout-Strategy-435159.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