트렌드 밴드 인디케이터
작성자 정보
- 차트분석 작성
- 작성일
컨텐츠 정보
- 3,496 조회
- 517 추천
- 221 비추천
- 목록
본문
Trend Band 인디케이터는 이동평균(MA)과 Heikin Ashi 캔들, 그리고 추세 반전 신호를 활용하여 시장 트렌드와 변화를 시각적으로 표시해주는 맞춤형 TradingView 스크립트입니다.
이 인디케이터는 2개의 변동성 기반 트렌드 라인을 생성하며, 특정 조건에서 추세 전환 신호(상승 / 하락 )를 감지하여 매매 전략을 수립하는 데 도움을 줍니다.
기능
트렌드 라인(Trend Band) 생성
- 두 개의 변동성 기반 트렌드 라인을 계산하여 차트에 표시
- 가격이 트렌드 라인을 돌파하는지 여부에 따라 추세 방향을 시각화
다양한 이동평균(MA) 선택 가능
- 사용자가 선택할 수 있는 이동평균 유형:
- 단순 이동평균(SMA)
- 적응형 이동평균(ALMA)
- 지수 이동평균(EMA)
- 스무딩 이동평균(SMMA, RMA)
- 가중 이동평균(WMA)
- 거래량 가중 이동평균(VWMA)
- 헐 이동평균(HMA)
Heikin Ashi(하이킨 아시) 캔들 적용 가능
- 일반 캔들 대신 Heikin Ashi 캔들을 사용하여 노이즈를 줄이고 부드러운 트렌드 표시 가능
- Heikin Ashi 기반의 트렌드 컬러 변화 감지
트렌드 반전 신호(▲▼) 제공
- ▲ 매수 신호: 강한 상승 반전이 감지될 경우 표시
- ▼ 매도 신호: 강한 하락 반전이 감지될 경우 표시
추세 색상 변경 및 트렌드 필링(Fill Trend) 기능
- 추세의 강도에 따라 색상이 자동 변경됨
- 상승 추세일 경우 녹색, 하락 추세일 경우 빨간색
- 추세 필링(Fill Trend) 옵션을 활성화하면 트렌드 밴드 영역을 색상으로 채워서 추세 강도 시각화
세부 작동 원리
1. 트렌드 라인(Trend Band) 계산
- 기본 이동평균 길이는
200
으로 설정 ma_ = ma(close , length , maTypeInput)
- 선택된 이동평균 방식에 따라
close
가격을 기반으로 MA 계산
- 선택된 이동평균 방식에 따라
closeMA = ta.sma(close, amp)
- 짧은 기간 이동평균을 계산하여 단기적인 변동성을 반영
highestHigh = ta.highest(amp)
- 설정된 기간 동안의 최고가를 찾음
lowestLow = ta.lowest(amp)
- 설정된 기간 동안의 최저가를 찾음
2. Heikin Ashi(하이킨 아시) 적용 (옵션)
- Heikin Ashi 캔들을 사용하면 일반 캔들보다 트렌드가 더 부드럽게 표현됨
useHeikin
옵션을 활성화하면 Heikin Ashi 캔들 값을 적용ha.close = (nz(ha.open) + nz(ha.high) + nz(ha.low) + hl_t) / 4
- Heikin Ashi 캔들의 종가를 계산
ha.open = na(ha.open[1]) ? (hl_t + hl_t[1]) / 2 : (nz(ha.open[1]) + nz(ha.close[1])) / 2
- Heikin Ashi 캔들의 시가를 계산
3. 트렌드 강도 측정
trend_st = (ha.high - ha.low) / ta.stdev((ha.high - ha.low), 200)
- Heikin Ashi 캔들의 변동성을 표준편차로 나누어 트렌드 강도를 수치화
- 강한 추세일 경우 최대
100
까지 증가하며, 이를 색상 변화에 반영하여 시각적인 피드백 제공
4. 추세 반전 신호 감지 (▲▼)
up_signal = ta.crossover(hl_t, hl_t[1])
- 트렌드 라인이 이전 값보다 상승할 때 매수 신호 발생
dn_signal = ta.crossunder(hl_t, hl_t[1])
- 트렌드 라인이 이전 값보다 하락할 때 매도 신호 발생
plotshape(up_signal ? hl_t[1] : na, title="Up", location=location.absolute, color=up_col, style=shape.circle, size=size.tiny, offset=-1)
- ▲ 매수 신호를 차트에 표시
plotshape(dn_signal ? hl_t[1] : na, title="Down", location=location.absolute, color=dn_col, style=shape.circle, size=size.tiny, offset=-1)
- ▼ 매도 신호를 차트에 표시
5. 추세 필링(Fill Trend) 기능
filltrend
옵션을 활성화하면 상승/하락 구간을 색상으로 채워서 시각적 가독성 향상fill(p1, p11, title="fill trend", color=color5)
- 상승 구간 → 녹색, 하락 구간 → 빨간색
사용 방법
이동평균 유형 선택
SMA
,EMA
,HMA
,VWMA
등 다양한 이동평균 방식을 선택 가능
Heikin Ashi 적용 가능
- 일반 캔들보다 부드러운 트렌드를 보고 싶다면
useHeikin
옵션을 활성화
트렌드 컬러 및 신호 확인
- 녹색 → 상승 추세, 빨간색 → 하락 추세
▲
신호가 나타나면 매수 고려,▼
신호가 나타나면 매도 고려
추세 필링(Fill Trend) 활용
filltrend
옵션을 활성화하면 트렌드 강도를 색상으로 표현하여 직관적인 분석 가능
주의사항
이 인디케이터는 시장의 트렌드를 시각적으로 보여주는 도구일 뿐, 100% 정확한 매매 신호를 보장하지 않습니다.
추세는 강하게 지속될 수도 있으며, 특정 신호가 나온다고 해서 반드시 반전이 발생하는 것은 아닙니다.
투자 시 유의해야 할 사항
잘못된 신호(거짓 신호, False Signal) 가능성
- 트렌드가 강하게 유지되는 경우, 반전 신호가 나와도 변동성이 커질 수 있음
- 다른 보조 지표(예: MACD, 볼린저 밴드, 거래량 분석)와 함께 활용 필요
시장 변동성 고려
- 변동성이 극심한 시장에서는 신호가 잦아지거나 신뢰도가 낮아질 수 있음
백테스트 및 실전 적용 전 시뮬레이션 필요
- 실제 거래 전에 백테스트 및 데모 트레이딩을 통해 전략을 검증하는 것이 중요
책임은 투자자 본인에게 있음
- 이 인디케이터는 보조도구일 뿐, 모든 투자 결정은 본인의 책임
Trend Band 인디케이터는 추세 분석 및 반전 신호 탐지에 유용하지만, 신호의 신뢰도를 높이기 위해 다른 기술적 분석 도구와 함께 사용해야 합니다.
시장 상황에 따라 신호가 달라질 수 있으므로 항상 리스크 관리를 철저히 해야 합니다.
//@version=5
indicator(title='Trend Band', shorttitle='Trend Band', overlay=true,timeframe="",timeframe_gaps=true)
///INPUTS
int amp = input.int(5, "Amplitude1", minval=1)
int amp1 = input.int(3, "Amplitude2", minval=1)
bool useHeikin = false
color up_col = input.color(#1dff00, "Up", group="Trend Colors", inline="1")
color dn_col = input.color(#ff0000, "Down", group="Trend Colors", inline="1")
bool trend_candl = false
filltrend = input(defval=false,title="fill trend?")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "ALMA", "EMA", "SMMA (RMA)", "WMA", "VWMA","HMA"], group="MA Settings")
length = input(defval=200,title="Length Moving", group="MA Settings")
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"HMA" => ta.hma(source,length)
"ALMA" => ta.alma(source, length,0.5,6)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
ma_ = ma(close , length , maTypeInput)
plot(ma_ , color= color.blue,title="Moving",display=display.none)
type HeikinAshi
float open
float high
float low
float close
var HeikinAshi ha = HeikinAshi.new(na, na, na, na) // Initialize Heikin Ashi UDT
var HeikinAshi ha1 = HeikinAshi.new(na, na, na, na) // Initialize Heikin Ashi UDT
// Variable Initialization
var bool up_signal = na
var bool dn_signal = na
var color trend_col = na
var bool up_signal1 = na
var bool dn_signal1 = na
var color trend_col1 = na
var float hl_t = 0.
var float hl_t1 = 0.
var float trend_st = 0.
var float oc2 = na
var float trend_st1 = 0.
var float oc21 = na
///CALCULATIONS
series float closeMA = ta.sma(close, amp)
series float highestHigh = ta.highest(amp)
series float lowestLow = ta.lowest(amp)
series float closeMA1 = ta.sma(close, amp1)
series float highestHigh1 = ta.highest(amp1)
series float lowestLow1 = ta.lowest(amp1)
///Initialize half trend on the first bar
if barstate.isfirst
hl_t := close
if barstate.isfirst
hl_t1 := close
///Update half trend value based on conditions
switch
closeMA < hl_t and highestHigh < hl_t => hl_t := highestHigh
closeMA > hl_t and lowestLow > hl_t => hl_t := lowestLow
=> hl_t := hl_t
switch
closeMA1 < hl_t1 and highestHigh1 < hl_t1 => hl_t1 := highestHigh1
closeMA1 > hl_t1 and lowestLow1 > hl_t1 => hl_t1 := lowestLow1
=> hl_t1 := hl_t1
// Calculate Heikin Ashi values based on Half Trend
if useHeikin
ha.close := (nz(ha.open) + nz(ha.high) + nz(ha.low) + hl_t) / 4
ha.open := na(ha.open[1]) ? (hl_t + hl_t[1]) / 2 : (nz(ha.open[1]) + nz(ha.close[1])) / 2
ha.high := math.max(hl_t, math.max(ha.open, ha.close))
ha.low := math.min(hl_t, math.min(ha.open, ha.close))
oc2 := (ha.close + ha.open) / 2
if useHeikin
ha1.close := (nz(ha1.open) + nz(ha1.high) + nz(ha1.low) + hl_t1) / 4
ha1.open := na(ha1.open[1]) ? (hl_t1 + hl_t1[1]) / 2 : (nz(ha1.open[1]) + nz(ha1.close[1])) / 2
ha1.high := math.max(hl_t1, math.max(ha1.open, ha1.close))
ha1.low := math.min(hl_t1, math.min(ha1.open, ha1.close))
oc21 := (ha1.close + ha1.open) / 2
// Calculate trend strength
trend_st := (ha.high - ha.low) / ta.stdev((ha.high - ha.low), 200)
trend_st := (trend_st * 20) > 100 ? 100 : (trend_st * 20)
trend_st1 := (ha1.high - ha1.low) / ta.stdev((ha1.high - ha1.low), 200)
trend_st1 := (trend_st1 * 20) > 100 ? 100 : (trend_st1 * 20)
// Determine trend color
if ta.crossover(hl_t, hl_t[1])
trend_col := up_col
if ta.crossunder(hl_t, hl_t[1])
trend_col := dn_col
if ta.crossover(hl_t1, hl_t1[1])
trend_col1 := up_col
if ta.crossunder(hl_t1, hl_t1[1])
trend_col1 := dn_col
// Signal conditions for trend direction
float trend_change = (ha.close - ha.open) / ha.open
up_signal := useHeikin ? ta.crossover (trend_change, 0) : ta.crossover (hl_t, hl_t[1]) and ta.change(trend_col == up_col)
dn_signal := useHeikin ? ta.crossunder(trend_change, 0) : ta.crossunder(hl_t, hl_t[1]) and ta.change(trend_col == dn_col)
// }
float trend_change1 = (ha1.close - ha1.open) / ha1.open
up_signal1 := useHeikin ? ta.crossover (trend_change1, 0) : ta.crossover (hl_t1, hl_t1[1]) and ta.change(trend_col1 == up_col)
dn_signal1 := useHeikin ? ta.crossunder(trend_change1, 0) : ta.crossunder(hl_t1, hl_t1[1]) and ta.change(trend_col1 == dn_col)
// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Heikin Ashi colors
color haColor = ha.close > ha.open
? color.from_gradient(trend_st, 0, 100, color.new(up_col, 70), up_col)
: color.from_gradient(trend_st, 0, 100, color.new(dn_col, 70), dn_col)
color ha_border_col = ha.close > ha.open
? color.from_gradient(trend_st, 0, 70, color.new(up_col, 70), up_col)
: color.from_gradient(trend_st, 0, 70, color.new(dn_col, 70), dn_col)
// Set candle color based on trend
color candle_col = trend_candl ? (useHeikin ? (ha.close > ha.open ? up_col : dn_col) : trend_col) : na
color haColor1 = ha1.close > ha1.open
? color.from_gradient(trend_st1, 0, 100, color.new(up_col, 70), up_col)
: color.from_gradient(trend_st1, 0, 100, color.new(dn_col, 70), dn_col)
color ha_border_col1 = ha1.close > ha1.open
? color.from_gradient(trend_st1, 0, 70, color.new(up_col, 70), up_col)
: color.from_gradient(trend_st1, 0, 70, color.new(dn_col, 70), dn_col)
// Set candle color based on trend
color candle_col1 = trend_candl ? (useHeikin ? (ha1.close > ha1.open ? up_col : dn_col) : trend_col1) : na
// Plot half trend line
p1 = plot(useHeikin ? na : hl_t, color = trend_col, linewidth = 2, editable = false)
p2 = plot(hl2, display = display.none, editable = false)
p11 = plot(useHeikin ? na : hl_t1, color = trend_col1, linewidth = 2, editable = false)
p21 = plot(hl2, display = display.none, editable = false)
color5 = trend_col1==up_col and filltrend ? color.new(up_col,80) : trend_col1==dn_col and filltrend ? color.new(dn_col,80) : na
fill(p1,p11,title="fill trend",color=color5)
// Fill between lines
// Plot upward signals
plotshape(
up_signal ? (useHeikin ? oc2 : hl_t[1]) : na,
title = "Up",
location = location.absolute, color=up_col,
style = shape.circle,
size = size.tiny,
offset =-1
)
// Plot downward signals
plotshape(
dn_signal ? (useHeikin ? oc2 : hl_t[1]) : na,
title = "Down",
location = location.absolute,
color = dn_col,
style = shape.circle,
size = size.tiny,
offset =-1
)
plotshape(
up_signal1 ? (useHeikin ? oc21 : hl_t1[1]) : na,
title = "Up1",
location = location.absolute, color=up_col,
style = shape.circle,
size = size.tiny,
offset =-1
)
// Plot downward signals
plotshape(
dn_signal1 ? (useHeikin ? oc21 : hl_t1[1]) : na,
title = "Down1",
location = location.absolute,
color = dn_col,
style = shape.circle,
size = size.tiny,
offset =-1
)
관련자료
-
이전
-
다음
댓글 0
등록된 댓글이 없습니다.