Indicator · Pine Script v6 · On the chart

Ver15 Environment Recognition (Provisional Pivot)

by Pesci1134· code credited to Ver15 環境認識スクリプト - 暫定ピボット方式

This multi-timeframe indicator plots technical analysis tools directly on the price chart using 1-hour higher timeframe data.

View on GitHub

Repaints

GitHub stars2on the repository
Pine versionv6current
Lines of code336
Settings20inputs
LicenceNone statedfile: MPL-2.0
Last update2 weeks ago13 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

336 lines of Pine Script v6 from scripts/pinescript/Ver15_Environment_Prospective.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Ver15_Environment_Prospective.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0
// © Ver15 環境認識スクリプト - 暫定ピボット方式
// sukepoyo_sub.pineのZigZagロジックを忠実に再現

//@version=6
indicator("Ver15 環境認識(暫定ピボット)", overlay=true, max_lines_count=500, max_labels_count=500)

// ==========================================
// 入力パラメータ
// ==========================================

// 1時間足パーフェクトオーダー
ema_1h_short = input.int(20, "1H EMA短期", minval=1, group="1時間足設定")
ema_1h_mid = input.int(30, "1H EMA中期", minval=1, group="1時間足設定")
ema_1h_long = input.int(40, "1H EMA長期", minval=1, group="1時間足設定")

// RCI設定
rci_1h_period = input.int(9, "1H RCI期間", minval=1, group="1時間足設定")
rci_1h_threshold = input.float(60, "1H RCI閾値", minval=0, maxval=100, group="1時間足設定")

// MACD設定(1時間足ダイバージェンス検出用)
macd_fast = input.int(6, "MACD Fast", minval=1, group="MACD設定")
macd_slow = input.int(13, "MACD Slow", minval=1, group="MACD設定")
macd_signal = input.int(4, "MACD Signal", minval=1, group="MACD設定")

// ZigZag設定
zigzag_depth = input.int(12, "ZigZag Depth", minval=1, maxval=50, group="ZigZag設定")
zigzag_deviation = input.int(5, "ZigZag Deviation (Points)", minval=1, group="ZigZag設定")
zigzag_backstep = input.int(3, "ZigZag Backstep", minval=1, group="ZigZag設定")

// ダイバージェンス有効期間
div_valid_bars = input.int(12, "ダイバージェンス有効バー数", minval=1, group="ダイバージェンス設定")

// 表示設定
show_zigzag = input.bool(true, "ZigZagを表示", group="表示設定")
show_divergence = input.bool(true, "ダイバージェンスを表示", group="表示設定")
show_prospective = input.bool(true, "暫定先端を表示(点線)", group="表示設定")
show_ema = input.bool(true, "1H EMAを表示", group="表示設定")
show_table = input.bool(true, "情報テーブルを表示", group="表示設定")

// ZigZag色設定
zz_color = input.color(color.white, "ZigZag色", group="ZigZag表示設定")
zz_color_prospective = input.color(color.orange, "暫定先端色", group="ZigZag表示設定")
zz_line_width = input.int(2, "ZigZagライン幅", minval=1, maxval=5, group="ZigZag表示設定")

// ==========================================
// 1時間足データ取得
// ==========================================
[open_1h, high_1h, low_1h, close_1h] = request.security(syminfo.tickerid, "60", [open, high, low, close])
ema20_1h = request.security(syminfo.tickerid, "60", ta.ema(close, ema_1h_short))
ema30_1h = request.security(syminfo.tickerid, "60", ta.ema(close, ema_1h_mid))
ema40_1h = request.security(syminfo.tickerid, "60", ta.ema(close, ema_1h_long))

// MACD(1時間足)
[macd_line_1h, signal_line_1h, hist_1h] = request.security(syminfo.tickerid, "60", ta.macd(close, macd_fast, macd_slow, macd_signal))

// ==========================================
// RCI計算関数
// ==========================================
rci(source, length) =>
    sum_d2 = 0.0
    for i = 0 to length - 1
        price_rank = 0.0
        count_less = 0
        count_equal = 0
        for j = 0 to length - 1
            if source[j] < source[i]
                count_less += 1
            else if source[j] == source[i]
                count_equal += 1
        price_rank := 1 + count_less + (count_equal - 1) / 2.0
        time_rank = length - i
        d = time_rank - price_rank
        sum_d2 += d * d
    (1 - (6 * sum_d2) / (length * (length * length - 1))) * 100

