OPEN-SOURCE SCRIPT
james S/R Trend Pro v6

//version=6
strategy("james S/R Trend Pro v6", overlay=true,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
commission_type=strategy.commission.percent,
commission_value=0.05,
slippage=1)
// --- 사용자 입력 (Inputs) ---
group_date = "1. 백테스트 기간"
start_date = input.time(timestamp("2024-01-01 00:00:00"), "시작일", group=group_date)
end_date = input.time(timestamp("2026-12-31 23:59:59"), "종료일", group=group_date)
is_within_date = time >= start_date and time <= end_date
group_main = "2. 지표 설정 (S/R & Trend)"
lookback_sr = input.int(15, "지지/저항 탐색 기간", minval=5, group=group_main)
atr_period = input.int(14, "ATR 기간", group=group_main)
atr_mult = input.float(3.5, "추세선 민감도", step=0.1, group=group_main)
group_color = "3. 다크모드 색상 설정"
trend_up_color = input.color(color.rgb(200, 200, 200), "상승 추세선 (밝은 회색)", group=group_color)
trend_down_color = input.color(color.rgb(255, 255, 255), "하락 추세선 (흰색)", group=group_color)
res_color = input.color(#ff1100, "저항선 (네온 레드)", group=group_color)
sup_color = input.color(#00e1ff, "지지선 (네온 사이언)", group=group_color)
// --- 데이터 처리 (Calculations) ---
// 1. 추세선 (검은색 배경용 고대비 설정)
[trend_line, direction] = ta.supertrend(atr_mult, atr_period)
// 2. 지지/저항선 (피벗 기반)
ph = ta.pivothigh(high, lookback_sr, lookback_sr)
pl = ta.pivotlow(low, lookback_sr, lookback_sr)
var float res_line = na
var float sup_line = na
if not na(ph)
res_line := high[lookback_sr]
if not na(pl)
sup_line := low[lookback_sr]
// --- 전략 로직 (Condition) ---
long_condition = direction < 0 and ta.crossover(close, sup_line)
short_condition = direction > 0 and ta.crossunder(close, res_line)
// --- 주문 실행 (Execution) ---
if is_within_date
if long_condition
strategy.entry("Long", strategy.long, comment="BUY")
if short_condition
strategy.entry("Short", strategy.short, comment="SHORT")
// 청산 로직
if strategy.position_size > 0
strategy.exit("TP-L", "Long", limit=res_line, qty_percent=50, comment="분할익절")
if ta.crossunder(close, trend_line)
strategy.close("Long", comment="추세이탈")
if strategy.position_size < 0
strategy.exit("TP-S", "Short", limit=sup_line, qty_percent=50, comment="분할익절")
if ta.crossover(close, trend_line)
strategy.close("Short", comment="추세이탈")
// --- 시각화 (Visualization - 다크 모드 최적화) ---
// 1. 추세선: 검은 배경에서 잘 보이도록 하얀색/회색 계열 사용
plot(trend_line, color=direction < 0 ? trend_up_color : trend_down_color, linewidth=2, title="Trend Line")
// 2. 지지/저항선: 네온 컬러로 시인성 극대화
plot(res_line, color=color.new(res_color, 0), style=plot.style_linebr, linewidth=2, title="Resistance")
plot(sup_line, color=color.new(sup_color, 0), style=plot.style_linebr, linewidth=2, title="Support")
// 3. 진입 시그널 라벨
plotshape(long_condition, style=shape.triangleup, location=location.belowbar, color=sup_color, size=size.small, title="Buy Label")
plotshape(short_condition, style=shape.triangledown, location=location.abovebar, color=res_color, size=size.small, title="Short Label")
// 4. 추세 배경색 (매우 옅게 설정하여 캔들을 방해하지 않음)
fill_color = direction < 0 ? color.new(sup_color, 90) : color.new(res_color, 90)
fill(plot(trend_line), plot(close), color=fill_color, title="Trend Fill")
strategy("james S/R Trend Pro v6", overlay=true,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
commission_type=strategy.commission.percent,
commission_value=0.05,
slippage=1)
// --- 사용자 입력 (Inputs) ---
group_date = "1. 백테스트 기간"
start_date = input.time(timestamp("2024-01-01 00:00:00"), "시작일", group=group_date)
end_date = input.time(timestamp("2026-12-31 23:59:59"), "종료일", group=group_date)
is_within_date = time >= start_date and time <= end_date
group_main = "2. 지표 설정 (S/R & Trend)"
lookback_sr = input.int(15, "지지/저항 탐색 기간", minval=5, group=group_main)
atr_period = input.int(14, "ATR 기간", group=group_main)
atr_mult = input.float(3.5, "추세선 민감도", step=0.1, group=group_main)
group_color = "3. 다크모드 색상 설정"
trend_up_color = input.color(color.rgb(200, 200, 200), "상승 추세선 (밝은 회색)", group=group_color)
trend_down_color = input.color(color.rgb(255, 255, 255), "하락 추세선 (흰색)", group=group_color)
res_color = input.color(#ff1100, "저항선 (네온 레드)", group=group_color)
sup_color = input.color(#00e1ff, "지지선 (네온 사이언)", group=group_color)
// --- 데이터 처리 (Calculations) ---
// 1. 추세선 (검은색 배경용 고대비 설정)
[trend_line, direction] = ta.supertrend(atr_mult, atr_period)
// 2. 지지/저항선 (피벗 기반)
ph = ta.pivothigh(high, lookback_sr, lookback_sr)
pl = ta.pivotlow(low, lookback_sr, lookback_sr)
var float res_line = na
var float sup_line = na
if not na(ph)
res_line := high[lookback_sr]
if not na(pl)
sup_line := low[lookback_sr]
// --- 전략 로직 (Condition) ---
long_condition = direction < 0 and ta.crossover(close, sup_line)
short_condition = direction > 0 and ta.crossunder(close, res_line)
// --- 주문 실행 (Execution) ---
if is_within_date
if long_condition
strategy.entry("Long", strategy.long, comment="BUY")
if short_condition
strategy.entry("Short", strategy.short, comment="SHORT")
// 청산 로직
if strategy.position_size > 0
strategy.exit("TP-L", "Long", limit=res_line, qty_percent=50, comment="분할익절")
if ta.crossunder(close, trend_line)
strategy.close("Long", comment="추세이탈")
if strategy.position_size < 0
strategy.exit("TP-S", "Short", limit=sup_line, qty_percent=50, comment="분할익절")
if ta.crossover(close, trend_line)
strategy.close("Short", comment="추세이탈")
// --- 시각화 (Visualization - 다크 모드 최적화) ---
// 1. 추세선: 검은 배경에서 잘 보이도록 하얀색/회색 계열 사용
plot(trend_line, color=direction < 0 ? trend_up_color : trend_down_color, linewidth=2, title="Trend Line")
// 2. 지지/저항선: 네온 컬러로 시인성 극대화
plot(res_line, color=color.new(res_color, 0), style=plot.style_linebr, linewidth=2, title="Resistance")
plot(sup_line, color=color.new(sup_color, 0), style=plot.style_linebr, linewidth=2, title="Support")
// 3. 진입 시그널 라벨
plotshape(long_condition, style=shape.triangleup, location=location.belowbar, color=sup_color, size=size.small, title="Buy Label")
plotshape(short_condition, style=shape.triangledown, location=location.abovebar, color=res_color, size=size.small, title="Short Label")
// 4. 추세 배경색 (매우 옅게 설정하여 캔들을 방해하지 않음)
fill_color = direction < 0 ? color.new(sup_color, 90) : color.new(res_color, 90)
fill(plot(trend_line), plot(close), color=fill_color, title="Trend Fill")
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.