# 2-2. option1_Zone & Gap
"NK-Box"にオプションとして使用するインジケーターです。"NK-Box"と全く同じ範囲にラインを描画することができます。
NK-Boxではミッドラインとの比較でしたが、このインジケーターではミッドライン以外の計算ライン同士でそれらの背景を設定することができます。
加えて、前期間からのギャップを背景で表示させることもできます。
![[▢TradingViewコード-13. option1_Zone & Gap.webp]]
出典: TradingView
---
> [!example] NOTICE(注意)
> - 学習および情報提供のみを目的としており、投資助言ではありません。
> - ツールを使用したことによる経済的損失について、一切の責任を負いません。
> - Pine Script v6 で動作確認しています。将来のTradingView側の仕様変更に対するアップデート保証や、個別の導入サポート・改修依頼は受け付けません(現状有姿での提供)。
> - [MIT License](https://opensource.org/licenses/MIT) に則っています。
> [!quote]- 導入の流れ
>
> - 「Pineを開く」→「スクリプトのメニューを開き、新規作成を選択」→「インジケーターを選択」→「全選択で既存のコードを削除してからペーストする」の順序で行ってください。
> ※この手順で行わないと正しく認識されないことがあります。
> - 好みの配色に設定後、パラメータータブの「デフォルトを保存」を押してください。
---
> **Copy area**
- Hist
> [!quote]- コードを展開する
> ````pinescript
> // 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
> // ※Gapをボックスで描画するため、max_boxes_count=500 を追加しています
> indicator("NK-box_option1_Zone & Gap (History)", shorttitle="NK-opt1 Z&G (Hist)", overlay=true, max_boxes_count=500, max_lines_count=500)
>
> // ==============================================================================
> // 【01】 免責・ライセンス
> // ==============================================================================
> // 独自視点の「解説/考察」記事を公開している個人サイトです。サイト内のTradingViewコードは無料でコピーできます。: https://www.nk-report.com/
> //
> // 免責事項: 本スクリプトは学習および情報提供のみを目的としており、投資助言ではありません。
> //
> // 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設定と言語
> // ==============================================================================
> // 1. 言語辞書の定義(テキストの定数化)
> // ※外国語版を作成する際は、このブロックの「右辺のテキスト」のみを翻訳してください
>
> const string GRP_GENERAL = "▼ 基本設定"
> const string GRP_OFFSET = "▼ 描画位置の微調整 (オフセット)"
> const string GRP_OPTION = "▼ カスタムゾーン設定"
>
> const string LBL_TF = "基準期間"
> const string TT_TF = "※NK-box本体と同じ基準期間を指定してください。"
>
> 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 LBL_LINE_A = "ライン A 基準"
> const string LBL_LINE_B = "ライン B 基準"
> const string LBL_SHOW = "線の表示"
> const string LBL_ZONE = "背景塗りつぶし (ゾーン)"
> const string LBL_GAP = "Gap (窓) ハイライト"
>
> // 分析ラインの選択肢
> const string OPT_MID = "ミッドライン"
> const string OPT_OPEN = "始値"
> const string OPT_CLOSE = "終値"
> const string OPT_WCL = "加重終値"
> const string OPT_PIVOT = "ピボット"
> const string OPT_MEDIAN = "実体中央値"
> const string OPT_TWAP = "TWAP"
>
> const string OPT_STY_S = "実線"
> const string OPT_STY_D = "破線"
> const string OPT_STY_DT = "点線"
>
> // データウィンドウ用の表示名
> const string LBL_DATA_A = "オプション ラインA"
> const string LBL_DATA_B = "オプション ラインB"
>
> // 2. UI(ユーザー入力画面)の構築
> // ※言語辞書で定義した定数を呼び出してUIを構築します
> i_tf_str = input.string(OPT_TF_1M, title=LBL_TF, options=[OPT_TF_D, OPT_TF_W, OPT_TF_1M, OPT_TF_3M, OPT_TF_12M], group=GRP_GENERAL, tooltip=TT_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)
>
> // カスタムゾーン設定(ラインA)
> i_type_a = input.string(OPT_TWAP, title=LBL_LINE_A, options=[OPT_MID, OPT_OPEN, OPT_CLOSE, OPT_WCL, OPT_PIVOT, OPT_MEDIAN, OPT_TWAP], group=GRP_OPTION)
> i_show_a = input.bool(true, title=LBL_SHOW, group=GRP_OPTION, inline="linea")
> i_col_a = input.color(color.orange, title="", group=GRP_OPTION, inline="linea")
> i_wid_a = input.int(2, title="", minval=1, maxval=5, group=GRP_OPTION, inline="linea")
> i_sty_a = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], group=GRP_OPTION, inline="linea")
>
> // カスタムゾーン設定(ラインB)
> i_type_b = input.string(OPT_PIVOT, title=LBL_LINE_B, options=[OPT_MID, OPT_OPEN, OPT_CLOSE, OPT_WCL, OPT_PIVOT, OPT_MEDIAN, OPT_TWAP], group=GRP_OPTION)
> i_show_b = input.bool(true, title=LBL_SHOW, group=GRP_OPTION, inline="lineb")
> i_col_b = input.color(color.blue, title="", group=GRP_OPTION, inline="lineb")
> i_wid_b = input.int(2, title="", minval=1, maxval=5, group=GRP_OPTION, inline="lineb")
> i_sty_b = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], group=GRP_OPTION, inline="lineb")
>
> // ゾーン塗りつぶし設定
> i_show_zone = input.bool(true, title=LBL_ZONE, group=GRP_OPTION, inline="zone")
> i_col_zone = input.color(color.new(color.gray, 85), title="", group=GRP_OPTION, inline="zone")
>
> // Gap (窓) 設定
> i_show_gap = input.bool(true, title=LBL_GAP, group=GRP_OPTION, inline="gap")
> i_col_gap_u = input.color(color.new(color.teal, 80), title="上窓", group=GRP_OPTION, inline="gap")
> i_col_gap_d = input.color(color.new(color.red, 80), title="下窓", group=GRP_OPTION, inline="gap")
>
>
> // ==============================================================================
> // 【03】 全コード共通仕様(時間・インフラ処理)
> // ==============================================================================
> // UIで選択された定数をPine内部のシステム識別子に変換
> string req_tf = switch i_tf_str
> OPT_TF_D => "1D"
> OPT_TF_W => "1W"
> OPT_TF_1M => "1M"
> OPT_TF_3M => "3M"
> OPT_TF_12M => "12M"
>
>
> // ==============================================================================
> // 【04】 各カテゴリ共通仕様 (描画インフラと判定ロジック)
> // ==============================================================================
> bool is_new_period = timeframe.change(req_tf) 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
>
> // プルダウンの選択肢に応じて純粋な数値を計算する専用関数
> f_get_val(type_str, _o, _h, _l, _c) =>
> float v = switch type_str
> OPT_MID => (_h + _l) / 2.0
> OPT_OPEN => _o
> OPT_CLOSE => _c
> OPT_WCL => (_h + _l + _c * 2.0) / 4.0
> OPT_PIVOT => (_h + _l + _c) / 3.0
> OPT_MEDIAN => (_o + _c) / 2.0
> OPT_TWAP => (_o + _h + _l + _c) / 4.0
> => na
> v
>
>
> // ==============================================================================
> // 【05】 このコード固有の計算仕様 (Specific Indicator Logic)
> // ==============================================================================
> var float curr_o = na
> var float curr_h = na
> var float curr_l = na
> var float prev_o = na
> var float prev_h = na
> var float prev_l = na
> var float prev_c = na
> var int start_bar = na
>
> // --- 描画エンジンへ引き渡すためのスナップショット変数(MVC分離用) ---
> bool do_draw = false
> int draw_start = na
> int draw_end = na
> float draw_o = na
> float draw_h = na
> float draw_l = na
> float draw_c = na
> float draw_gap_c = na
> float draw_gap_o = na
>
> if is_new_period
> // ① 描画キューの生成:計算用の変数が新しい期間のもので上書きされる前に、描画用の確定値を退避させます。
> if not na(prev_o) and 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_o := prev_o
> draw_h := prev_h
> draw_l := prev_l
> draw_c := prev_c
> draw_gap_c := prev_c
> draw_gap_o := curr_o
>
> // ② 次の期間へのバケツリレー
> prev_o := curr_o
> prev_h := curr_h
> prev_l := curr_l
> prev_c := close[1]
> curr_o := open
> curr_h := high
> curr_l := low
> start_bar := bar_index
> else
> curr_h := math.max(curr_h, high)
> curr_l := math.min(curr_l, low)
>
>
> // ==============================================================================
> // 【06】 描画と出力 (Rendering & Outputs)
> // ==============================================================================
> // 1. チャートへの視覚的出力(スタンプ描画)
> if do_draw
> // 【05】で退避したスナップショットを用いて、選択された2つの数値を計算します
> float val_a = f_get_val(i_type_a, draw_o, draw_h, draw_l, draw_c)
> float val_b = f_get_val(i_type_b, draw_o, draw_h, draw_l, draw_c)
>
> // ラインの描画(線の表示がOFFでも、背景表示がONなら「見えない透明の線」を引いて背景のアンカーにします)
> bool draw_line_a = i_show_a or i_show_zone
> bool draw_line_b = i_show_b or i_show_zone
>
> line l_a = draw_line_a ? line.new(draw_start, val_a, draw_end, val_a, color=i_show_a ? i_col_a : na, width=i_wid_a, style=f_get_style(i_sty_a)) : na
> line l_b = draw_line_b ? line.new(draw_start, val_b, draw_end, val_b, color=i_show_b ? i_col_b : na, width=i_wid_b, style=f_get_style(i_sty_b)) : na
>
> // 背景塗りつぶし
> if i_show_zone and not na(l_a) and not na(l_b)
> linefill.new(l_a, l_b, i_col_zone)
>
> // Gap (窓) の描画
> if i_show_gap and not na(draw_gap_c) and not na(draw_gap_o) and (draw_gap_c != draw_gap_o)
> color gap_col = draw_gap_o > draw_gap_c ? i_col_gap_u : i_col_gap_d
> float gap_top = math.max(draw_gap_c, draw_gap_o)
> float gap_bot = math.min(draw_gap_c, draw_gap_o)
> box.new(draw_start, gap_top, draw_end, gap_bot, border_color=na, bgcolor=gap_col)
>
> // 2. データウィンドウへの出力
> // 選択されたラインの値だけを出力し、本体のデータウィンドウを圧迫しないように設計しています
> float out_a = f_get_val(i_type_a, prev_o, prev_h, prev_l, prev_c)
> float out_b = f_get_val(i_type_b, prev_o, prev_h, prev_l, prev_c)
>
> plot(out_a, title=LBL_DATA_A, color=i_col_a, display=display.data_window, editable=false)
> plot(out_b, title=LBL_DATA_B, color=i_col_b, display=display.data_window, editable=false)
> ````
- Current
> [!quote]- コードを展開する
> ````pinescript
> // 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_option1_Zone & Gap (Current)", shorttitle="NK-opt1 Z&G (Curr)", overlay=true)
>
> // ==============================================================================
> // 【01】 免責・ライセンス
> // ==============================================================================
> // 独自視点の「解説/考察」記事を公開している個人サイトです。サイト内のTradingViewコードは無料でコピーできます。: https://www.nk-report.com/
> //
> // 免責事項: 本スクリプトは学習および情報提供のみを目的としており、投資助言ではありません。
> //
> // 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設定と言語
> // ==============================================================================
> // 1. 言語辞書の定義(テキストの定数化)
> // ※外国語版を作成する際は、このブロックの「右辺のテキスト」のみを翻訳してください
>
> const string GRP_GENERAL = "▼ 基本設定"
> const string GRP_OFFSET = "▼ 描画位置の微調整 (オフセット)"
> const string GRP_OPTION = "▼ カスタムゾーン設定"
>
> const string LBL_TF = "基準期間"
> const string TT_TF = "※NK-box本体と同じ基準期間を指定してください。"
>
> 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 LBL_LINE_A = "ライン A 基準"
> const string LBL_LINE_B = "ライン B 基準"
> const string LBL_SHOW = "線の表示"
> const string LBL_ZONE = "背景塗りつぶし (ゾーン)"
> const string LBL_GAP = "Gap (窓) ハイライト"
>
> // 分析ラインの選択肢
> const string OPT_MID = "ミッドライン"
> const string OPT_OPEN = "始値"
> const string OPT_CLOSE = "終値"
> const string OPT_WCL = "加重終値"
> const string OPT_PIVOT = "ピボット"
> const string OPT_MEDIAN = "実体中央値"
> const string OPT_TWAP = "TWAP"
>
> const string OPT_STY_S = "実線"
> const string OPT_STY_D = "破線"
> const string OPT_STY_DT = "点線"
>
> // データウィンドウ用の表示名
> const string LBL_DATA_A = "オプション ラインA"
> const string LBL_DATA_B = "オプション ラインB"
>
> // 2. UI(ユーザー入力画面)の構築
> // ※言語辞書で定義した定数を呼び出してUIを構築します
> i_tf_str = input.string(OPT_TF_1M, title=LBL_TF, options=[OPT_TF_D, OPT_TF_W, OPT_TF_1M, OPT_TF_3M, OPT_TF_12M], group=GRP_GENERAL, tooltip=TT_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)
>
> // カスタムゾーン設定(ラインA)
> i_type_a = input.string(OPT_TWAP, title=LBL_LINE_A, options=[OPT_MID, OPT_OPEN, OPT_CLOSE, OPT_WCL, OPT_PIVOT, OPT_MEDIAN, OPT_TWAP], group=GRP_OPTION)
> i_show_a = input.bool(true, title=LBL_SHOW, group=GRP_OPTION, inline="linea")
> i_col_a = input.color(color.orange, title="", group=GRP_OPTION, inline="linea")
> i_wid_a = input.int(2, title="", minval=1, maxval=5, group=GRP_OPTION, inline="linea")
> i_sty_a = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], group=GRP_OPTION, inline="linea")
>
> // カスタムゾーン設定(ラインB)
> i_type_b = input.string(OPT_PIVOT, title=LBL_LINE_B, options=[OPT_MID, OPT_OPEN, OPT_CLOSE, OPT_WCL, OPT_PIVOT, OPT_MEDIAN, OPT_TWAP], group=GRP_OPTION)
> i_show_b = input.bool(true, title=LBL_SHOW, group=GRP_OPTION, inline="lineb")
> i_col_b = input.color(color.blue, title="", group=GRP_OPTION, inline="lineb")
> i_wid_b = input.int(2, title="", minval=1, maxval=5, group=GRP_OPTION, inline="lineb")
> i_sty_b = input.string(OPT_STY_S, title="", options=[OPT_STY_S, OPT_STY_D, OPT_STY_DT], group=GRP_OPTION, inline="lineb")
>
> // ゾーン塗りつぶし設定
> i_show_zone = input.bool(true, title=LBL_ZONE, group=GRP_OPTION, inline="zone")
> i_col_zone = input.color(color.new(color.gray, 85), title="", group=GRP_OPTION, inline="zone")
>
> // Gap (窓) 設定
> i_show_gap = input.bool(true, title=LBL_GAP, group=GRP_OPTION, inline="gap")
> i_col_gap_u = input.color(color.new(color.teal, 80), title="上窓", group=GRP_OPTION, inline="gap")
> i_col_gap_d = input.color(color.new(color.red, 80), title="下窓", group=GRP_OPTION, inline="gap")
>
>
> // ==============================================================================
> // 【03】 全コード共通仕様(時間・インフラ処理)
> // ==============================================================================
> // UIで選択された定数をPine内部のシステム識別子に変換
> string req_tf = switch i_tf_str
> OPT_TF_D => "1D"
> OPT_TF_W => "1W"
> OPT_TF_1M => "1M"
> OPT_TF_3M => "3M"
> OPT_TF_12M => "12M"
>
> // 時間計算用の定数 (Current版のオフセット概算に使用)
> const int MS_PER_SEC = 1000
>
>
> // ==============================================================================
> // 【04】 各カテゴリ共通仕様 (描画インフラと判定ロジック)
> // ==============================================================================
> bool is_new_period = timeframe.change(req_tf) 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
>
> // プルダウンの選択肢に応じて純粋な数値を計算する専用関数
> f_get_val(type_str, _o, _h, _l, _c) =>
> float v = switch type_str
> OPT_MID => (_h + _l) / 2.0
> OPT_OPEN => _o
> OPT_CLOSE => _c
> OPT_WCL => (_h + _l + _c * 2.0) / 4.0
> OPT_PIVOT => (_h + _l + _c) / 3.0
> OPT_MEDIAN => (_o + _c) / 2.0
> OPT_TWAP => (_o + _h + _l + _c) / 4.0
> => na
> v
>
> // ------------------------------------------------------------------------------
> // オブジェクトの事前生成 (Current版専用インフラ)
> // ------------------------------------------------------------------------------
> // ラインの表示がOFFでも、ゾーン表示がONなら透明な線を引いてアンカーにします
> bool req_line_a = i_show_a or i_show_zone
> bool req_line_b = i_show_b or i_show_zone
>
> 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)
> 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 box b_gap = box.new(na, na, na, na, xloc=xloc.bar_time, border_color=na, bgcolor=na)
>
> if barstate.isfirst
> if i_show_zone
> linefill.new(l_a, l_b, i_col_zone)
>
>
> // ==============================================================================
> // 【05】 このコード固有の計算仕様 (Specific Indicator Logic)
> // ==============================================================================
> var float temp_o = na
> var float temp_h = na
> var float temp_l = na
>
> var float prev_o = na
> var float prev_h = na
> var float prev_l = na
> var float prev_c = na
>
> var int start_t = na
> var int end_t = na
>
> // 描画エンジンへ引き渡すためのフラグと変数
> bool do_draw = false
> int draw_start = na
> int draw_end = na
> float val_a = na
> float val_b = na
> float gap_c = na
> float gap_o = na
>
> if is_new_period
> // ① 期間が切り替わった瞬間、今まで蓄積していたデータを「前期間の確定値」として昇格させる
> prev_o := temp_o
> prev_h := temp_h
> prev_l := temp_l
> prev_c := close[1]
>
> // ② 新しい期間の高値・安値記録をスタート
> temp_o := open
> temp_h := high
> temp_l := low
>
> // ③ X軸(横幅)を今期間の開始時刻から未来の終了時刻に設定
> start_t := time
> int tc = time_close(req_tf)
> end_t := not na(tc) ? tc : time + timeframe.in_seconds(req_tf) * MS_PER_SEC
> else
> // 期間中は裏で次の期間のための高値・安値を蓄積 (Y座標の高さには一切影響させません)
> temp_h := math.max(temp_h, high)
> temp_l := math.min(temp_l, low)
>
> if not na(prev_o) 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)
>
> // ユーザーが選択した2つのラインの「高さ(Y座標)」を専用関数で計算
> val_a := f_get_val(i_type_a, prev_o, prev_h, prev_l, prev_c)
> val_b := f_get_val(i_type_b, prev_o, prev_h, prev_l, prev_c)
> gap_c := prev_c
> gap_o := temp_o
>
> // ==============================================================================
> // 【06】 描画と出力 (Rendering & Outputs)
> // ==============================================================================
> // 1. チャートへの視覚的出力(オブジェクト座標の更新)
> if do_draw
> if req_line_a
> line.set_xy1(l_a, draw_start, val_a)
> line.set_xy2(l_a, draw_end, val_a)
>
> if req_line_b
> line.set_xy1(l_b, draw_start, val_b)
> line.set_xy2(l_b, draw_end, val_b)
>
> // Gap (窓) の描画(枠線なしで色のみ更新)
> if i_show_gap and not na(gap_c) and not na(gap_o) and (gap_c != gap_o)
> color gap_col = gap_o > gap_c ? i_col_gap_u : i_col_gap_d
> float gap_top = math.max(gap_c, gap_o)
> float gap_bot = math.min(gap_c, gap_o)
> box.set_lefttop(b_gap, draw_start, gap_top)
> box.set_rightbottom(b_gap, draw_end, gap_bot)
> box.set_bgcolor(b_gap, gap_col)
> else
> // 窓がない場合、または非表示の場合は見えない場所へ退避
> box.set_lefttop(b_gap, na, na)
> box.set_rightbottom(b_gap, na, na)
>
> // 2. データウィンドウへの出力 (辞書定数を参照)
> // ※【05】で純粋な計算として算出済みの数値をそのまま出力します
> plot(val_a, title=LBL_DATA_A, color=i_col_a, display=display.data_window, editable=false)
> plot(val_b, title=LBL_DATA_B, color=i_col_b, display=display.data_window, editable=false)
> ````
---
> **Navigation**
**ページ移動:**
* [[2-1. NK-Box|前の記事へ]]
* [[2-3. option2_SVWAP & Zone|次の記事へ]]
* [[09. ▢-TradingViewコード|▢-TradingViewへ戻る]]
* [[01. トップページ|トップページへ戻る]]