OPEN-SOURCE SCRIPT
jaems_Combo: StochRSI + MACD + ADX [QuantDev]

//version=6
strategy("jaems_Combo: StochRSI + MACD + ADX [QuantDev]", overlay=false, initial_capital=10000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.05, slippage=1)
// ==========================================
// 1. 사용자 입력 (User Inputs)
// ==========================================
// [시간 필터]
grp_time = "Backtest Period"
useDateFilter = input.bool(true, "기간 필터 적용", group=grp_time)
startDate = input.time(timestamp("2023-01-01 00:00"), "시작일", group=grp_time)
endDate = input.time(timestamp("2099-12-31 23:59"), "종료일", group=grp_time)
inDateRange = not useDateFilter or (time >= startDate and time <= endDate)
// [Stoch RSI 설정]
grp_stoch = "1. Stochastic RSI Settings"
stoch_len = input.int(14, "RSI Length", group=grp_stoch)
stoch_k = input.int(3, "K", group=grp_stoch)
stoch_d = input.int(3, "D", group=grp_stoch)
rsi_len = input.int(14, "Stochastic Length", group=grp_stoch)
// [MACD 설정]
grp_macd = "2. MACD Settings (Normalized)"
macd_fast = input.int(12, "Fast Length", group=grp_macd)
macd_slow = input.int(26, "Slow Length", group=grp_macd)
macd_sig = input.int(9, "Signal Length", group=grp_macd)
macd_norm_len = input.int(100, "Normalization Lookback", group=grp_macd)
// [ADX 설정]
grp_adx = "3. ADX Settings"
adx_len = input.int(14, "ADX Smoothing", group=grp_adx)
di_len = input.int(14, "DI Length", group=grp_adx)
adx_thresh = input.int(25, "ADX Threshold", group=grp_adx)
// [리스크 관리]
grp_risk = "4. Risk Management"
stopLossPct = input.float(2.0, "손절매 (Stop Loss %)", step=0.1, group=grp_risk) / 100
takeProfitPct = input.float(4.0, "익절매 (Take Profit %)", step=0.1, group=grp_risk) / 100
// [알림 메시지 설정] - 신규 추가 (Alert Configuration)
grp_alert = "5. Alert Configuration"
msg_long_entry = input.string("Long Entry Triggered", "Long 진입 메시지", group=grp_alert)
msg_short_entry = input.string("Short Entry Triggered", "Short 진입 메시지", group=grp_alert)
msg_long_exit = input.string("Long Position Closed", "Long 청산 메시지", group=grp_alert)
msg_short_exit = input.string("Short Position Closed", "Short 청산 메시지", group=grp_alert)
// ==========================================
// 2. 데이터 처리 및 지표 계산
// ==========================================
// Stoch RSI
rsi_val = ta.rsi(close, rsi_len)
k = ta.sma(ta.stoch(rsi_val, rsi_val, rsi_val, stoch_len), stoch_k)
d = ta.sma(k, stoch_d)
// ADX
[di_plus, di_minus, adx] = ta.dmi(di_len, adx_len)
// Normalized MACD (0~100 Scale)
[macd_line, macd_signal, macd_hist] = ta.macd(close, macd_fast, macd_slow, macd_sig)
highest_macd = ta.highest(macd_line, macd_norm_len)
lowest_macd = ta.lowest(macd_line, macd_norm_len)
// 분모가 0이 되는 예외 처리
denom = (highest_macd - lowest_macd)
norm_macd = denom != 0 ? (macd_line - lowest_macd) / denom * 100 : 50
norm_signal = denom != 0 ? (macd_signal - lowest_macd) / denom * 100 : 50
// ==========================================
// 3. 시각화 (Dark Mode Optimized Colors)
// ==========================================
color gridColor = color.new(#787B86, 50)
hline(0, "Bottom", color=gridColor)
hline(50, "Middle", color=gridColor, linestyle=hline.style_dotted)
hline(100, "Top", color=gridColor)
plot(k, "Stoch K", color=color.new(#00E5FF, 0), linewidth=1) // Neon Cyan
plot(d, "Stoch D", color=color.new(#EA00FF, 0), linewidth=1) // Neon Magenta
plot(adx, "ADX", color=color.new(#FFEB3B, 0), linewidth=2)
hline(adx_thresh, "ADX Threshold", color=color.new(#FFEB3B, 50), linestyle=hline.style_dashed)
plot(norm_macd, "Norm MACD", color=color.new(#76FF03, 60), style=plot.style_area)
plot(norm_signal, "Norm Signal", color=color.new(#FF1744, 20), linewidth=1)
// ==========================================
// 4. 전략 로직 (Strategy Logic) - 요청하신 내용으로 전면 수정
// ==========================================
// 조건: K가 D보다 크고(AND) K가 Norm Signal보다 큰 상태
bool is_bullish = (k > d) and (k > norm_signal)
// 조건: K가 D보다 작고(AND) K가 Norm Signal보다 작은 상태
bool is_bearish = (k < d) and (k < norm_signal)
// 진입 신호: "이전 봉에는 아니었는데, 지금 봉에서 두 조건을 동시에 만족했을 때" (돌파 순간)
longCondition = is_bullish and not is_bullish[1]
shortCondition = is_bearish and not is_bearish[1]
// 주문 실행 (Confirmed Bar Only) + Alert Message 연결
if inDateRange and barstate.isconfirmed
if longCondition
strategy.entry("Long", strategy.long, alert_message=msg_long_entry)
if shortCondition
strategy.entry("Short", strategy.short, alert_message=msg_short_entry)
// ==========================================
// 5. 청산 및 신호 강조 (Alert Message 추가)
// ==========================================
if strategy.position_size > 0
strategy.exit("Long Exit", "Long", stop=strategy.position_avg_price * (1 - stopLossPct), limit=strategy.position_avg_price * (1 + takeProfitPct), alert_message=msg_long_exit)
if strategy.position_size < 0
strategy.exit("Short Exit", "Short", stop=strategy.position_avg_price * (1 + stopLossPct), limit=strategy.position_avg_price * (1 - takeProfitPct), alert_message=msg_short_exit)
// 배경 신호
bgcolor(longCondition ? color.new(#76FF03, 90) : na, title="Long Signal BG")
bgcolor(shortCondition ? color.new(#FF1744, 90) : na, title="Short Signal BG")
strategy("jaems_Combo: StochRSI + MACD + ADX [QuantDev]", overlay=false, initial_capital=10000, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.05, slippage=1)
// ==========================================
// 1. 사용자 입력 (User Inputs)
// ==========================================
// [시간 필터]
grp_time = "Backtest Period"
useDateFilter = input.bool(true, "기간 필터 적용", group=grp_time)
startDate = input.time(timestamp("2023-01-01 00:00"), "시작일", group=grp_time)
endDate = input.time(timestamp("2099-12-31 23:59"), "종료일", group=grp_time)
inDateRange = not useDateFilter or (time >= startDate and time <= endDate)
// [Stoch RSI 설정]
grp_stoch = "1. Stochastic RSI Settings"
stoch_len = input.int(14, "RSI Length", group=grp_stoch)
stoch_k = input.int(3, "K", group=grp_stoch)
stoch_d = input.int(3, "D", group=grp_stoch)
rsi_len = input.int(14, "Stochastic Length", group=grp_stoch)
// [MACD 설정]
grp_macd = "2. MACD Settings (Normalized)"
macd_fast = input.int(12, "Fast Length", group=grp_macd)
macd_slow = input.int(26, "Slow Length", group=grp_macd)
macd_sig = input.int(9, "Signal Length", group=grp_macd)
macd_norm_len = input.int(100, "Normalization Lookback", group=grp_macd)
// [ADX 설정]
grp_adx = "3. ADX Settings"
adx_len = input.int(14, "ADX Smoothing", group=grp_adx)
di_len = input.int(14, "DI Length", group=grp_adx)
adx_thresh = input.int(25, "ADX Threshold", group=grp_adx)
// [리스크 관리]
grp_risk = "4. Risk Management"
stopLossPct = input.float(2.0, "손절매 (Stop Loss %)", step=0.1, group=grp_risk) / 100
takeProfitPct = input.float(4.0, "익절매 (Take Profit %)", step=0.1, group=grp_risk) / 100
// [알림 메시지 설정] - 신규 추가 (Alert Configuration)
grp_alert = "5. Alert Configuration"
msg_long_entry = input.string("Long Entry Triggered", "Long 진입 메시지", group=grp_alert)
msg_short_entry = input.string("Short Entry Triggered", "Short 진입 메시지", group=grp_alert)
msg_long_exit = input.string("Long Position Closed", "Long 청산 메시지", group=grp_alert)
msg_short_exit = input.string("Short Position Closed", "Short 청산 메시지", group=grp_alert)
// ==========================================
// 2. 데이터 처리 및 지표 계산
// ==========================================
// Stoch RSI
rsi_val = ta.rsi(close, rsi_len)
k = ta.sma(ta.stoch(rsi_val, rsi_val, rsi_val, stoch_len), stoch_k)
d = ta.sma(k, stoch_d)
// ADX
[di_plus, di_minus, adx] = ta.dmi(di_len, adx_len)
// Normalized MACD (0~100 Scale)
[macd_line, macd_signal, macd_hist] = ta.macd(close, macd_fast, macd_slow, macd_sig)
highest_macd = ta.highest(macd_line, macd_norm_len)
lowest_macd = ta.lowest(macd_line, macd_norm_len)
// 분모가 0이 되는 예외 처리
denom = (highest_macd - lowest_macd)
norm_macd = denom != 0 ? (macd_line - lowest_macd) / denom * 100 : 50
norm_signal = denom != 0 ? (macd_signal - lowest_macd) / denom * 100 : 50
// ==========================================
// 3. 시각화 (Dark Mode Optimized Colors)
// ==========================================
color gridColor = color.new(#787B86, 50)
hline(0, "Bottom", color=gridColor)
hline(50, "Middle", color=gridColor, linestyle=hline.style_dotted)
hline(100, "Top", color=gridColor)
plot(k, "Stoch K", color=color.new(#00E5FF, 0), linewidth=1) // Neon Cyan
plot(d, "Stoch D", color=color.new(#EA00FF, 0), linewidth=1) // Neon Magenta
plot(adx, "ADX", color=color.new(#FFEB3B, 0), linewidth=2)
hline(adx_thresh, "ADX Threshold", color=color.new(#FFEB3B, 50), linestyle=hline.style_dashed)
plot(norm_macd, "Norm MACD", color=color.new(#76FF03, 60), style=plot.style_area)
plot(norm_signal, "Norm Signal", color=color.new(#FF1744, 20), linewidth=1)
// ==========================================
// 4. 전략 로직 (Strategy Logic) - 요청하신 내용으로 전면 수정
// ==========================================
// 조건: K가 D보다 크고(AND) K가 Norm Signal보다 큰 상태
bool is_bullish = (k > d) and (k > norm_signal)
// 조건: K가 D보다 작고(AND) K가 Norm Signal보다 작은 상태
bool is_bearish = (k < d) and (k < norm_signal)
// 진입 신호: "이전 봉에는 아니었는데, 지금 봉에서 두 조건을 동시에 만족했을 때" (돌파 순간)
longCondition = is_bullish and not is_bullish[1]
shortCondition = is_bearish and not is_bearish[1]
// 주문 실행 (Confirmed Bar Only) + Alert Message 연결
if inDateRange and barstate.isconfirmed
if longCondition
strategy.entry("Long", strategy.long, alert_message=msg_long_entry)
if shortCondition
strategy.entry("Short", strategy.short, alert_message=msg_short_entry)
// ==========================================
// 5. 청산 및 신호 강조 (Alert Message 추가)
// ==========================================
if strategy.position_size > 0
strategy.exit("Long Exit", "Long", stop=strategy.position_avg_price * (1 - stopLossPct), limit=strategy.position_avg_price * (1 + takeProfitPct), alert_message=msg_long_exit)
if strategy.position_size < 0
strategy.exit("Short Exit", "Short", stop=strategy.position_avg_price * (1 + stopLossPct), limit=strategy.position_avg_price * (1 - takeProfitPct), alert_message=msg_short_exit)
// 배경 신호
bgcolor(longCondition ? color.new(#76FF03, 90) : na, title="Long Signal BG")
bgcolor(shortCondition ? color.new(#FF1744, 90) : na, title="Short Signal BG")
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.