rci_1h = request.security(syminfo.tickerid, "60", rci(close, rci_1h_period))

// ==========================================
// 1時間足パーフェクトオーダー判定
// ==========================================
po_uptrend_1h = ema20_1h > ema30_1h and ema30_1h > ema40_1h
po_downtrend_1h = ema20_1h < ema30_1h and ema30_1h < ema40_1h

// ==========================================
// ZigZag計算(sukepoyo_sub.pine方式を忠実に再現)
// ==========================================

// deviation閾値
float dev_th = zigzag_deviation * syminfo.mintick

// highestbars / lowestbars(1時間足)
// request.security内で計算
zz_hb = request.security(syminfo.tickerid, "60", ta.highestbars(zigzag_depth))
zz_lb = request.security(syminfo.tickerid, "60", ta.lowestbars(zigzag_depth))

// barssince条件(sukepoyo_sub.pineと同じ形式)
// high[-hb]は hbが負なので過去のバーを参照
zz_hr = request.security(syminfo.tickerid, "60", ta.barssince(not (high[-ta.highestbars(zigzag_depth)] - high > zigzag_deviation * syminfo.mintick)[1]))
zz_lr = request.security(syminfo.tickerid, "60", ta.barssince(not (low - low[-ta.lowestbars(zigzag_depth)] > zigzag_deviation * syminfo.mintick)[1]))

// 方向決定(sukepoyo_sub.pineと同じ)
zz_dir = request.security(syminfo.tickerid, "60", ta.barssince(not (ta.barssince(not (high[-ta.highestbars(zigzag_depth)] - high > zigzag_deviation * syminfo.mintick)[1]) > ta.barssince(not (low - low[-ta.lowestbars(zigzag_depth)] > zigzag_deviation * syminfo.mintick)[1]))) >= zigzag_backstep ? -1 : 1)

// ピボットポイント追跡(chart.point相当)
var float z_A_price = na   // 現在形成中(次の谷/山候補)
var int z_A_bar = na
var float z2_A_price = na  // 直近確定候補
var int z2_A_bar = na
var float z1_A_price = na  // 1つ前の確定
var int z1_A_bar = na

// 方向転換時
if zz_dir != zz_dir[1]
    z1_A_price := z2_A_price
    z1_A_bar := z2_A_bar
    z2_A_price := z_A_price
    z2_A_bar := z_A_bar

// ピボット更新(sukepoyo_sub.pineロジック)
if zz_dir > 0  // 上昇方向
    if high_1h > nz(z2_A_price, 0)
        z2_A_price := high_1h
        z2_A_bar := bar_index
        z_A_price := low_1h
        z_A_bar := bar_index
    if low_1h < nz(z_A_price, high_1h)
        z_A_price := low_1h
        z_A_bar := bar_index
else if zz_dir < 0  // 下降方向
    if low_1h < nz(z2_A_price, 999999)
        z2_A_price := low_1h
        z2_A_bar := bar_index
        z_A_price := high_1h
        z_A_bar := bar_index
    if high_1h > nz(z_A_price, 0)
        z_A_price := high_1h
        z_A_bar := bar_index

// ==========================================
// ダイバージェンス検出(暫定ピボット使用)
// ==========================================
var float prev_low_price = na
var float prev_macd_at_low = na
var int prev_low_bar = na

var float prev_high_price = na
var float prev_macd_at_high = na
var int prev_high_bar = na

// ダイバージェンス状態
var string div_type = "none"
var string div_direction = "none"
var int div_bar = na
var bool div_active = false

