# 1-4. NK-Fixed Multi MA 「足が閉じる何秒前にリアルタイム描画を開始するか、0秒から5分の間で調節できる」機能が付いたMulti MAです。その他あった方が良い機能も付けています。 ## [Multi MA] 単一の移動平均線が特定の期間の「線」であるのに対し、Multi MAは複数の異なる期間(例:短期・中期・長期)、あるいは異なる種類(SMAとEMAなど)の移動平均線を同時に描画し、「面」として捉えます。ライン同士の「間隔」や「配列」などを分析します。 ![[▢TradingViewコード-04. NK-Fixed Multi MA.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 Multi MA", shorttitle="NK-Fixed Multi MA", 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_FIXED = "▼ 描画制御 (Fixed Settings)" > const string LBL_SEC = "リアルタイム描画開始 (足が閉じるX秒前)" > const string TT_SEC = "0秒から300秒(5分)の間で調節。指定時間(例:10秒前)になるまで、現在の足への描画を非表示にします。\n0秒と入力した場合は非表示機能を無効化し、常にリアルタイムで描画します。" > > const string GRP_MA = "▼ Multi MA設定 (Multi MA Settings)" > const string LBL_MA1 = "MA 1" > const string LBL_MA2 = "MA 2" > const string LBL_MA3 = "MA 3" > const string LBL_MA4 = "MA 4" > const string LBL_WIDTH = "太さ" > > // 2. UI(ユーザー入力画面)の構築 & 3. トップダウン処理への適合 > > i_sec = input.int(0, title=LBL_SEC, minval=0, maxval=300, group=GRP_FIXED, tooltip=TT_SEC) > > // MA 1 (色指定: 10-2 に対応) > i_ma1_show = input.bool(true, title=LBL_MA1, group=GRP_MA, inline="MA1_A") > i_ma1_type = input.string("SMA", title="", options=["SMA", "EMA", "WMA"], group=GRP_MA, inline="MA1_A") > i_ma1_len = input.int(20, title="", minval=1, group=GRP_MA, inline="MA1_A") > i_ma1_src = input.source(close, title="", group=GRP_MA, inline="MA1_A") > i_ma1_col = input.color(color.purple, title="", group=GRP_MA, inline="MA1_B") > i_ma1_wid = input.int(2, title=LBL_WIDTH, minval=1, maxval=5, group=GRP_MA, inline="MA1_B") > > // MA 2 (色指定: 2-2 に対応) > i_ma2_show = input.bool(true, title=LBL_MA2, group=GRP_MA, inline="MA2_A") > i_ma2_type = input.string("SMA", title="", options=["SMA", "EMA", "WMA"], group=GRP_MA, inline="MA2_A") > i_ma2_len = input.int(50, title="", minval=1, group=GRP_MA, inline="MA2_A") > i_ma2_src = input.source(close, title="", group=GRP_MA, inline="MA2_A") > i_ma2_col = input.color(color.orange, title="", group=GRP_MA, inline="MA2_B") > i_ma2_wid = input.int(2, title=LBL_WIDTH, minval=1, maxval=5, group=GRP_MA, inline="MA2_B") > > // MA 3 (色指定: 4-7 に対応) > i_ma3_show = input.bool(true, title=LBL_MA3, group=GRP_MA, inline="MA3_A") > i_ma3_type = input.string("SMA", title="", options=["SMA", "EMA", "WMA"], group=GRP_MA, inline="MA3_A") > i_ma3_len = input.int(100, title="", minval=1, group=GRP_MA, inline="MA3_A") > i_ma3_src = input.source(close, title="", group=GRP_MA, inline="MA3_A") > i_ma3_col = input.color(color.green, title="", group=GRP_MA, inline="MA3_B") > i_ma3_wid = input.int(2, title=LBL_WIDTH, minval=1, maxval=5, group=GRP_MA, inline="MA3_B") > > // MA 4 (色指定: 7-7 に対応) > i_ma4_show = input.bool(true, title=LBL_MA4, group=GRP_MA, inline="MA4_A") > i_ma4_type = input.string("SMA", title="", options=["SMA", "EMA", "WMA"], group=GRP_MA, inline="MA4_A") > i_ma4_len = input.int(200, title="", minval=1, group=GRP_MA, inline="MA4_A") > i_ma4_src = input.source(close, title="", group=GRP_MA, inline="MA4_A") > i_ma4_col = input.color(color.blue, title="", group=GRP_MA, inline="MA4_B") > i_ma4_wid = input.int(2, title=LBL_WIDTH, minval=1, maxval=5, group=GRP_MA, inline="MA4_B") > > > // ============================================================================== > // 【03】 全コード共通仕様(タイムゾーン・時間インフラ処理) > // ============================================================================== > // 1. 基本時間単位のシステム定義(定数化) > const int MS_PER_SEC = 1000 > > // ============================================================================== > // 【04】 各カテゴリ共通仕様 (NK-Fixed Core Logic) > // ============================================================================== > // 1. カテゴリ固有のインフラ構築(コア機能の定義) > 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. インジケーター固有の純粋な数学的処理 > // 各MAのタイプ(SMA/EMA/WMA)に応じて計算を切り替える関数 > f_calc_ma(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 calc_ma1 = f_calc_ma(i_ma1_type, i_ma1_src, i_ma1_len) > float calc_ma2 = f_calc_ma(i_ma2_type, i_ma2_src, i_ma2_len) > float calc_ma3 = f_calc_ma(i_ma3_type, i_ma3_src, i_ma3_len) > float calc_ma4 = f_calc_ma(i_ma4_type, i_ma4_src, i_ma4_len) > > // 3. 視覚的装飾の排除とデータの引き渡し > // ユーザーの表示チェック(i_maX_show)と描画フラグ(is_draw_ready)の両方を満たす場合のみデータを渡す > float final_ma1 = (i_ma1_show and is_draw_ready) ? calc_ma1 : na > float final_ma2 = (i_ma2_show and is_draw_ready) ? calc_ma2 : na > float final_ma3 = (i_ma3_show and is_draw_ready) ? calc_ma3 : na > float final_ma4 = (i_ma4_show and is_draw_ready) ? calc_ma4 : na > > > // ============================================================================== > // 【06】 描画と出力 (Rendering & Outputs) > // ============================================================================== > // 1. チャートへの視覚的出力(プロットと装飾) > plot(final_ma1, title="MA 1", color=i_ma1_col, linewidth=i_ma1_wid, style=plot.style_line) > plot(final_ma2, title="MA 2", color=i_ma2_col, linewidth=i_ma2_wid, style=plot.style_line) > plot(final_ma3, title="MA 3", color=i_ma3_col, linewidth=i_ma3_wid, style=plot.style_line) > plot(final_ma4, title="MA 4", color=i_ma4_col, linewidth=i_ma4_wid, style=plot.style_line) > > // 3. アラート(通知)条件の統合 > // Multi MAならではの機能として、代表的な「MA 1とMA 2のクロス」を通知条件に設定 > bool ma_cross_over = ta.crossover(calc_ma1, calc_ma2) and is_draw_ready > bool ma_cross_under = ta.crossunder(calc_ma1, calc_ma2) and is_draw_ready > > alertcondition(ma_cross_over, title="MA1 Cross Over MA2", message="NK-Fixed Multi MA: MA 1 crossed over MA 2") > alertcondition(ma_cross_under, title="MA1 Cross Under MA2", message="NK-Fixed Multi MA: MA 1 crossed under MA 2") > > > ```` --- > **Navigation** **ページ移動:** * [[1-3. NK-Fixed WMA|前の記事へ]] * [[1-5. NK-Fixed RSI|次の記事へ]] * [[09. ▢-TradingViewコード|▢-TradingViewへ戻る]] * [[01. トップページ|トップページへ戻る]]