
La estrategia es un sistema de negociación de seguimiento de tendencias basado en las ondas de Gauss y el indicador StochRSI. La estrategia identifica las tendencias del mercado a través del canal de Gauss y se combina con el indicador StochRSI para optimizar el tiempo de entrada. El sistema utiliza un método de fusión múltiple para construir el canal de Gauss y seguir las tendencias de los precios mediante la adaptación dinámica de la trayectoria ascendente, lo que permite un seguimiento preciso de la evolución del mercado.
El núcleo de la estrategia es un canal de precios basado en el algoritmo de Gauss. La implementación en concreto incluye los siguientes pasos clave:
La estrategia, a través de la combinación de las ondas de Gauss y el indicador StochRSI, permite un seguimiento eficaz de las tendencias del mercado. El sistema tiene una buena capacidad de reducción de ruido y de identificación de tendencias, pero también existe cierto retraso y dificultad para optimizar los parámetros. Mediante la optimización y el perfeccionamiento continuos, la estrategia espera obtener ganancias estables en el comercio real.
/*backtest
start: 2024-02-19 00:00:00
end: 2025-02-16 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="Demo GPT - Gaussian Channel Strategy v3.0", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0, default_qty_type=strategy.percent_of_equity, default_qty_value=250)
// ============================================
// Gaussian Functions (Must be at top)
// ============================================
f_filt9x(_a, _s, _i) =>
var int _m2 = 0, var int _m3 = 0, var int _m4 = 0, var int _m5 = 0, var int _m6 = 0,
var int _m7 = 0, var int _m8 = 0, var int _m9 = 0, var float _f = 0.0
_x = 1 - _a
_m2 := _i == 9 ? 36 : _i == 8 ? 28 : _i == 7 ? 21 : _i == 6 ? 15 : _i == 5 ? 10 : _i == 4 ? 6 : _i == 3 ? 3 : _i == 2 ? 1 : 0
_m3 := _i == 9 ? 84 : _i == 8 ? 56 : _i == 7 ? 35 : _i == 6 ? 20 : _i == 5 ? 10 : _i == 4 ? 4 : _i == 3 ? 1 : 0
_m4 := _i == 9 ? 126 : _i == 8 ? 70 : _i == 7 ? 35 : _i == 6 ? 15 : _i == 5 ? 5 : _i == 4 ? 1 : 0
_m5 := _i == 9 ? 126 : _i == 8 ? 56 : _i == 7 ? 21 : _i == 6 ? 6 : _i == 5 ? 1 : 0
_m6 := _i == 9 ? 84 : _i == 8 ? 28 : _i == 7 ? 7 : _i == 6 ? 1 : 0
_m7 := _i == 9 ? 36 : _i == 8 ? 8 : _i == 7 ? 1 : 0
_m8 := _i == 9 ? 9 : _i == 8 ? 1 : 0
_m9 := _i == 9 ? 1 : 0
_f := math.pow(_a, _i) * nz(_s) + _i * _x * nz(_f[1]) - (_i >= 2 ? _m2 * math.pow(_x, 2) * nz(_f[2]) : 0) + (_i >= 3 ? _m3 * math.pow(_x, 3) * nz(_f[3]) : 0) - (_i >= 4 ? _m4 * math.pow(_x, 4) * nz(_f[4]) : 0) + (_i >= 5 ? _m5 * math.pow(_x, 5) * nz(_f[5]) : 0) - (_i >= 6 ? _m6 * math.pow(_x, 6) * nz(_f[6]) : 0) + (_i >= 7 ? _m7 * math.pow(_x, 7) * nz(_f[7]) : 0) - (_i >= 8 ? _m8 * math.pow(_x, 8) * nz(_f[8]) : 0) + (_i == 9 ? _m9 * math.pow(_x, 9) * nz(_f[9]) : 0)
_f
f_pole(_a, _s, _i) =>
_f1 = f_filt9x(_a, _s, 1)
_f2 = _i >= 2 ? f_filt9x(_a, _s, 2) : 0.0
_f3 = _i >= 3 ? f_filt9x(_a, _s, 3) : 0.0
_f4 = _i >= 4 ? f_filt9x(_a, _s, 4) : 0.0
_f5 = _i >= 5 ? f_filt9x(_a, _s, 5) : 0.0
_f6 = _i >= 6 ? f_filt9x(_a, _s, 6) : 0.0
_f7 = _i >= 7 ? f_filt9x(_a, _s, 7) : 0.0
_f8 = _i >= 8 ? f_filt9x(_a, _s, 8) : 0.0
_f9 = _i == 9 ? f_filt9x(_a, _s, 9) : 0.0
_fn = _i == 1 ? _f1 : _i == 2 ? _f2 : _i == 3 ? _f3 : _i == 4 ? _f4 : _i == 5 ? _f5 : _i == 6 ? _f6 : _i == 7 ? _f7 : _i == 8 ? _f8 : _i == 9 ? _f9 : na
[_fn, _f1]
// ============================================
// Date Filter
// ============================================
startDate = input(timestamp("1 Jan 2018"), "Start Date", group="Time Settings")
endDate = input(timestamp("31 Dec 2069"), "End Date", group="Time Settings")
timeCondition = true
// ============================================
// Stochastic RSI (Hidden Calculations)
// ============================================
stochRsiK = input.int(3, "Stoch RSI K", group="Stochastic RSI", tooltip="Only for calculations, not visible")
stochRsiD = input.int(3, "Stoch RSI D", group="Stochastic RSI")
rsiLength = input.int(14, "RSI Length", group="Stochastic RSI")
stochLength = input.int(14, "Stochastic Length", group="Stochastic RSI")
rsiValue = ta.rsi(close, rsiLength)
k = ta.sma(ta.stoch(rsiValue, rsiValue, rsiValue, stochLength), stochRsiK)
d = ta.sma(k, stochRsiD)
// ============================================
// Gaussian Channel
// ============================================
gaussianSrc = input(hlc3, "Source", group="Gaussian")
poles = input.int(4, "Poles", minval=1, maxval=9, group="Gaussian")
samplingPeriod = input.int(144, "Sampling Period", minval=2, group="Gaussian")
multiplier = input.float(1.414, "Multiplier", step=0.1, group="Gaussian")
reducedLag = input.bool(false, "Reduced Lag Mode", group="Gaussian")
fastResponse = input.bool(false, "Fast Response Mode", group="Gaussian")
// Gaussian Calculations
beta = (1 - math.cos(4 * math.asin(1) / samplingPeriod)) / (math.pow(1.414, 2 / poles) - 1)
alpha = -beta + math.sqrt(math.pow(beta, 2) + 2 * beta)
lag = (samplingPeriod - 1) / (2 * poles)
srcData = reducedLag ? gaussianSrc + (gaussianSrc - gaussianSrc[lag]) : gaussianSrc
trData = reducedLag ? ta.tr(true) + (ta.tr(true) - ta.tr(true)[lag]) : ta.tr(true)
[mainFilter, filter1] = f_pole(alpha, srcData, poles)
[trFilter, trFilter1] = f_pole(alpha, trData, poles)
finalFilter = fastResponse ? (mainFilter + filter1) / 2 : mainFilter
finalTrFilter = fastResponse ? (trFilter + trFilter1) / 2 : trFilter
upperBand = finalFilter + finalTrFilter * multiplier
lowerBand = finalFilter - finalTrFilter * multiplier
// ============================================
// Trading Logic
// ============================================
longCondition =
finalFilter > finalFilter[1] and // Green Channel
close > upperBand and // Price above upper band
(k >= 80 or k <= 20) and // Stoch RSI condition
timeCondition
exitCondition = ta.crossunder(close, upperBand)
if longCondition
strategy.entry("Long", strategy.long)
if exitCondition
strategy.close("Long")
// ============================================
// Visuals (Gaussian Only)
// ============================================
bandColor = finalFilter > finalFilter[1] ? color.new(#00ff00, 0) : color.new(#ff0000, 0)
plot(finalFilter, "Filter", bandColor, 2)
plot(upperBand, "Upper Band", bandColor)
plot(lowerBand, "Lower Band", bandColor)
fill(plot(upperBand), plot(lowerBand), color.new(bandColor, 90))
barcolor(close > open and close > upperBand ? color.green :
close < open and close < lowerBand ? color.red : na)