OPEN-SOURCE SCRIPT
james S/R Trend Pro v6

//version=6
strategy("jaems_MACD+RSI[Fixed]", shorttitle="jaems_MACD+RSI[Fixed]", overlay=false, initial_capital=10000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05, calc_on_every_tick=false)
// =============================================================================
// 1. 설정 (Inputs)
// =============================================================================
group_macd = "📊 MACD 설정"
fastLen = input.int(12, "Fast Length", group=group_macd)
slowLen = input.int(26, "Slow Length", group=group_macd)
sigLen = input.int(9, "Signal Smoothing", group=group_macd)
src = input.source(close, "Source", group=group_macd)
group_col = "🎨 시각화 색상"
col_up = input.color(color.new(#00E676, 0), "상승 (Neon Green)", group=group_col)
col_dn = input.color(color.new(#FF1744, 0), "하락 (Red)", group=group_col)
col_sig = input.color(color.new(#FFEA00, 0), "Signal 기본색", group=group_col)
// =============================================================================
// 2. 계산 (Calculations)
// =============================================================================
fastMA = ta.ema(src, fastLen)
slowMA = ta.ema(src, slowLen)
macd = fastMA - slowMA
signal = ta.ema(macd, sigLen)
hist = macd - signal
// 교차 확인 (Crossovers)
bool crossUp = ta.crossover(macd, signal)
bool crossDn = ta.crossunder(macd, signal)
// 추세 상태 확인
bool isBullish = macd >= signal
// =============================================================================
// 3. 전략 실행 (Execution)
// =============================================================================
if crossUp
strategy.entry("Long", strategy.long)
if crossDn
strategy.entry("Short", strategy.short)
// =============================================================================
// 4. 시각화 (Visualization) - 수정된 부분
// =============================================================================
// 4.1 MACD 라인 색상 동적 변경
color macdDynamicColor = isBullish ? col_up : col_dn
// 4.2 라인 그리기
plot(macd, title="MACD Line", color=macdDynamicColor, linewidth=2)
plot(signal, title="Signal Line", color=col_sig, linewidth=1)
// 4.3 교차점 도트 (Thick Dots) - 괄호 오류 방지를 위해 명시적 변수 할당
float dotLevelUp = crossUp ? signal : na
float dotLevelDn = crossDn ? signal : na
plot(dotLevelUp, title="Golden Cross Dot", style=plot.style_circles, color=col_up, linewidth=5)
plot(dotLevelDn, title="Dead Cross Dot", style=plot.style_circles, color=col_dn, linewidth=5)
// 4.4 히스토그램 색상 (오류 수정: 중첩 삼항연산자 제거 -> if-else 변환)
color histColor = na
if isBullish
// 상승 추세일 때: 히스토그램이 직전보다 커지면 진한색, 작아지면 연한색
if hist[1] < hist
histColor := col_up
else
histColor := color.new(col_up, 50)
else
// 하락 추세일 때: 히스토그램이 직전보다 커지면(덜 음수면) 연한색, 작아지면 진한색
if hist[1] < hist
histColor := color.new(col_dn, 50)
else
histColor := col_dn
plot(hist, title="Histogram", style=plot.style_columns, color=histColor)
// 4.5 기준선
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)
strategy("jaems_MACD+RSI[Fixed]", shorttitle="jaems_MACD+RSI[Fixed]", overlay=false, initial_capital=10000, currency=currency.USD, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05, calc_on_every_tick=false)
// =============================================================================
// 1. 설정 (Inputs)
// =============================================================================
group_macd = "📊 MACD 설정"
fastLen = input.int(12, "Fast Length", group=group_macd)
slowLen = input.int(26, "Slow Length", group=group_macd)
sigLen = input.int(9, "Signal Smoothing", group=group_macd)
src = input.source(close, "Source", group=group_macd)
group_col = "🎨 시각화 색상"
col_up = input.color(color.new(#00E676, 0), "상승 (Neon Green)", group=group_col)
col_dn = input.color(color.new(#FF1744, 0), "하락 (Red)", group=group_col)
col_sig = input.color(color.new(#FFEA00, 0), "Signal 기본색", group=group_col)
// =============================================================================
// 2. 계산 (Calculations)
// =============================================================================
fastMA = ta.ema(src, fastLen)
slowMA = ta.ema(src, slowLen)
macd = fastMA - slowMA
signal = ta.ema(macd, sigLen)
hist = macd - signal
// 교차 확인 (Crossovers)
bool crossUp = ta.crossover(macd, signal)
bool crossDn = ta.crossunder(macd, signal)
// 추세 상태 확인
bool isBullish = macd >= signal
// =============================================================================
// 3. 전략 실행 (Execution)
// =============================================================================
if crossUp
strategy.entry("Long", strategy.long)
if crossDn
strategy.entry("Short", strategy.short)
// =============================================================================
// 4. 시각화 (Visualization) - 수정된 부분
// =============================================================================
// 4.1 MACD 라인 색상 동적 변경
color macdDynamicColor = isBullish ? col_up : col_dn
// 4.2 라인 그리기
plot(macd, title="MACD Line", color=macdDynamicColor, linewidth=2)
plot(signal, title="Signal Line", color=col_sig, linewidth=1)
// 4.3 교차점 도트 (Thick Dots) - 괄호 오류 방지를 위해 명시적 변수 할당
float dotLevelUp = crossUp ? signal : na
float dotLevelDn = crossDn ? signal : na
plot(dotLevelUp, title="Golden Cross Dot", style=plot.style_circles, color=col_up, linewidth=5)
plot(dotLevelDn, title="Dead Cross Dot", style=plot.style_circles, color=col_dn, linewidth=5)
// 4.4 히스토그램 색상 (오류 수정: 중첩 삼항연산자 제거 -> if-else 변환)
color histColor = na
if isBullish
// 상승 추세일 때: 히스토그램이 직전보다 커지면 진한색, 작아지면 연한색
if hist[1] < hist
histColor := col_up
else
histColor := color.new(col_up, 50)
else
// 하락 추세일 때: 히스토그램이 직전보다 커지면(덜 음수면) 연한색, 작아지면 진한색
if hist[1] < hist
histColor := color.new(col_dn, 50)
else
histColor := col_dn
plot(hist, title="Histogram", style=plot.style_columns, color=histColor)
// 4.5 기준선
hline(0, "Zero Line", color=color.gray, linestyle=hline.style_dotted)
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.