Strategy vault / Trend following
Gaussian Channel Trend Following with Stochastic RSI Trading Strategy
This strategy combines a Gaussian Weighted Moving Average Channel with the Stochastic Relative Strength Index (Stochastic RSI) to create a trend-following trading system. The strategy uses Gaussian weighting methods…

Overview
This strategy combines a Gaussian Weighted Moving Average Channel with the Stochastic Relative Strength Index (Stochastic RSI) to create a trend-following trading system. The strategy uses Gaussian weighting methods to construct a price channel and combines it with Stochastic RSI crossover signals to determine entry and exit points, effectively capturing trends and confirming momentum. The strategy has a solid mathematical foundation and effectively filters market noise while capturing major trends.
Strategy Principles
The core logic consists of two main components:
Gaussian Channel System: Uses Gaussian Weighted Moving Average (GWMA) and Gaussian Weighted Standard Deviation (GWSD) to construct a price channel. GWMA assigns higher weights to recent data, making the moving average more responsive to price changes. The channel bands are determined by multiplying the GWSD by a factor.
Stochastic RSI System: Applies stochastic calculations to the traditional RSI indicator to compute K and D values. This processing method better identifies overbought and oversold areas, providing more accurate momentum signals.
Trading signals are generated based on the following conditions:
- Long Entry: Price closes above the upper Gaussian channel band AND Stochastic RSI K-line crosses above D-line
- Exit Signal: Price closes below the upper Gaussian channel band
Strategy Advantages
- Solid Mathematical Foundation: Uses Gaussian weighting methods to construct price channels, providing better theoretical basis than simple moving averages.
- High Signal Reliability: Combines price breakout and momentum confirmation as dual verification mechanism, effectively reducing false signals.
- Strong Adaptability: Gaussian weighting method automatically adjusts channel width based on market volatility.
- Comprehensive Risk Control: Implements effective control over trading costs and risks through money management and commission settings.
Strategy Risks
- Trend Dependency: May generate frequent false signals in ranging markets, leading to overtrading.
- Lag Effect: Multiple moving average smoothing may result in delayed signals at trend turning points.
- Parameter Sensitivity: Strategy performance is highly dependent on parameter settings, requiring careful optimization.
Optimization Directions
- Market Environment Recognition: Add market state identification mechanism to use different parameter settings in different market conditions.
- Stop Loss Optimization: Introduce dynamic stop loss mechanism, such as ATR-based or volatility-based adaptive stops.
- Signal Filtering: Add volume confirmation or other technical indicators as auxiliary filtering conditions.
- Money Management: Implement more flexible position management strategies, adjusting position sizes dynamically based on signal strength.
Summary
This strategy combines Gaussian channels and Stochastic RSI indicators to build a trend-following system with solid mathematical foundations. The strategy performs excellently in trending markets but requires attention to parameter optimization and market environment adaptability. Through implementing the suggested optimization measures, the strategy's stability and profitability can be further enhanced.
Source Pine Script
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("Gaussian Channel + Stoch RSI Strategy", overlay=true, margin_long=100, margin_short=100, initial_capital=100000, commission_type=strategy.commission.percent, commission_value=0.1, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=1)
// User Inputs
length = input.int(20, "Gaussian Length", minval=5)
multiplier = input.float(2.0, "Channel Multiplier", step=0.1)
rsiLength = input.int(14, "RSI Length", minval=1)
stochLength= input.int(14, "Stoch RSI Length", minval=1)
kLength = input.int(3, "Stoch K Smoothing", minval=1)
dLength = input.int(3, "Stoch D Smoothing", minval=1)
// Gaussian Weighted Moving Average Function
f_gaussian(source, length) =>
half = (length - 1) / 2.0
sum = 0.0
norm = 0.0
// Gaussian standard deviation chosen as length/6 for a smooth curve
denom = (length / 6.0) * (length / 6.0)
for i = 0 to length - 1
x = i - half
w = math.exp(-(x * x) / (2 * denom))
sum += source[i] * w
norm += w
sum / norm
// Gaussian Weighted Standard Deviation Function
f_gaussian_std(source, length) =>
half = (length - 1) / 2.0
gavg = f_gaussian(source, length)
sum = 0.0
norm = 0.0
denom = (length / 6.0) * (length / 6.0)
for i = 0 to length - 1
x = i - half
w = math.exp(-(x * x)/(2*denom))
diff = source[i] - gavg
sum += diff * diff * w
norm += w
math.sqrt(sum/norm)
// Compute Gaussian Channel
gaussMid = f_gaussian(close, length)
gaussStd = f_gaussian_std(close, length)
gaussUpper = gaussMid + gaussStd * multiplier
gaussLower = gaussMid - gaussStd * multiplier
// Stochastic RSI Calculation
rsi = ta.rsi(close, rsiLength)
rsiLowest = ta.lowest(rsi, stochLength)
rsiHighest = ta.highest(rsi, stochLength)
stoch = 100 * (rsi - rsiLowest) / math.max(rsiHighest - rsiLowest, 1e-10)
k = ta.sma(stoch, kLength)
d = ta.sma(k, dLength)
// Conditions
// Long entry: Price closes above upper Gaussian line AND Stoch RSI K > D (stochastic is "up")
longCondition = close > gaussUpper and k > d
// Exit condition: Price closes below upper Gaussian line
exitCondition = close < gaussUpper
// Only trade in the specified date range
inDateRange = time >= timestamp("2018-01-01T00:00:00") and time < timestamp("2069-01-01T00:00:00")
// Submit Orders
if inDateRange
if longCondition and strategy.position_size <= 0
strategy.entry("Long", strategy.long)
if exitCondition and strategy.position_size > 0
strategy.close("Long")
// Plot Gaussian Channel
plot(gaussMid, "Gaussian Mid", color=color.new(color.yellow, 0))
plot(gaussUpper, "Gaussian Upper", color=color.new(color.green, 0))
plot(gaussLower, "Gaussian Lower", color=color.new(color.red, 0))
Published by ianzeng123 on the FMZ strategy square · last modified 2025-02-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.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Gaussian-Channel-Trend-Following-with-Stochastic-RSI-Trading-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- 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
- EMA200 and Stochastic RSI StrategyPine Script · Trend following · 1h
- Multi Dimensional Short Term Trend Predictor Technical Analysis and Volatility Adaptive Trading StrategyPine Script · Trend following · 1h
- Multi Indicator Trend Following with Oscillator Alert StrategyPine Script · Trend following · 2h
- Mini Pullback Supertrend StrategyPine Script · Trend following · 1h
- Three Exponential Moving Averages and Stochastic Relative Strength Index Trading StrategyPine Script · Trend following · 1h
- Triple SuperTrend Quantitative Trading StrategyPine Script · Trend following · 1d