// 下降方向で安値更新時(買いダイバージェンス検出)
if zz_dir < 0 and not na(z2_A_price) and z2_A_bar != prev_low_bar
    current_macd = macd_line_1h

    if not na(prev_low_price) and not na(prev_macd_at_low)
        // ヒドゥン買い: 価格が切り上げ、MACDが切り下げ
        if z2_A_price > prev_low_price and current_macd < prev_macd_at_low
            div_type := "hidden"
            div_direction := "long"
            div_bar := bar_index
            div_active := true
        // レギュラー買い: 価格が切り下げ、MACDが切り上げ
        else if z2_A_price < prev_low_price and current_macd > prev_macd_at_low
            div_type := "regular"
            div_direction := "long"
            div_bar := bar_index
            div_active := true

    prev_low_price := z2_A_price
    prev_macd_at_low := current_macd
    prev_low_bar := z2_A_bar

// 上昇方向で高値更新時(売りダイバージェンス検出)
if zz_dir > 0 and not na(z2_A_price) and z2_A_bar != prev_high_bar
    current_macd = macd_line_1h

    if not na(prev_high_price) and not na(prev_macd_at_high)
        // ヒドゥン売り: 価格が切り下げ、MACDが切り上げ
        if z2_A_price < prev_high_price and current_macd > prev_macd_at_high
            div_type := "hidden"
            div_direction := "short"
            div_bar := bar_index
            div_active := true
        // レギュラー売り: 価格が切り上げ、MACDが切り下げ
        else if z2_A_price > prev_high_price and current_macd < prev_macd_at_high
            div_type := "regular"
            div_direction := "short"
            div_bar := bar_index
            div_active := true

    prev_high_price := z2_A_price
    prev_macd_at_high := current_macd
    prev_high_bar := z2_A_bar

// ダイバージェンスの有効期限チェック
if div_active and bar_index - div_bar > div_valid_bars
    div_active := false
    div_type := "none"
    div_direction := "none"

// ==========================================
// 環境認識の総合判定
// ==========================================
env_long = po_uptrend_1h and rci_1h <= -rci_1h_threshold and div_active and div_direction == "long"
env_short = po_downtrend_1h and rci_1h >= rci_1h_threshold and div_active and div_direction == "short"

// ==========================================
// ZigZag描画(sukepoyo_sub.pine方式)
// ==========================================
var line zz_line = na

// 方向が同じ場合は前のラインを削除(更新するため)
if zz_dir == zz_dir[1]
    line.delete(zz_line[1])

// ZigZagライン描画(z1_A → z2_A)
if show_zigzag and not na(z1_A_bar) and not na(z2_A_bar) and not na(z1_A_price) and not na(z2_A_price)
    zz_line := line.new(z1_A_bar, z1_A_price, z2_A_bar, z2_A_price,
                        xloc.bar_index, extend.none, zz_color, line.style_solid, zz_line_width)

// 暫定先端への点線
var line zz_prospective_line = na
if show_prospective and show_zigzag
    line.delete(zz_prospective_line[1])
    if not na(z2_A_bar) and not na(z_A_bar) and not na(z2_A_price) and not na(z_A_price)
        zz_prospective_line := line.new(z2_A_bar, z2_A_price, z_A_bar, z_A_price,
                                         xloc.bar_index, extend.none, zz_color_prospective, line.style_dashed, zz_line_width)

// 暫定先端ラベル
var label prospective_label = na
if show_prospective and barstate.islast
    label.delete(prospective_label[1])
    if zz_dir > 0 and not na(z_A_price)
        prospective_label := label.new(z_A_bar, z_A_price, "暫定L\n" + str.tostring(z_A_price, "#.###"),
                                        style=label.style_label_up, color=color.new(zz_color_prospective, 50),
                                        textcolor=color.white, size=size.tiny)
    else if zz_dir < 0 and not na(z_A_price)
        prospective_label := label.new(z_A_bar, z_A_price, "暫定H\n" + str.tostring(z_A_price, "#.###"),
                                        style=label.style_label_down, color=color.new(zz_color_prospective, 50),
                                        textcolor=color.white, size=size.tiny)

// ==========================================
// EMA描画
// ==========================================
plot(show_ema ? ema20_1h : na, "1H EMA20", color=color.new(color.blue, 50), linewidth=1)
plot(show_ema ? ema30_1h : na, "1H EMA30", color=color.new(color.orange, 50), linewidth=1)
plot(show_ema ? ema40_1h : na, "1H EMA40", color=color.new(color.red, 50), linewidth=1)

