This is an optional indicator for "NK-Box". It can draw lines in the exact same range as "NK-Box".
"SVWAP" stands for "Static VWAP", an original term coined by the author. It draws the final confirmed VWAP value of the previous period as a fixed line in the current period (Static).
You can create a background zone using two SVWAPs (short-term and long-term).
Note: This can only be applied to tickers where volume data is available.
⇩ "Hist" (Top), "Current" (Bottom)
"SVWAP" stands for "Static VWAP", an original term coined by the author. It draws the final confirmed VWAP value of the previous period as a fixed line in the current period (Static).
You can create a background zone using two SVWAPs (short-term and long-term).
Note: This can only be applied to tickers where volume data is available.
Source: TradingView
⇩ "Hist" (Top), "Current" (Bottom)
[NOTICE & LICENSE]
・For educational and informational purposes only; does not constitute investment advice. We assume no liability for any economic loss arising from the use of this tool.
・Tested on Pine Script v6. Provided "As-Is" with no guarantee of updates in response to future TradingView specification changes. We do not provide individual installation support or accept modification requests.
・Governed by the MIT License.
// 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】 免責・ライセンス
// ==============================================================================
//
// Indicator is published for free: https://www.nk-report.com/p/tradingview-code.html
//
// Disclaimer: This script is for educational and informational purposes only and does not constitute investment advice.
//
// 1. This code has been tested with Pine Script v6 as of 2026.
// We do not provide individual support or modifications for any issues caused by future specification changes.
// 2. This script was independently created using an LLM, based on general calculation logic.
// It is distributed under the MIT License.
// ------------------------------------------------------------------------------
// 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 = "▼ Timeframe Settings (Dual Timeframe)"
const string GRP_OFFSET = "▼ Position Adjustment (Offset)"
const string GRP_LINES = "▼ SVWAP Line & Zone Settings"
const string LBL_BASE_TF = "Base Timeframe 1 (Short-term SVWAP)"
const string TT_BASE_TF = "* Please specify the same value as the main NK-box.\nThe box width and short-term SVWAP will be synchronized automatically."
const string LBL_MACRO_TF = "Base Timeframe 2 (Long-term SVWAP)"
const string TT_MACRO_TF = "* Please specify a timeframe longer than Base Timeframe 1.\n* If set shorter, the system will automatically adjust it to match Base Timeframe 1."
const string OPT_TF_D = "1 Day"
const string OPT_TF_W = "1 Week"
const string OPT_TF_1M = "1 Month"
const string OPT_TF_3M = "3 Months"
const string OPT_TF_12M = "12 Months"
const string LBL_OFS_L = "Left Offset (Bars)"
const string LBL_OFS_R = "Right Offset (Bars)"
const string TT_OFS = "Negative values move left, positive values move right.\n* Please specify the same value as the main NK-box."
const string OPT_STY_S = "Solid"
const string OPT_STY_D = "Dashed"
const string OPT_STY_DT = "Dotted"
// 期間設定 (デフォルト: 短期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="Show Short-term 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="Show Long-term 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="Show Zone (Between Short & Long)", 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="Short-term SVWAP", color=i_col_b, display=display.data_window, editable=false)
plot(proj_vwap_a, title="Long-term 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】 免責・ライセンス
// ==============================================================================
//
// Indicator is published for free: https://www.nk-report.com/p/tradingview-code.html
//
// Disclaimer: This script is for educational and informational purposes only and does not constitute investment advice.
//
// 1. This code has been tested with Pine Script v6 as of 2026.
// We do not provide individual support or modifications for any issues caused by future specification changes.
// 2. This script was independently created using an LLM, based on general calculation logic.
// It is distributed under the MIT License.
// ------------------------------------------------------------------------------
// 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 = "▼ Timeframe Settings (Dual Timeframe)"
const string GRP_OFFSET = "▼ Position Adjustment (Offset)"
const string GRP_LINES = "▼ SVWAP Line & Zone Settings"
const string LBL_BASE_TF = "Base Timeframe 1 (Short-term SVWAP)"
const string TT_BASE_TF = "* Please specify the same value as the main NK-box.\nThe box width and short-term SVWAP will be synchronized automatically."
const string LBL_MACRO_TF = "Base Timeframe 2 (Long-term SVWAP)"
const string TT_MACRO_TF = "* Please specify a timeframe longer than Base Timeframe 1.\n* If set shorter, the system will automatically adjust it to match Base Timeframe 1."
const string OPT_TF_D = "1 Day"
const string OPT_TF_W = "1 Week"
const string OPT_TF_1M = "1 Month"
const string OPT_TF_3M = "3 Months"
const string OPT_TF_12M = "12 Months"
const string LBL_OFS_L = "Left Offset (in Bars)"
const string LBL_OFS_R = "Right Offset (in Bars)"
const string TT_OFS = "Negative values move left, positive values move right.\n* In the Current version, this is an approximate movement calculated by time (milliseconds).\n* Please specify the same value as the main NK-box."
const string OPT_STY_S = "Solid"
const string OPT_STY_D = "Dashed"
const string OPT_STY_DT = "Dotted"
// 期間設定 (デフォルト: 短期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="Show Short-term 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="Show Long-term 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="Show Zone (Between Short & Long)", 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="Short-term SVWAP", color=i_col_b, display=display.data_window, editable=false)
plot(proj_vwap_a, title="Long-term SVWAP", color=i_col_a, display=display.data_window, editable=false)
* After setting your preferred colors, please click "Save as default" in the settings tab.
* The indicator may not display correctly unless you follow the steps: Create New -> Indicator -> Paste.
