볼래틸리티는 지정한 기간동안의 파이낸셜 인스트루먼트의 프라이스 베리에이션을 측정합니다. 프라이스 레인지가 넓을수록 볼래틸리티도 커집니다. 프라이스 레인지가 좁을 수록 볼래틸리티도 낮아집니다.
(위클리, 만쓸리, 데일리) 볼래틸리티 셈에 쓰이는 포뮬러입니다:
//@version=4
study("volatility")fastSearchN(xs, x) => // xs - sorted, ascendingmax_bars_back(xs, 366) left = 0 right = min(bar_index,366) mid = 0if xs < x 0elsefor i = 0 to 9 mid := ceil((left+right) / 2)if left == right breakelse if xs[mid] < x right := mid continueelse if xs[mid] > x left := mid continueelsebreak mid
month1 = 30
month_ago = timenow - 1000*60*60*24*month1 month_ago_this_bar = time - 1000*60*60*24*month1 countOfBars1MonthAgo = fastSearchN(time, month_ago)
countOfBars1MonthAgoThisBar = fastSearchN(time, month_ago_this_bar)
week1 = 7
week_ago = timenow - 1000*60*60*24*week1 week_ago_this_bar = time - 1000*60*60*24*week1 countOfBarsWeekAgo = fastSearchN(time, week_ago)
countOfBarsWeekAgoThisBar = fastSearchN(time, week_ago_this_bar)// volatility
volatility(bb) => bb2 = bb if bar_index == 0 bb2 := 365if bb2 == 0 na else s = sum((high-low)/abs(low) * 100 / bb2, bb2)if bb == 0 na else s
plot(volatility(countOfBarsWeekAgoThisBar), title="Volatility.W")
plot(volatility(countOfBars1MonthAgoThisBar),title="Volatility.M")
plot(tr(true)*100/abs(low), title="Volatility.D")
Java노트: 이 스크립트 밸류는 히스토리와 리얼타임에서 서로 다르며, 이는 timenow 를 쓰기 때문입니다. https://www.tradingview.com/pine-script-docs/en/v4/essential/Indicator_repainting.html 를 읽어 보십시오.
이 스크립트를 여러분의 데일리 차트에 파인스크립트 에디터로 넣어 비주얼을 디스플레이해 볼 수 있습니다. 차트에는 인디케이터가 나타나고 그 플롯은 각 타입의 볼래틸리티 밸류를 보여줍니다.