// ==========================================
// ダイバージェンスシグナル
// ==========================================
if show_divergence
    if div_active and div_bar == bar_index
        if div_direction == "long"
            div_label_text = div_type == "hidden" ? "Hidden↑" : "Regular↑"
            label.new(bar_index, low_1h, div_label_text,
                      style=label.style_label_up, color=color.green,
                      textcolor=color.white, size=size.small)
        else if div_direction == "short"
            div_label_text = div_type == "hidden" ? "Hidden↓" : "Regular↓"
            label.new(bar_index, high_1h, div_label_text,
                      style=label.style_label_down, color=color.red,
                      textcolor=color.white, size=size.small)

// 環境認識シグナル(背景色)
bgcolor(env_long ? color.new(color.green, 90) : na, title="買い環境")
bgcolor(env_short ? color.new(color.red, 90) : na, title="売り環境")

// ==========================================
// 情報テーブル
// ==========================================
if show_table
    var table info_table = table.new(position.top_right, 2, 9,
                                      bgcolor=color.new(color.black, 80),
                                      border_color=color.gray, border_width=1)

    if barstate.islast
        table.cell(info_table, 0, 0, "項目", text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 0, "状態", text_color=color.white, text_size=size.small)

        // 1H パーフェクトオーダー
        po_status = po_uptrend_1h ? "上昇PO" : (po_downtrend_1h ? "下降PO" : "なし")
        po_color = po_uptrend_1h ? color.green : (po_downtrend_1h ? color.red : color.gray)
        table.cell(info_table, 0, 1, "1H PO", text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 1, po_status, text_color=po_color, text_size=size.small)

        // 1H RCI
        rci_status = rci_1h <= -rci_1h_threshold ? "売られすぎ" : (rci_1h >= rci_1h_threshold ? "買われすぎ" : "中立")
        rci_color = rci_1h <= -rci_1h_threshold ? color.green : (rci_1h >= rci_1h_threshold ? color.red : color.gray)
        table.cell(info_table, 0, 2, "1H RCI", text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 2, str.tostring(rci_1h, "#.0") + " " + rci_status, text_color=rci_color, text_size=size.small)

        // ZigZag方向
        zz_status = zz_dir > 0 ? "上昇中" : "下降中"
        zz_dir_color = zz_dir > 0 ? color.green : color.red
        table.cell(info_table, 0, 3, "ZZ方向", text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 3, zz_status, text_color=zz_dir_color, text_size=size.small)

        // 確定ピボット(z2_A)
        z2_label = zz_dir > 0 ? "確定高値" : "確定安値"
        table.cell(info_table, 0, 4, z2_label, text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 4, str.tostring(z2_A_price, "#.###"), text_color=color.white, text_size=size.small)

        // 暫定先端(z_A)
        zA_label = zz_dir > 0 ? "暫定安値" : "暫定高値"
        table.cell(info_table, 0, 5, zA_label, text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 5, str.tostring(z_A_price, "#.###"), text_color=zz_color_prospective, text_size=size.small)

        // ダイバージェンス
        div_status = div_active ? (div_type + " " + div_direction) : "なし"
        div_color = div_active ? (div_direction == "long" ? color.green : color.red) : color.gray
        table.cell(info_table, 0, 6, "Div", text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 6, div_status, text_color=div_color, text_size=size.small)

        // 環境認識結果
        env_status = env_long ? "買い環境" : (env_short ? "売り環境" : "待機")
        env_color = env_long ? color.green : (env_short ? color.red : color.gray)
        table.cell(info_table, 0, 7, "環境", text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 7, env_status, text_color=env_color, text_size=size.small)

        // MACD値
        table.cell(info_table, 0, 8, "MACD", text_color=color.white, text_size=size.small)
        table.cell(info_table, 1, 8, str.tostring(macd_line_1h, "#.####"), text_color=color.white, text_size=size.small)

// ==========================================
// アラート
// ==========================================
alertcondition(env_long, title="買い環境成立", message="Ver15: 買い環境が成立しました(暫定ピボット方式)")
alertcondition(env_short, title="売り環境成立", message="Ver15: 売り環境が成立しました(暫定ピボット方式)")
alertcondition(div_active and div_bar == bar_index, title="ダイバージェンス検出", message="Ver15: ダイバージェンスを検出しました(暫定)")

