0bps

Strategy vault / Breakout

Quantitative Long Short Switching Strategy Based on G Channel and EMA

This strategy is a quantitative trading system that combines G-Channel and Exponential Moving Average (EMA). The core concept is to capture market trend directions through G-Channel while using EMA for signal…

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

IMG

Overview

This strategy is a quantitative trading system that combines G-Channel and Exponential Moving Average (EMA). The core concept is to capture market trend directions through G-Channel while using EMA for signal confirmation and risk control, aiming to generate profits from market fluctuations. The strategy operates in a fully automated mode without manual intervention.

Strategy Principle

The strategy operates based on two core indicators: G-Channel and EMA. G-Channel identifies price trends by dynamically calculating upper and lower bands, generating trading signals when prices break through the channel. Specifically, the strategy uses a 100-period G-Channel calculation, continuously updating the channel boundaries through mathematical formulas. Additionally, a 50-period EMA is introduced as secondary confirmation, executing trades only when the price's relative position to EMA meets expectations. Buy conditions are triggered when G-Channel signals long and closing price is below EMA, while sell conditions occur when G-Channel signals short and closing price is above EMA.

Strategy Advantages

  1. Combines trend-following and mean-reversion characteristics, maintaining stable performance in various market conditions
  2. Uses EMA as auxiliary confirmation to effectively reduce false breakout risks
  3. Employs fully automated trading to avoid emotional interference
  4. Features simple and clear calculation logic, easy to understand and maintain
  5. Offers strong parameter adjustability to adapt to different market characteristics

Strategy Risks

  1. May result in frequent trading in oscillating markets, increasing transaction costs
  2. Improper G-Channel parameter settings may lead to signal lag
  3. Inappropriate EMA period selection might miss important trend turning points
  4. Possibility of significant drawdowns during extreme market volatility Risk mitigation measures:
  • Implement stop-loss mechanisms
  • Optimize parameter configuration
  • Add market environment filtering
  • Set reasonable position management strategies

Strategy Optimization Directions

  1. Introduce volatility indicators to adjust strategy parameters or pause trading in high-volatility environments
  2. Incorporate volume analysis to improve signal reliability
  3. Add trend strength filters to avoid frequent trading in weak trend markets
  4. Optimize EMA parameter adaptive mechanisms to enhance system adaptability
  5. Develop multi-timeframe signal confirmation mechanisms to improve trading stability

Summary

This strategy constructs a robust quantitative trading system by combining G-Channel and EMA technical indicators. The strategy logic is clear, implementation is simple, and it offers good scalability. Through proper parameter optimization and risk control measures, the strategy shows potential for generating stable returns in live trading. It is recommended to optimize the strategy based on market characteristics and strictly implement risk management protocols when applying it to live trading.

Source Pine Script

/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © stanleygao01


//@version=5
strategy('G-Channel with EMA Strategy', overlay=true)

// G-Channel parameters
length = input(100, title='G-Channel Length')
src = input(close, title='Source')

a = 0.0
b = 0.0
a := math.max(src, nz(a[1])) - nz(a[1] - b[1]) / length
b := math.min(src, nz(b[1])) + nz(a[1] - b[1]) / length
avg = math.avg(a, b)

crossup = b[1] < close[1] and b > close
crossdn = a[1] < close[1] and a > close
bullish = ta.barssince(crossdn) <= ta.barssince(crossup)

// EMA parameters
emaLength = input(50, title='EMA Length')
ema = ta.ema(close, emaLength)

// Buy and Sell Conditions
buyCondition = bullish and close < ema
sellCondition = not bullish and close > ema

// Plot G-Channel
c = bullish ? color.lime : color.red
p1 = plot(avg, title='Average', color=c, linewidth=1, transp=90)
p2 = plot(close, title='Close Price', color=c, linewidth=1, transp=100)
fill(p1, p2, color=c, transp=90)

// Plot EMA
plot(ema, title='EMA', color=color.new(color.blue, 0), linewidth=2)

// Strategy Entries and Exits
if buyCondition
    strategy.entry('Buy', strategy.long)
if sellCondition
    strategy.close('Buy')

// Plot Buy/Sell Labels
plotshape(buyCondition, title='Buy Signal', location=location.belowbar, color=color.new(color.lime, 0), style=shape.labelup, text='Buy')
plotshape(sellCondition, title='Sell Signal', location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, text='Sell')

Published by ChaoZhang on the FMZ strategy square · last modified 2024-12-20. 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/Quantitative-Long-Short-Switching-Strategy-Based-on-G-Channel-and-EMA.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