"NK-Box"의 옵션으로 사용하는 지표입니다. "NK-Box"와 완전히 동일한 범위에 선을 그릴 수 있습니다.
"SVWAP"는 "Static VWAP"의 약자로, 필자 고유의 명칭입니다. 이전 기간 VWAP의 최종 확정값을 현재 기간에 선으로 그린 것입니다. (정적=Static)
단기와 장기 2개의 SVWAP으로 배경을 만들 수 있습니다.
※거래량을 가져올 수 있는 종목에만 적용할 수 있습니다.
⇩ 위가 "Hist", 아래가 "Current"
"SVWAP"는 "Static VWAP"의 약자로, 필자 고유의 명칭입니다. 이전 기간 VWAP의 최종 확정값을 현재 기간에 선으로 그린 것입니다. (정적=Static)
단기와 장기 2개의 SVWAP으로 배경을 만들 수 있습니다.
※거래량을 가져올 수 있는 종목에만 적용할 수 있습니다.
출처: TradingView
⇩ 위가 "Hist", 아래가 "Current"
[NOTICE & LICENSE]
・학습 및 정보 제공만을 목적으로 하며, 투자 조언이 아닙니다. 툴 사용으로 인해 발생한 경제적 손실에 대해 일절 책임을 지지 않습니다.
・Pine Script v6에서 동작을 확인했습니다. 향후 TradingView의 사양 변경에 따른 업데이트를 보장하지 않으며, 개별적인 설치 지원이나 수정 요청은 일절 받지 않습니다 (있는 그대로(As-is) 제공).
・MIT 라이선스가 적용됩니다.
// SPDX-FileCopyrightText: 2026 NK-report https://www.nk-report.com/
// SPDX-License-Identifier: MIT
//
// Disclaimer: This script is for educational purposes only and does not constitute investment advice.
//@version=6
// ※計算負荷がゼロに等しいため過去表示の制限を撤廃。TVのガベージコレクションに任せるためmax_lines_count=500を設定
indicator("NK-box_option2_SVWAP & Zone (History)", shorttitle="NK-opt2 SVWAP (Hist)", overlay=true, max_lines_count=500)
// ==============================================================================
// 【01】 免責・ライセンス
// ==============================================================================
//
// 지표를 무료로 공개하고 있습니다: https://www.nk-report.com/p/kr-tradingview.html
//
// 면책 조항: 본 스크립트는 학습 및 정보 제공만을 목적으로 하며, 투자 조언이 아닙니다.
//
// 1. 본 코드는 2026년 기준 Pine Script v6에서 동작 확인을 마쳤습니다.
// 향후 사양 변경으로 인한 오류 등에 대해 개별적인 지원이나 수정은 제공하지 않습니다.
// 2. 본 스크립트는 일반적인 계산 로직을 바탕으로 LLM을 활용하여 독자적으로 작성된 것입니다.
// MIT 라이선스를 따릅니다.
// ------------------------------------------------------------------------------
// MIT License
//
// Copyright 2026 NK-report https://www.nk-report.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ==============================================================================
// 【02】 UI設定と言語
// ==============================================================================
const string GRP_GENERAL = "▼ 기간 설정 (듀얼 타임프레임)"
const string GRP_OFFSET = "▼ 그리기 위치 미세 조정 (오프셋)"
const string GRP_LINES = "▼ SVWAP 라인 & 영역 설정"
const string LBL_BASE_TF = "기준 기간 1 (단기 SVWAP)"
const string TT_BASE_TF = "※ NK-box 본체와 동일한 수치를 지정해 주세요.\n박스 너비와 단기 SVWAP가 자동으로 동기화됩니다."
const string LBL_MACRO_TF = "기준 기간 2 (장기 SVWAP)"
const string TT_MACRO_TF = "※ 기준 기간 1보다 긴 기간을 지정해 주세요.\n※ 더 짧게 설정된 경우 시스템이 자동으로 기준 기간 1과 동일하게 보정합니다."
const string OPT_TF_D = "1일"
const string OPT_TF_W = "1주"
const string OPT_TF_1M = "1개월"
const string OPT_TF_3M = "3개월"
const string OPT_TF_12M = "12개월"
const string LBL_OFS_L = "좌측 오프셋 조정 (봉 개수)"
const string LBL_OFS_R = "우측 오프셋 조정 (봉 개수)"
const string TT_OFS = "음수는 좌측으로, 양수는 우측으로 이동합니다.\n※ NK-box 본체와 동일한 수치를 지정해 주세요."
const string OPT_STY_S = "실선"
const string OPT_STY_D = "파선"
const string OPT_STY_DT = "점선"
// 期間設定 (デフォルト: 短期3ヶ月 / 長期12ヶ月)
i_base_tf_str = input.string(OPT_TF_3M, title=LBL_BASE_TF, options=[OPT_TF_D, OPT_TF_W, OPT_TF_1M, OPT_TF_3M, OPT_TF_12M], group=GRP_GENERAL, tooltip=TT_BASE_TF)
i_macro_tf_str = input.string(OPT_TF_12M, title=LBL_MACRO_TF, options=[OPT_TF_D, OPT_TF_W, OPT_TF_1M, OPT_TF_3M, OPT_TF_12M], group=GRP_GENERAL, tooltip=TT_MACRO_TF)
// オフセット設定
i_offset_left = input.int(-1, title=LBL_OFS_L, group=GRP_OFFSET, tooltip=TT_OFS)
i_offset_right = input.int(0, title=LBL_OFS_R, group=GRP_OFFSET, tooltip=TT_OFS)
// 短期 SVWAP
i_show_b = input.bool(true, title="단기 SVWAP 표시", inline="b", group=GRP_LINES)
i_col_b = input.color(color.green, title="", inline="b", group=GRP_LINES)
i_wid_b = input.int(2, title="", minval=1, maxval=5, inline="b", group=GRP_LINES)
i_sty_b = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], inline="b", group=GRP_LINES)
// 長期 SVWAP
i_show_a = input.bool(true, title="장기 SVWAP 표시", inline="a", group=GRP_LINES)
i_col_a = input.color(color.blue, title="", inline="a", group=GRP_LINES)
i_wid_a = input.int(2, title="", minval=1, maxval=5, inline="a", group=GRP_LINES)
i_sty_a = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], inline="a", group=GRP_LINES)
// ゾーン設定 (紫の5%不透明度 = transp 95)
i_show_zone = input.bool(true, title="영역 표시 (단기와 장기 사이)", group=GRP_LINES, inline="zone")
i_col_zone = input.color(color.new(color.purple, 95), title="", group=GRP_LINES, inline="zone")
// ==============================================================================
// 【03】 全コード共通仕様(時間・安全装置処理)
// ==============================================================================
// TF文字列を内部インデックスに変換する関数 (安全装置の比較用)
f_tf_idx(tf_str) =>
tf_str == OPT_TF_D ? 1 : tf_str == OPT_TF_W ? 2 : tf_str == OPT_TF_1M ? 3 : tf_str == OPT_TF_3M ? 4 : tf_str == OPT_TF_12M ? 5 : 0
// ユーザーが長期を短期より短く設定した場合、強制的に短期と同じにする安全装置
int idx_base = f_tf_idx(i_base_tf_str)
int idx_macro = f_tf_idx(i_macro_tf_str)
string safe_macro_str = idx_macro < idx_base ? i_base_tf_str : i_macro_tf_str
// Pine内部識別子への変換
string req_base = switch i_base_tf_str
OPT_TF_D => "1D"
OPT_TF_W => "1W"
OPT_TF_1M => "1M"
OPT_TF_3M => "3M"
OPT_TF_12M => "12M"
string req_macro = switch safe_macro_str
OPT_TF_D => "1D"
OPT_TF_W => "1W"
OPT_TF_1M => "1M"
OPT_TF_3M => "3M"
OPT_TF_12M => "12M"
bool is_new_base = timeframe.change(req_base) or barstate.isfirst
bool is_new_macro = timeframe.change(req_macro) or barstate.isfirst
f_get_style(sty_str) =>
sty_str == OPT_STY_S ? line.style_solid : sty_str == OPT_STY_D ? line.style_dashed : line.style_dotted
// ==============================================================================
// 【05】 このコード固有の計算仕様 (Specific Indicator Logic)
// ==============================================================================
// 短期SVWAP [B] 系統
var float cum_pv_b = 0.0
var float cum_v_b = 0.0
var float prev_calc_vwap_b = na
// 長期SVWAP [A] 系統
var float cum_pv_a = 0.0
var float cum_v_a = 0.0
var float prev_calc_vwap_a = na
// 現在の投影期間(箱)に描画するための保持変数
var float proj_vwap_b = na
var float proj_vwap_a = na
var int start_bar = na
bool do_draw = false
int draw_start = na
int draw_end = na
float draw_b = na
float draw_a = na
// ① 裏側の計算:期間が切り替わったら、過去の累積からVWAPを確定させリセットする
if is_new_macro
prev_calc_vwap_a := cum_v_a > 0 ? cum_pv_a / cum_v_a : na
cum_pv_a := 0.0
cum_v_a := 0.0
if is_new_base
prev_calc_vwap_b := cum_v_b > 0 ? cum_pv_b / cum_v_b : na
cum_pv_b := 0.0
cum_v_b := 0.0
// ② 表側の投影:ベース期間(箱の幅)が切り替わるタイミングで、AとB両方の座標をセット
if not na(start_bar)
do_draw := true
draw_start := math.max(0, start_bar + i_offset_left)
draw_end := math.max(0, bar_index[1] + i_offset_right)
draw_b := proj_vwap_b
draw_a := proj_vwap_a
start_bar := bar_index
proj_vwap_b := prev_calc_vwap_b
proj_vwap_a := prev_calc_vwap_a
// ③ 毎ティックの出来高加重累積 (超軽量ストック)
float typ = hlc3
float vol = volume
if not na(typ) and not na(vol)
float pv = typ * vol
cum_pv_b += pv
cum_v_b += vol
cum_pv_a += pv
cum_v_a += vol
// ==============================================================================
// 【06】 描画と出力 (Rendering & Outputs)
// ==============================================================================
if do_draw
// 配列管理を完全撤廃し、TV標準のガベージコレクションに丸投げしてスクロールズレを防止
bool req_line_b = i_show_b or i_show_zone
bool req_line_a = i_show_a or i_show_zone
line l_b = req_line_b ? line.new(draw_start, draw_b, draw_end, draw_b, color=i_show_b ? i_col_b : na, width=i_wid_b, style=f_get_style(i_sty_b)) : na
line l_a = req_line_a ? line.new(draw_start, draw_a, draw_end, draw_a, color=i_show_a ? i_col_a : na, width=i_wid_a, style=f_get_style(i_sty_a)) : na
// ゾーン塗りつぶし
if i_show_zone and not na(l_b) and not na(l_a)
linefill.new(l_b, l_a, i_col_zone)
// データウィンドウ出力
plot(proj_vwap_b, title="단기 SVWAP", color=i_col_b, display=display.data_window, editable=false)
plot(proj_vwap_a, title="장기 SVWAP", color=i_col_a, display=display.data_window, editable=false)
// SPDX-FileCopyrightText: 2026 NK-report https://www.nk-report.com/
// SPDX-License-Identifier: MIT
//
// Disclaimer: This script is for educational purposes only and does not constitute investment advice.
//@version=6
indicator("NK-box_option2_SVWAP & Zone (Current)", shorttitle="NK-opt2 SVWAP (Curr)", overlay=true)
// ==============================================================================
// 【01】 免責・ライセンス
// ==============================================================================
//
// 지표를 무료로 공개하고 있습니다: https://www.nk-report.com/p/kr-tradingview.html
//
// 면책 조항: 본 스크립트는 학습 및 정보 제공만을 목적으로 하며, 투자 조언이 아닙니다.
//
// 1. 본 코드는 2026년 기준 Pine Script v6에서 동작 확인을 마쳤습니다.
// 향후 사양 변경으로 인한 오류 등에 대해 개별적인 지원이나 수정은 제공하지 않습니다.
// 2. 본 스크립트는 일반적인 계산 로직을 바탕으로 LLM을 활용하여 독자적으로 작성된 것입니다.
// MIT 라이선스를 따릅니다.
// ------------------------------------------------------------------------------
// MIT License
//
// Copyright 2026 NK-report https://www.nk-report.com/
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of
// this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
// of the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ==============================================================================
// 【02】 UI設定と言語
// ==============================================================================
const string GRP_GENERAL = "▼ 기간 설정 (듀얼 타임프레임)"
const string GRP_OFFSET = "▼ 그리기 위치 미세 조정 (오프셋)"
const string GRP_LINES = "▼ SVWAP 라인 & 영역 설정"
const string LBL_BASE_TF = "기준 기간 1 (단기 SVWAP)"
const string TT_BASE_TF = "※ NK-box 본체와 동일한 수치를 지정해 주세요.\n박스 너비와 단기 SVWAP가 자동으로 동기화됩니다."
const string LBL_MACRO_TF = "기준 기간 2 (장기 SVWAP)"
const string TT_MACRO_TF = "※ 기준 기간 1보다 긴 기간을 지정해 주세요.\n※ 더 짧게 설정된 경우 시스템이 자동으로 기준 기간 1과 동일하게 보정합니다."
const string OPT_TF_D = "1일"
const string OPT_TF_W = "1주"
const string OPT_TF_1M = "1개월"
const string OPT_TF_3M = "3개월"
const string OPT_TF_12M = "12개월"
const string LBL_OFS_L = "좌측 오프셋 조정 (봉 개수 환산)"
const string LBL_OFS_R = "우측 오프셋 조정 (봉 개수 환산)"
const string TT_OFS = "음수는 좌측으로, 양수는 우측으로 이동합니다.\n※ Current 버전에서는 시간 계산(밀리초)을 통한 대략적인 이동입니다.\n※ NK-box 본체와 동일한 수치를 지정해 주세요."
const string OPT_STY_S = "실선"
const string OPT_STY_D = "파선"
const string OPT_STY_DT = "점선"
// 期間設定 (デフォルト: 短期3ヶ月 / 長期12ヶ月)
i_base_tf_str = input.string(OPT_TF_3M, title=LBL_BASE_TF, options=[OPT_TF_D, OPT_TF_W, OPT_TF_1M, OPT_TF_3M, OPT_TF_12M], group=GRP_GENERAL, tooltip=TT_BASE_TF)
i_macro_tf_str = input.string(OPT_TF_12M, title=LBL_MACRO_TF, options=[OPT_TF_D, OPT_TF_W, OPT_TF_1M, OPT_TF_3M, OPT_TF_12M], group=GRP_GENERAL, tooltip=TT_MACRO_TF)
i_offset_left = input.int(-1, title=LBL_OFS_L, group=GRP_OFFSET, tooltip=TT_OFS)
i_offset_right = input.int(0, title=LBL_OFS_R, group=GRP_OFFSET, tooltip=TT_OFS)
// 短期 SVWAP
i_show_b = input.bool(true, title="단기 SVWAP 표시", inline="b", group=GRP_LINES)
i_col_b = input.color(color.green, title="", inline="b", group=GRP_LINES)
i_wid_b = input.int(2, title="", minval=1, maxval=5, inline="b", group=GRP_LINES)
i_sty_b = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], inline="b", group=GRP_LINES)
// 長期 SVWAP
i_show_a = input.bool(true, title="장기 SVWAP 표시", inline="a", group=GRP_LINES)
i_col_a = input.color(color.blue, title="", inline="a", group=GRP_LINES)
i_wid_a = input.int(2, title="", minval=1, maxval=5, inline="a", group=GRP_LINES)
i_sty_a = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], inline="a", group=GRP_LINES)
// ゾーン設定 (紫の5%不透明度 = transp 95)
i_show_zone = input.bool(true, title="영역 표시 (단기와 장기 사이)", group=GRP_LINES, inline="zone")
i_col_zone = input.color(color.new(color.purple, 95), title="", group=GRP_LINES, inline="zone")
// ==============================================================================
// 【03】 全コード共通仕様(時間・安全装置処理)
// ==============================================================================
const int MS_PER_SEC = 1000
// 強制ガードロジック: インデックス化して判定
f_tf_idx(tf_str) =>
tf_str == OPT_TF_D ? 1 : tf_str == OPT_TF_W ? 2 : tf_str == OPT_TF_1M ? 3 : tf_str == OPT_TF_3M ? 4 : tf_str == OPT_TF_12M ? 5 : 0
// ユーザーが長期を短期より短く設定した場合、強制的に短期と同じにする安全装置
int idx_base = f_tf_idx(i_base_tf_str)
int idx_macro = f_tf_idx(i_macro_tf_str)
string safe_macro_str = idx_macro < idx_base ? i_base_tf_str : i_macro_tf_str
// Pine内部識別子への変換
string req_base = switch i_base_tf_str
OPT_TF_D => "1D"
OPT_TF_W => "1W"
OPT_TF_1M => "1M"
OPT_TF_3M => "3M"
OPT_TF_12M => "12M"
string req_macro = switch safe_macro_str
OPT_TF_D => "1D"
OPT_TF_W => "1W"
OPT_TF_1M => "1M"
OPT_TF_3M => "3M"
OPT_TF_12M => "12M"
bool is_new_base = timeframe.change(req_base) or barstate.isfirst
bool is_new_macro = timeframe.change(req_macro) or barstate.isfirst
f_get_style(sty_str) =>
sty_str == OPT_STY_S ? line.style_solid : sty_str == OPT_STY_D ? line.style_dashed : line.style_dotted
// ------------------------------------------------------------------------------
// オブジェクトの事前生成 (Current版専用インフラ)
// ------------------------------------------------------------------------------
var line l_b = line.new(na, na, na, na, xloc=xloc.bar_time, width=i_wid_b, style=f_get_style(i_sty_b), color=i_show_b ? i_col_b : na)
var line l_a = line.new(na, na, na, na, xloc=xloc.bar_time, width=i_wid_a, style=f_get_style(i_sty_a), color=i_show_a ? i_col_a : na)
if barstate.isfirst
if i_show_zone
linefill.new(l_b, l_a, i_col_zone)
// ==============================================================================
// 【05】 このコード固有の計算仕様 (Specific Indicator Logic)
// ==============================================================================
// 短期 SVWAP [B] 系統
var float cum_pv_b = 0.0
var float cum_v_b = 0.0
var float prev_calc_vwap_b = na
// 長期 SVWAP [A] 系統
var float cum_pv_a = 0.0
var float cum_v_a = 0.0
var float prev_calc_vwap_a = na
// 投影空間のX軸変数とY軸値
var int start_t = na
var int end_t = na
var float proj_vwap_b = na
var float proj_vwap_a = na
bool do_draw = false
int draw_start = na
int draw_end = na
// ① 裏側の計算:期間が確定した瞬間にSVWAPをロック
if is_new_macro
prev_calc_vwap_a := cum_v_a > 0 ? cum_pv_a / cum_v_a : na
cum_pv_a := 0.0
cum_v_a := 0.0
if is_new_base
prev_calc_vwap_b := cum_v_b > 0 ? cum_pv_b / cum_v_b : na
cum_pv_b := 0.0
cum_v_b := 0.0
// ② 表側の投影:ベース期間(箱の幅)が切り替わるタイミングで未来時間をセット
proj_vwap_b := prev_calc_vwap_b
proj_vwap_a := prev_calc_vwap_a
start_t := time
int tc = time_close(req_base)
end_t := not na(tc) ? tc : time + timeframe.in_seconds(req_base) * MS_PER_SEC
// ③ 毎ティックの出来高加重累積
float typ = hlc3
float vol = volume
if not na(typ) and not na(vol)
float pv = typ * vol
cum_pv_b += pv
cum_v_b += vol
cum_pv_a += pv
cum_v_a += vol
// 描画フラグの生成 (現在の時間軸空間へ投影)
if (not na(proj_vwap_b) or not na(proj_vwap_a)) and not na(start_t) and not na(end_t)
do_draw := true
int bar_ms = timeframe.in_seconds(timeframe.period) * MS_PER_SEC
draw_start := start_t + (i_offset_left * bar_ms)
draw_end := end_t + (i_offset_right * bar_ms)
// ==============================================================================
// 【06】 描画と出力 (Rendering & Outputs)
// ==============================================================================
if do_draw
bool req_line_b = i_show_b or i_show_zone
bool req_line_a = i_show_a or i_show_zone
if req_line_b
line.set_xy1(l_b, draw_start, proj_vwap_b)
line.set_xy2(l_b, draw_end, proj_vwap_b)
else
line.set_xy1(l_b, na, na)
line.set_xy2(l_b, na, na)
if req_line_a
line.set_xy1(l_a, draw_start, proj_vwap_a)
line.set_xy2(l_a, draw_end, proj_vwap_a)
else
line.set_xy1(l_a, na, na)
line.set_xy2(l_a, na, na)
// データウィンドウ出力
plot(proj_vwap_b, title="단기 SVWAP", color=i_col_b, display=display.data_window, editable=false)
plot(proj_vwap_a, title="장기 SVWAP", color=i_col_a, display=display.data_window, editable=false)
* 원하는 색상으로 설정한 후, 설정 탭에서 '기본값으로 저장'을 눌러주세요.
* 새로 만들기 -> 지표 -> 붙여넣기 순서로 진행하지 않으면 정상적으로 표시되지 않을 수 있습니다.