Overview

Ver15 Environment Recognition (Provisional Pivot) calculates 1-hour Exponential Moving Averages (20, 30, 40), a custom Rank Correlation Index (RCI), and MACD divergence signals. Additionally, it draws ZigZag trend lines with provisional pivot extensions and displays an optional status table. Settings allow customization of EMA lengths, MACD parameters, ZigZag depth and deviation, and visual toggles. Note that provisional ZigZag pivots repaint dynamically until locked by confirmed price movement.

Details

Published by

Pesci1134 on GitHub

Code credit

Ver15 環境認識スクリプト - 暫定ピボット方式, as written in the script's header

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Oscillators & momentum, Moving averages, Divergence

Markets

Forex

Timeframes

M1-M5, M15-H1

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)

Topics

github-configalgorithmic-tradingbacktestingdivergenceforexgbpjpymacdpinescriptpythontrading

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
1H EMA短期int20ema_1h_short
1H EMA中期int30ema_1h_mid
1H EMA長期int40ema_1h_long
1H RCI期間int9rci_1h_period
1H RCI閾値float60rci_1h_threshold
MACD Fastint6macd_fast
MACD Slowint13macd_slow
MACD Signalint4macd_signal
ZigZag Depthint12zigzag_depth
ZigZag Deviation (Points)int5zigzag_deviation
ZigZag Backstepint3zigzag_backstep
ダイバージェンス有効バー数int12div_valid_bars
Show all 20 settings
SettingTypeDefaultVariable
ZigZagを表示booltrueshow_zigzag
ダイバージェンスを表示booltrueshow_divergence
暫定先端を表示(点線)booltrueshow_prospective
1H EMAを表示booltrueshow_ema
情報テーブルを表示booltrueshow_table
ZigZag色colorcolor.whitezz_color
暫定先端色colorcolor.orangezz_color_prospective
ZigZagライン幅int2zz_line_width
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

5 stars

This indicator overlays multiple technical analysis tools onto the price chart to evaluate trend direction and trade setups. It computes an exponential moving average, a smoothed Stochastic RSI, a custom Williams Alligator using smoothed moving averages with o

Indicator v4 TrendMoving averages
Updated 3 years ago · Apache-2.0 GitHub repository of 200 EMA + Alligator + Stochastic

Fractals with Divergence Scanner is an overlay indicator that combines Exponential Moving Averages, an eight-line EMA ribbon cloud, and WaveTrend divergence analysis. It calculates baseline EMA trends alongside WaveTrend oscillators to detect regular and hidde

Indicator v5 TrendMoving averages
Updated 5 months ago · None stated GitHub repository of Fractals with Divergence Scanner
2 stars

ARPS Ultimate MultiStrategy Trading combines multiple technical indicators into a single chart overlay. It calculates and plots trend lines, moving averages, Ichimoku cloud components, Williams Alligator lines, and Fibonacci support and resistance levels direc

Indicator v4 TrendOscillators & momentum
Updated 6 months ago · None stated GitHub repository of ARPS Ultimate MultiStrategy Trading

Complexity Trender

by panzmoravylab
2 stars

Complexity Trender is an indicator that combines EMA crossovers, RSI momentum, Stochastic signals, Bollinger Bands, ADX trend strength, volume analysis, and divergence detection to identify trends. It plots labels, trend lines, and a summary table directly on

Indicator v6 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Complexity Trender

This indicator evaluates how price relates to one selected moving-average family rather than treating a crossover as a signal. It scores trend quality, historical respect of the average, extension, compression, acceleration, and exhaustion, then plots a relati

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of Market–Average Relationship Engine [WavesUnchained]

MTF MA bands + RSI

by InNoobWeTrust
4 stars

This indicator plots multi-timeframe moving average bands alongside a Relative Strength Index in a separate pane. It calculates up to four configurable moving averages across different timeframes, offering selectable types such as SMA, EMA, and WMA with colore

Indicator v6 Oscillators & momentumMoving averages
Updated today · None stated GitHub repository of MTF MA bands + RSI

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers