스크립트 인풋을 섹션 및 라인으로 관리

Mar 12, 2021

파인 최신 업데이트에 인풋에 대한 두 가지 나아진 것이 있습니다:

  • group 파라미터로 인풋 그룹용 섹션 헤더를 디파인할 수 있도록 하였습니다.
  • 새 inline 파라미터로 멀티플 인풋이 한 라인에 조인될 수 있도록 하였습니다. 

이러한 피처를 써서 인풋을 좀 더 깔끔하게 정리할 수 있습니다. 보기 : Auto Fib Retracement 인디케이터.

새로운 파라미터는 쓰기 쉽습니다! VWAP 인디케이터를 보면 셈을 하기 위한 스타트/스탑 포인트를 유저가 지정하고 앵커 디스플레이를 컨트로할 수 있습니다.

//@version=4
study(title = "Custom Period VWAP", shorttitle = "CPVWAP", overlay = true)

src = input(hlc3, "Source", input.source)
enableHighlight = input(true, "Highlight", input.bool, inline = "Highlight")
highlightType = input("Anchors", "", input.string, options = ["Anchors", "Background"], inline = "Highlight")
highlightColor = input(color.red, "", input.color, inline = "Highlight")
useStartPeriodTime = input(true, "Start", input.bool, group = "Date Range", inline = "Start Period")
startPeriodTime = input(timestamp("20 Jan 2021"), "", input.time, group = "Date Range", inline = "Start Period")
useEndPeriodTime = input(true, "End", input.bool, group = "Date Range", inline = "End Period")
endPeriodTime = input(timestamp("20 Feb 2021"), "", input.time, group = "Date Range", inline = "End Period")

start = useStartPeriodTime ? startPeriodTime >= time : false
end = useEndPeriodTime ? endPeriodTime <= time : false
calcPeriod = not start and not end

var srcVolArray = array.new_float(na)
var volArray = array.new_float(na)
var line startAnchor = line.new(na, na, na, na, xloc.bar_time, extend.both, highlightColor, width = 2)
var line endAnchor = line.new(na, na, na, na, xloc.bar_time, extend.both, highlightColor, width = 2)
useBgcolor = false

if calcPeriod
    array.push(srcVolArray, src*volume)
    array.push(volArray, volume)
else
    array.clear(srcVolArray), array.clear(volArray)

customVwap = array.sum(srcVolArray) / array.sum(volArray)
if enableHighlight
    if highlightType == "Anchors"
        if useStartPeriodTime
            line.set_xy1(startAnchor, startPeriodTime, low)
            line.set_xy2(startAnchor, startPeriodTime, high)
        if useEndPeriodTime
            line.set_xy1(endAnchor, not na(customVwap) ? time : line.get_x1(endAnchor), low)
            line.set_xy2(endAnchor, not na(customVwap) ? time : line.get_x1(endAnchor), high)
    if highlightType == "Background"
        useBgcolor :=  true

bgcolor(useBgcolor and calcPeriod ? highlightColor : na, editable = false)
plot(customVwap, title="CPVWAP", color = color.blue, linewidth = 2)

group 아규먼트는 두 가지로 쓰입니다. 그룹 헤더로 쓰이며 또한 그 그룹에 어떤 인풋이 들어가는 지를 디파인합니다.

inline 아규먼트를 쓰게 되면 같은  inline 아규먼트를 쓰는 모든 input() 콜들이 한 라인으로 조인됩니다. 각 input() 콜들의 title 아규먼트는 그 필드의 레전드를 디파인합니다. input() 콜에 아무런 title 아규먼트가 없으면 그 필드에 대한 레전드를 쓸 수 없게 됩니다. inline 을 써서 합친 인풋들이 한 라인에 들어가지 못하면 다음 줄로 넘어갑니다.

새로운 파라미터 설명은 파인 레퍼런스 매뉴얼의 input() 에 나옵니다.

파인 업데이트에 대한 모든 것은 당사 유저 매뉴얼 릴리즈 노트에 나와 있습니다.

이번 피처가 도움이 되길 바랍니다. 여러분의 피드백을 보내 주시기 바랍니다.

Look first Then leap

트레이딩뷰는 여러분을 위해 만들어졌으므로 트레이딩뷰의 멋진 기능을 최대한 활용하세요
차트 시작