# 1-9. NK-Fixed RCI 「足が閉じる何秒前にリアルタイム描画を開始するか、0秒から5分の間で調節できる」機能が付いたRCIです。その他あった方が良い機能も付けています。 ## [RCI] RCIは、計算期間内の「日付(時間)の順位」と「価格の順位」にどれだけの相関関係(連動性)があるかを-100%から+100%の範囲で数値化したインジケーターです。「毎日連続して価格が上がり続ける」と+100%になり、「毎日連続して下がり続ける」と-100%になります。価格の「変動幅(ボラティリティ)」を無視し、「上がったか・下がったかという事実(順位)」のみを抽出するため、線が滑らかになり、ノイズ(突発的なヒゲなど)に強いという特徴があります。 ![[▢TradingViewコード-09. NK-Fixed RCI.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 RCI", shorttitle="NK-Fixed RCI", 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_RCI = "▼ RCI設定 (RCI Settings)" > const string LBL_SHORT = "短期 期間 (Short Length)" > const string LBL_MID = "中期 期間 (Mid Length)" > const string LBL_LONG = "長期 期間 (Long Length)" > const string LBL_SRC = "ソース (Source)" > > // 2. UI(ユーザー入力画面)の構築 & 3. トップダウン処理への適合 > > i_sec = input.int(0, title=LBL_SEC, minval=0, maxval=300, group=GRP_FIXED, tooltip=TT_SEC) > > i_short = input.int(9, title=LBL_SHORT, minval=1, group=GRP_RCI, inline="RCI1") > i_mid = input.int(26, title=LBL_MID, minval=1, group=GRP_RCI, inline="RCI1") > i_long = input.int(52, title=LBL_LONG, minval=1, group=GRP_RCI, inline="RCI2") > i_src = input.source(close, title=LBL_SRC, group=GRP_RCI, inline="RCI2") > > > // ============================================================================== > // 【03】 全コード共通仕様(タイムゾーン・時間インフラ処理) > // ============================================================================== > // 1. 基本時間単位のシステム定義(定数化) > const int MS_PER_SEC = 1000 > > // ============================================================================== > // 【04】 各カテゴリ共通仕様 (NK-Fixed Core Logic) > // ============================================================================== > // 1. カテゴリ固有のインフラ構築(コア機能の定義) > bool is_draw_ready = true > > // リアルタイム足であり、かつユーザーが0秒より大きい数値を設定している場合のみ処理 > 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. インジケーター固有の純粋な数学的処理 > // RCI(順位相関係数)を計算する独自関数 > f_rci(src, len) => > float sum_sq = 0.0 > for i = 0 to len - 1 > int time_rank = i + 1 > float price_rank = 1.0 > int same_count = 0 > for j = 0 to len - 1 > if src[j] > src[i] > price_rank += 1.0 > else if src[j] == src[i] > same_count += 1 > // 同値(タイ)の順位を平均化する処理 > price_rank := price_rank + (same_count - 1) / 2.0 > sum_sq += math.pow(time_rank - price_rank, 2) > float rci = (1.0 - (6.0 * sum_sq) / (len * (math.pow(len, 2) - 1.0))) * 100.0 > rci > > float calc_short = f_rci(i_src, i_short) > float calc_mid = f_rci(i_src, i_mid) > float calc_long = f_rci(i_src, i_long) > > // 2. ロジックの完全な隔離と差し替えの容易性 > > // 3. 視覚的装飾の排除とデータの引き渡し > float final_short = is_draw_ready ? calc_short : na > float final_mid = is_draw_ready ? calc_mid : na > float final_long = is_draw_ready ? calc_long : na > > > // ============================================================================== > // 【06】 描画と出力 (Rendering & Outputs) > // ============================================================================== > // 1. チャートへの視覚的出力(プロットと装飾) > // 水平線と背景の塗りつぶし > ob_line = hline(80, title="Overbought", color=color.new(color.gray, 50), linestyle=hline.style_dashed) > os_line = hline(-80, title="Oversold", color=color.new(color.gray, 50), linestyle=hline.style_dashed) > hline(0, title="Zero Line", color=color.new(color.gray, 50), linestyle=hline.style_dotted) > > fill(ob_line, os_line, title="OB/OS Background", color=color.new(#9E9E9E, 80)) > > plot(final_short, title="RCI Short", color=#F44336, linewidth=2) > plot(final_mid, title="RCI Mid", color=#4CAF50, linewidth=2) > plot(final_long, title="RCI Long", color=#2196F3, linewidth=2) > > // 2. ロジックとデザインの完全分離 > > // 3. アラート(通知)条件の統合 > // ※投資助言を回避するため、方向性を指示する言葉(Buy/Sell等)は使わず、純粋な事実・状態のみを通知します > bool cross_over_sm = ta.crossover(calc_short, calc_mid) and is_draw_ready > bool cross_under_sm = ta.crossunder(calc_short, calc_mid) and is_draw_ready > bool cross_over_0 = ta.crossover(calc_short, 0) and is_draw_ready > bool cross_under_0 = ta.crossunder(calc_short, 0) and is_draw_ready > > alertcondition(cross_over_sm, title="RCI Short Cross Over Mid", message="RCI Short line crossed over RCI Mid line") > alertcondition(cross_under_sm, title="RCI Short Cross Under Mid", message="RCI Short line crossed under RCI Mid line") > alertcondition(cross_over_0, title="RCI Short Cross Over 0", message="RCI Short line crossed over Zero line") > alertcondition(cross_under_0, title="RCI Short Cross Under 0", message="RCI Short line crossed under Zero line") > > > ```` --- > **Navigation** **ページ移動:** * [[1-8. NK-Fixed DMI|前の記事へ]] * [[1-10. NK-Fixed CCI|次の記事へ]] * [[09. ▢-TradingViewコード|▢-TradingViewへ戻る]] * [[01. トップページ|トップページへ戻る]]