
La estrategia utiliza el indicador KDJ y el promedio móvil ((MA) para identificar la tendencia del mercado y generar señales de negociación. La estrategia genera una señal de cierre cuando el indicador KDJ supera la zona de sobreventa y el precio cae por debajo de la MA. La estrategia genera una señal de cierre cuando el indicador KDJ está por debajo de la zona de sobreventa y el precio rompe la MA.
La estrategia, a través de la combinación de los indicadores de KDJ y las medias móviles, puede capturar mejor las tendencias del mercado y generar señales de negociación. El uso racional de la información de sobreventa y sobreventa y la dirección de la tendencia puede obtener un buen rendimiento de las operaciones. Sin embargo, la estrategia aún tiene espacio para optimización, como la introducción de más condiciones de filtración, gestión dinámica de posiciones y paradas de pérdidas, etc., para mejorar aún más la solidez y la rentabilidad de la estrategia.
/*backtest
start: 2024-04-01 00:00:00
end: 2024-04-30 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("KDJ Trending View with Signals and MA Strategy", overlay=true)
// KDJ Settings
kdjLength = input.int(9, title="KDJ Length")
kdjSignal = input.int(3, title="KDJ Signal")
kdjOverbought = input.int(80, title="KDJ Overbought Level")
kdjOversold = input.int(20, title="KDJ Oversold Level")
// Margin Settings
longMargin = input.float(2.0, title="Long Margin", step=0.01)
shortMargin = input.float(2.0, title="Short Margin", step=0.01)
// MA Settings
maLength = input.int(20, title="MA Length")
maType = input.string("SMA", title="MA Type (SMA, EMA, etc.)")
// Calculate KDJ
kdj_highest = ta.highest(high, kdjLength)
kdj_lowest = ta.lowest(low, kdjLength)
kdjRSV = 100 * ((close - kdj_lowest) / (kdj_highest - kdj_lowest))
kdjK = ta.sma(kdjRSV, kdjSignal)
kdjD = ta.sma(kdjK, kdjSignal)
kdjJ = 3 * kdjK - 2 * kdjD
// Calculate Moving Average
ma = ta.sma(close, maLength) // SMA kullanarak ortalama hesaplama
// Determine MA Direction
maCrossUp = ta.crossover(close, ma)
maCrossDown = ta.crossunder(close, ma)
// Plot MA with Direction Color Change
maColor = maCrossUp ? color.green : maCrossDown ? color.red : color.gray
plot(ma, color=maColor, title="Moving Average")
// Plot Trading Signals
plotshape(kdjJ >= kdjOverbought ? low : na, style=shape.triangleup, location=location.belowbar, color=color.red, size=size.small, title="Short Signal")
plotshape(kdjJ <= kdjOversold ? high : na, style=shape.triangledown, location=location.abovebar, color=color.green, size=size.small, title="Long Signal")
// Trading Strategy with Manual Margin and MA Strategy
if (kdjJ >= kdjOverbought and maCrossDown)
strategy.entry("Short", strategy.short, qty=1, comment="Short Entry")
if (kdjJ <= kdjOversold and maCrossUp)
strategy.entry("Long", strategy.long, qty=1, comment="Long Entry")