
La estrategia es un sistema de negociación de ruptura de momentum basado en las bandas de Bollinger, que captura oportunidades de tendencia principalmente a través de la relación entre el precio y la banda de Bollinger. La estrategia utiliza un mecanismo de selección de tipo de línea uniforme adaptativo, combinado con un canal de diferencia estándar para identificar las características de la volatilidad del mercado, especialmente adecuado para aplicaciones en entornos de mercado con mucha volatilidad.
La lógica central de la estrategia se basa en los siguientes elementos clave:
Se trata de una estrategia de seguimiento de tendencias de diseño razonable, con claridad lógica. Capta la dinámica del mercado a través de las características dinámicas de las bandas de Bollinger y tiene un buen mecanismo de control de riesgos. La estrategia es altamente personalizable y puede adaptarse a diferentes entornos de mercado mediante la adaptación de parámetros. Se recomienda una adecuada optimización de parámetros y verificación de retroalimentación en la aplicación en el mundo real, y se recomienda una mejora de la estrategia en combinación con la dirección de optimización recomendada.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-11 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Demo GPT - Bollinger Bands", overlay=true, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// Inputs
length = input.int(20, minval=1, title="Length")
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
offset = input.int(0, "Offset", minval=-500, maxval=500)
// Date range inputs
startYear = input.int(2018, "Start Year", minval=1970, maxval=2100)
startMonth = input.int(1, "Start Month", minval=1, maxval=12)
startDay = input.int(1, "Start Day", minval=1, maxval=31)
endYear = input.int(2069, "End Year", minval=1970, maxval=2100)
endMonth = input.int(12, "End Month", minval=1, maxval=12)
endDay = input.int(31, "End Day", minval=1, maxval=31)
// Time range
startTime = timestamp("GMT+0", startYear, startMonth, startDay, 0, 0)
endTime = timestamp("GMT+0", endYear, endMonth, endDay, 23, 59)
// Moving average function
ma(source, length, _type) =>
switch _type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Calculate Bollinger Bands
basis = ma(src, length, maType)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
// Plot
plot(basis, "Basis", color=#2962FF, offset=offset)
p1 = plot(upper, "Upper", color=#F23645, offset=offset)
p2 = plot(lower, "Lower", color=#089981, offset=offset)
fill(p1, p2, title="Background", color=color.rgb(33, 150, 243, 95))
// Strategy logic: Only go long and flat
inDateRange = time >= startTime and time <= endTime
noPosition = strategy.position_size == 0
longPosition = strategy.position_size > 0
// Buy if close is above upper band
if inDateRange and noPosition and close > upper
strategy.entry("Long", strategy.long)
// Sell/Exit if close is below lower band
if inDateRange and longPosition and close < lower
strategy.close("Long")