
La estrategia es un sistema de comercio dinámico de doble ciclo de tiempo basado en un indicador aleatorio (estocástico). Identifica oportunidades de comercio potenciales mediante el análisis de señales cruzadas de indicadores aleatorios en diferentes períodos de tiempo, mientras que combina el principio de dinámica y el método de seguimiento de tendencias para lograr un juicio más preciso de las tendencias del mercado y la captura de la hora de negociar. La estrategia también integra mecanismos de gestión de riesgos, incluida la configuración de stop-loss, para una mejor gestión de fondos.
La lógica central de la estrategia se basa en los siguientes elementos clave:
Se trata de una estrategia de negociación estructurada, lógica y clara, para capturar oportunidades de mercado mediante el análisis de indicadores aleatorios en doble ciclo de tiempo. La ventaja de esta estrategia reside en el mecanismo de confirmación múltiple y el control de riesgos perfectos, pero también se debe tener en cuenta los riesgos como los falsos avances y la sensibilidad de los parámetros.
/*backtest
start: 2024-12-04 00:00:00
end: 2024-12-11 00:00:00
period: 5m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Enhanced Stochastic Strategy", overlay=true)
// Input untuk Stochastic
length = input.int(14, title="Length", minval=1)
OverBought = input(80, title="Overbought Level")
OverSold = input(20, title="Oversold Level")
smoothK = input.int(3, title="Smooth %K")
smoothD = input.int(3, title="Smooth %D")
// Input untuk Manajemen Risiko
tpPerc = input.float(2.0, title="Take Profit (%)", step=0.1)
slPerc = input.float(1.0, title="Stop Loss (%)", step=0.1)
// Hitung Stochastic
k = ta.sma(ta.stoch(close, high, low, length), smoothK)
d = ta.sma(k, smoothD)
// Logika Sinyal
co = ta.crossover(k, d) // %K memotong %D ke atas
cu = ta.crossunder(k, d) // %K memotong %D ke bawah
longCondition = co and k < OverSold
shortCondition = cu and k > OverBought
// Harga untuk TP dan SL
var float longTP = na
var float longSL = na
var float shortTP = na
var float shortSL = na
if (longCondition)
longTP := close * (1 + tpPerc / 100)
longSL := close * (1 - slPerc / 100)
strategy.entry("Buy", strategy.long, comment="StochLE")
strategy.exit("Sell Exit", "Buy", limit=longTP, stop=longSL)
if (shortCondition)
shortTP := close * (1 - tpPerc / 100)
shortSL := close * (1 + slPerc / 100)
strategy.entry("Sell", strategy.short, comment="StochSE")
strategy.exit("Buy Exit", "Sell", limit=shortTP, stop=shortSL)
// Plot Stochastic dan Level
hline(OverBought, "Overbought", color=color.red, linestyle=hline.style_dotted)
hline(OverSold, "Oversold", color=color.green, linestyle=hline.style_dotted)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)
plot(k, color=color.blue, title="%K")
plot(d, color=color.orange, title="%D")
// Tambahkan sinyal visual
plotshape(longCondition, title="Buy Signal", location=location.belowbar, style=shape.labelup, color=color.new(color.green, 0), text="BUY")
plotshape(shortCondition, title="Sell Signal", location=location.abovebar, style=shape.labeldown, color=color.new(color.red, 0), text="SELL")