# 1-10. NK-Fixed CCI 「足が閉じる何秒前にリアルタイム描画を開始するか、0秒から5分の間で調節できる」機能が付いたCCIです。その他あった方が良い機能も付けています。 ## [CCI] CCIは、現在の価格が「過去の一定期間の平均価格」から、統計的にどの程度乖離(逸脱)しているかを算出する無制限のオシレーターです。その計算式には 0.015 という定数が組み込まれていますが、これは開発者が「CCIの数値の70%〜80%が、-100から+100の間に収まるように」意図的に設定した統計的目安です。裏を返せば、CCIが+100を超えた、あるいは-100を下回った状態は「統計的な常軌を逸した強いトレンド(異常値)が発生している」ことを意味します。 ![[▢TradingViewコード-10. NK-Fixed CCI.webp]] 出典: TradingView --- > [!example] NOTICE(注意) > - 学習および情報提供のみを目的としており、投資助言ではありません。 > - ツールを使用したことによる経済的損失について、一切の責任を負いません。 > - Pine Script v6 で動作確認しています。将来のTradingView側の仕様変更に対するアップデート保証や、個別の導入サポート・改修依頼は受け付けません(現状有姿での提供)。 > - [MIT License](https://opensource.org/licenses/MIT) に則っています。 > [!quote]- 導入の流れ > > - 「Pineを開く」→「スクリプトのメニューを開き、新規作成を選択」→「インジケーターを選択」→「全選択で既存のコードを削除してからペーストする」の順序で行ってください。 > ※この手順で行わないと正しく認識されないことがあります。 > - 好みの配色に設定後、パラメータータブの「デフォルトを保存」を押してください。 --- > **Copy area** > [!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-Fixed CCI", shorttitle="NK-Fixed CCI", overlay=false) > > // ============================================================================== > // 【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_FIXED = "▼ 描画制御 (Fixed Settings)" > const string LBL_SEC = "リアルタイム描画開始 (足が閉じるX秒前)" > const string TT_SEC = "0秒から300秒(5分)の間で調節。指定時間(例:10秒前)になるまで、現在の足への描画を非表示にします。\n0秒と入力した場合は非表示機能を無効化し、常にリアルタイムで描画します。" > > const string GRP_CCI = "▼ CCI設定 (CCI Settings)" > const string LBL_SH_CCI = "CCI " > const string LBL_LEN = "期間" > const string LBL_SRC = "ソース" > > const string LBL_SH_MA1 = "平滑化 1 " > const string LBL_S1_TYPE = "タイプ" > const string LBL_S1_LEN = "期間" > > const string LBL_SH_MA2 = "平滑化 2 " > const string LBL_S2_TYPE = "タイプ" > const string LBL_S2_LEN = "期間" > > // 2. UI(ユーザー入力画面)の構築 & 3. トップダウン処理への適合 > > i_sec = input.int(0, title=LBL_SEC, minval=0, maxval=300, group=GRP_FIXED, tooltip=TT_SEC) > > // CCI設定 (hlc3と期間20をデフォルトに設定) > i_show_cci = input.bool(true, title=LBL_SH_CCI, group=GRP_CCI, inline="CCI0") > i_len = input.int(20, title=LBL_LEN, minval=1, group=GRP_CCI, inline="CCI0") > i_src = input.source(hlc3, title=LBL_SRC, group=GRP_CCI, inline="CCI0") > > // 平滑化1の設定 > i_show_ma1 = input.bool(false, title=LBL_SH_MA1, group=GRP_CCI, inline="CCI1") > i_ma1_type = input.string("SMA", title=LBL_S1_TYPE, options=["SMA", "EMA", "WMA"], group=GRP_CCI, inline="CCI1") > i_ma1_len = input.int(20, title=LBL_S1_LEN, minval=1, group=GRP_CCI, inline="CCI1") > > // 平滑化2の設定 > i_show_ma2 = input.bool(false, title=LBL_SH_MA2, group=GRP_CCI, inline="CCI2") > i_ma2_type = input.string("SMA", title=LBL_S2_TYPE, options=["SMA", "EMA", "WMA"], group=GRP_CCI, inline="CCI2") > i_ma2_len = input.int(50, title=LBL_S2_LEN, minval=1, group=GRP_CCI, inline="CCI2") > > > // ============================================================================== > // 【03】 全コード共通仕様(タイムゾーン・時間インフラ処理) > // ============================================================================== > const int MS_PER_SEC = 1000 > > // ============================================================================== > // 【04】 各カテゴリ共通仕様 (NK-Fixed Core Logic) > // ============================================================================== > bool is_draw_ready = true > > if barstate.isrealtime and i_sec > 0 > if not na(time_close) > int time_left_ms = time_close - timenow > int threshold_ms = i_sec * MS_PER_SEC > > if time_left_ms > threshold_ms > is_draw_ready := false > > > // ============================================================================== > // 【05】 このコード固有の計算仕様 (Specific Indicator Logic) > // ============================================================================== > // 1. 純正CCIの計算 > float raw_cci = ta.cci(i_src, i_len) > > // 2. 平滑化処理の共通関数 > f_calc_smooth(type_str, src_val, len_val) => > float res = na > switch type_str > "SMA" => res := ta.sma(src_val, len_val) > "EMA" => res := ta.ema(src_val, len_val) > "WMA" => res := ta.wma(src_val, len_val) > res > > // 平滑化ラインの計算 > float raw_ma1 = f_calc_smooth(i_ma1_type, raw_cci, i_ma1_len) > float raw_ma2 = f_calc_smooth(i_ma2_type, raw_cci, i_ma2_len) > > // 3. データ引き渡し > float final_cci = (is_draw_ready and i_show_cci) ? raw_cci : na > float final_ma1 = (is_draw_ready and i_show_ma1) ? raw_ma1 : na > float final_ma2 = (is_draw_ready and i_show_ma2) ? raw_ma2 : na > > > // ============================================================================== > // 【06】 描画と出力 (Rendering & Outputs) > // ============================================================================== > // カラー定義(水色・シアンベースに変更) > color col_cci = #00BCD4 // CCIメイン:水色(シアン) > color col_lvl_100 = #787B86 // 基準線:グレー(RSI仕様踏襲) > color col_lvl_0 = color.black // ゼロ線:黒 > color col_lvl_m100= #787B86 // 基準線:グレー(RSI仕様踏襲) > > // メインラインの描画 > plot(final_cci, title="NK-Fixed CCI", color=col_cci, linewidth=1, style=plot.style_line) > plot(final_ma1, title="平滑化 1", color=color.green, linewidth=1, style=plot.style_line) > plot(final_ma2, title="平滑化 2", color=color.blue, linewidth=1, style=plot.style_line) > > // 標準的な水平線の描画 (100, 0, -100) > h100 = hline(100, title="水平線 1", color=col_lvl_100, linestyle=hline.style_dashed) > h0 = hline(0, title="水平線 2", color=col_lvl_0, linestyle=hline.style_dashed) > hm100= hline(-100, title="水平線 3", color=col_lvl_m100, linestyle=hline.style_dashed) > > // 背景の塗りつぶし (水色の不透明度10%) > fill(h100, hm100, title="背景", color=color.new(col_cci, 90)) > > // ユーザー追加ライン (Extra Line) - デフォルトは非表示 > hline(200, title="水平線 4", color=color.black, linestyle=hline.style_solid, display=display.none) > hline(-200, title="水平線 5", color=color.black, linestyle=hline.style_solid, display=display.none) > > // 3. アラート(通知)条件の統合 > bool overbought = ta.crossover(raw_cci, 100) and is_draw_ready > bool oversold = ta.crossunder(raw_cci, -100) and is_draw_ready > > alertcondition(overbought, title="CCI Over 100", message="NK-Fixed CCI crossed over 100 level") > alertcondition(oversold, title="CCI Under -100", message="NK-Fixed CCI crossed under -100") > > > ```` --- > **Navigation** **ページ移動:** * [[1-9. NK-Fixed RCI|前の記事へ]] * [[1-11. NK-Fixed ATR|次の記事へ]] * [[09. ▢-TradingViewコード|▢-TradingViewへ戻る]] * [[01. トップページ|トップページへ戻る]]