勉強用インジケーター<無料>

ストップ高研究所
FREE INDICATOR ARCHIVE
無料配布|TradingView

勉強用
インジケーター

銘柄研究やチャート分析の補助として使えるTradingView用Pine Scriptを無料配布しています。画像による見本表示は省き、機能の概要とコードだけをシンプルに掲載しています。

※「TradingViewをサブスク」ボタンはアフィリエイトリンクです。

インジケーターを見る TradingViewをサブスクTradingViewをサブスクボタンはアフィリエイトリンクです。
無料配布について

インジケーターの無料ダウンロード・無料配布は、予告なく変更または停止する場合があります。必要なコードは各自で保存してご利用ください。

無料インジケーター一覧

ストップ高マーカー

日本株のストップ高発生日を、縦線・日付ラベル・一覧テーブルで確認するためのインジケーターです。

コードを見る

売買代金

下位足データから売買代金を集計し、棒グラフと平均線で売買エネルギーを確認するためのインジケーターです。

コードを見る

売買代金回転率

当日の売買代金を時価総額と比較し、売買代金回転率とその平均を表示するインジケーターです。

コードを見る

RSI-BB

RSIの過熱感を確認しながら、メインチャートへの高RSI・低RSIマークやBull/Bearダイバージェンスも確認できるインジケーターです。

コードを見る

ストップ高マーカー

確定済みの日足データを使ってストップ高を判定し、発生日をチャート上に表示します。

  • 日足基準でストップ高を判定
  • 縦線と日付ラベルを表示
  • 検出した発生日をテーブル表示
  • 取得する日付範囲を指定可能
Pine Script v6
//@version=6
// 日本株個別銘柄向け ストップ高マーカー(日足基準)
// ① ストップ高の日(ロック足 O=H=L=C 含む)に縦線+日付ラベル
// ② ストップ高の日すべての日付をテーブル表示
// ※ どの時間足を表示していても、ストップ高判定は「日足」のみで行う
indicator("日本株 ストップ高マーカー(日足基準)", overlay=true, max_lines_count=500, max_labels_count=500)

// ===== 入力 =====
incLocked = input.bool(true,  "ロック足(O=H=L=C)も含める")
lineCol   = input.color(color.new(color.red, 0), "縦線の色")
lineW     = input.int(1, "縦線の太さ", minval=1, maxval=4)
tblPos    = input.string("top_right", "テーブル位置", options=["top_right","top_left","bottom_right","bottom_left","middle_right"])
rowsPerCol= input.int(30, "1列あたりの行数", minval=5, maxval=60)
tickTol   = input.bool(true, "呼値ズレ許容(高値判定)")
showLbl   = input.bool(true,  "縦線に日付ラベルを表示")
lblPos    = input.string("above", "ラベル位置", options=["above","below"])
lblSize   = input.string("small", "ラベル文字サイズ", options=["tiny","small","normal"])

// ===== ストップ高取得期間 =====
rangeMode = input.string("過去1年", "ストップ高取得日付範囲", options=["過去1年","期間指定"])
rangeStartInput = input.time(timestamp("2025-01-01T00:00:00+09:00"), "開始日")
rangeEndInput   = input.time(timestamp("2099-12-31T23:59:59+09:00"), "終了日")

oneYearMs = 365 * 24 * 60 * 60 * 1000
rangeStart = rangeMode == "過去1年" ? timenow - oneYearMs : rangeStartInput
rangeEnd   = rangeMode == "過去1年" ? timenow : rangeEndInput

// ===== JPX 制限値幅(内国株:基準値段別)=====
limitWidth(base) =>
    w = 0.0
    if base < 100
        w := 30
    else if base < 200
        w := 50
    else if base < 500
        w := 80
    else if base < 700
        w := 100
    else if base < 1000
        w := 150
    else if base < 1500
        w := 300
    else if base < 2000
        w := 400
    else if base < 3000
        w := 500
    else if base < 5000
        w := 700
    else if base < 7000
        w := 1000
    else if base < 10000
        w := 1500
    else if base < 15000
        w := 3000
    else if base < 20000
        w := 4000
    else if base < 30000
        w := 5000
    else if base < 50000
        w := 7000
    else if base < 70000
        w := 10000
    else if base < 100000
        w := 15000
    else if base < 150000
        w := 30000
    else if base < 200000
        w := 40000
    else if base < 300000
        w := 50000
    else if base < 500000
        w := 70000
    else if base < 700000
        w := 100000
    else if base < 1000000
        w := 150000
    else
        w := 150000
    w

// ===== 日足データ取得(チャートの時間足に依存しない)=====
[dO, dH, dL, dC, dBase, dT] = request.security(syminfo.tickerid, "D", [open, high, low, close, close[1], time], lookahead=barmerge.lookahead_off)

// 新しい日足バーが確定した最初のチャートバーで、1つ前(=確定済み)の日足を評価
isNewDay = ta.change(dT) != 0
pO    = dO[1]
pH    = dH[1]
pL    = dL[1]
pC    = dC[1]
pBase = dBase[1]
pT    = dT[1]

tol      = tickTol ? syminfo.mintick / 2 : 0.0
sh_price = pBase + limitWidth(pBase)
strictSH = not na(pBase) and math.abs(pH - sh_price) <= tol
lockedSH = not na(pBase) and pO == pH and pH == pL and pL == pC and pC > pBase
inDateRange = not na(pT) and pT >= rangeStart and pT <= rangeEnd
isSH     = isNewDay and inDateRange and (strictSH or (incLocked and lockedSH))

// ===== ① 縦線 + 日付ラベル(日足の位置に時刻基準で描画)=====
if isSH
    float y2 = pH == pL ? pH + syminfo.mintick : pH
    line.new(pT, pL, pT, y2, xloc=xloc.bar_time, extend=extend.both, color=lineCol, width=lineW)
    if showLbl
        string d   = str.format_time(pT, "yyyy/MM/dd", "Asia/Tokyo")
        bool   abv = lblPos == "above"
        sz = lblSize == "tiny" ? size.tiny : lblSize == "normal" ? size.normal : size.small
        label.new(pT, abv ? pH : pL, text=d, xloc=xloc.bar_time, yloc=yloc.price, style=abv ? label.style_label_down : label.style_label_up, color=lineCol, textcolor=color.white, size=sz)

// ===== ② 日付収集 =====
var array<string> dates = array.new<string>()
if isSH
    array.push(dates, str.format_time(pT, "yyyy/MM/dd", "Asia/Tokyo"))

// ===== テーブル描画(最終バーのみ)=====
posMap(p) =>
    p == "top_left"      ? position.top_left      :
     p == "bottom_right" ? position.bottom_right  :
     p == "bottom_left"  ? position.bottom_left   :
     p == "middle_right" ? position.middle_right  :
     position.top_right

var table t = na
if barstate.islast
    table.delete(t)
    int n    = array.size(dates)
    int cols = math.max(1, int(math.ceil(n / rowsPerCol)))
    t := table.new(posMap(tblPos), cols, rowsPerCol + 1, border_width=1, frame_color=color.gray, frame_width=1)
    for c = 0 to cols - 1
        string hdr = c == 0 ? "計 " + str.tostring(n) + "件" : "日付"
        table.cell(t, c, 0, hdr, text_color=color.white, bgcolor=color.new(color.red, 0), text_size=size.small)
    if n > 0
        for i = 0 to n - 1
            int c  = int(i / rowsPerCol)
            int rr = i % rowsPerCol + 1
            table.cell(t, c, rr, array.get(dates, i), text_color=color.white, bgcolor=color.new(color.black, 15), text_size=size.small)

売買代金

指定した下位足の「価格 × 出来高」を集計して売買代金を表示します。日足チャートで、その日の資金流入の大きさを確認する用途を想定しています。

  • 下位足から売買代金を集計
  • 円・百万円・億円の表示単位に対応
  • 平均線と平均比を表示
  • 日足VWAPを使った色分け
Pine Script v6
//@version=6
indicator("売買代金(日中足合計・過去表示対応・億円)", overlay=false, max_bars_back=5000)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 入力設定
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
lowerTf = input.timeframe(
     "5",
     "集計に使う下位足",
     tooltip="日足チャートでは 1, 3, 5, 15 などを指定します。精度重視なら1分、表示期間重視なら5分〜15分。"
)

priceType = input.string(
     "HLC3",
     "各下位足の計算価格",
     options = ["終値", "HL2", "HLC3", "OHLC4"],
     tooltip = "各下位足ごとの price × volume の price を指定します。HLC3が実用上おすすめです。"
)

unitType = input.string(
     "億円",
     "表示単位",
     options = ["円", "百万円", "億円"]
)

maLen = input.int(25, "平均期間", minval=1)
showMA = input.bool(true, "平均線を表示")
showRatio = input.bool(true, "平均比をデータウィンドウに表示")
showTable = input.bool(true, "右上テーブルを表示")
showIndicatorName = input.bool(true, "インジケーター名を表示")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 下位足で使う価格
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
f_price() =>
    switch priceType
        "終値"  => close
        "HL2"   => hl2
        "HLC3"  => hlc3
        "OHLC4" => ohlc4

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// チャート足と下位足の判定
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
chartSec = timeframe.in_seconds(timeframe.period)
lowerSec = timeframe.in_seconds(lowerTf)

isLowerTfValid = not na(chartSec) and not na(lowerSec) and lowerSec < chartSec

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 下位足ごとの price × volume を取得
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
lowerTurnoverArray = request.security_lower_tf(
     syminfo.tickerid,
     lowerTf,
     f_price() * volume,
     ignore_invalid_timeframe = true
)

// VWAP計算用の出来高を取得
lowerVolumeArray = request.security_lower_tf(
     syminfo.tickerid,
     lowerTf,
     volume,
     ignore_invalid_timeframe = true
)

// 配列の合計
turnoverYenFromLowerTf =
     isLowerTfValid and array.size(lowerTurnoverArray) > 0
     ? array.sum(lowerTurnoverArray)
     : na

volumeFromLowerTf =
     isLowerTfValid and array.size(lowerVolumeArray) > 0
     ? array.sum(lowerVolumeArray)
     : na

// 下位足集計が使えない場合の代替:現在足の概算
fallbackTurnoverYen = f_price() * volume

turnoverYen =
     not na(turnoverYenFromLowerTf)
     ? turnoverYenFromLowerTf
     : fallbackTurnoverYen

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 日足VWAP
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
dailyVWAP =
     not na(turnoverYenFromLowerTf) and
     not na(volumeFromLowerTf) and
     volumeFromLowerTf > 0
     ? turnoverYenFromLowerTf / volumeFromLowerTf
     : f_price()

// 前日の日足VWAP
prevDayVWAP = dailyVWAP[1]

// 当日終値が前日VWAPより高い → 赤
// 当日終値が前日VWAPより低い → 青
turnoverColor =
     na(prevDayVWAP)       ? color.gray :
     close > prevDayVWAP   ? color.red :
     close < prevDayVWAP   ? color.blue :
                             color.gray

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 単位変換
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
unitDivisor =
     unitType == "円"     ? 1.0 :
     unitType == "百万円" ? 1000000.0 :
     100000000.0

turnover = turnoverYen / unitDivisor
turnoverMA = ta.sma(turnover, maLen)
turnoverRatio = turnoverMA != 0 and not na(turnoverMA) ? turnover / turnoverMA : na

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 描画
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plot(
     turnover,
     title="売買代金(日中足合計)",
     style=plot.style_columns,
     color=turnoverColor
)

plot(
     showMA ? turnoverMA : na,
     title="売買代金平均",
     linewidth=2
)

plot(
     showRatio ? turnoverRatio : na,
     title="売買代金 / 平均売買代金",
     display=display.data_window
)

// 前日VWAPをデータウィンドウに表示
plot(
     prevDayVWAP,
     title="前日VWAP",
     display=display.data_window
)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// テーブル表示
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table t = table.new(position.top_right, 2, 6, border_width=1)

if barstate.islast and showTable
    table.cell(t, 0, 0, "集計下位足")
    table.cell(t, 1, 0, lowerTf)

    table.cell(t, 0, 1, "計算価格")
    table.cell(t, 1, 1, priceType)

    table.cell(t, 0, 2, "売買代金")
    table.cell(t, 1, 2, str.tostring(turnover, "#,##0.00") + " " + unitType)

    table.cell(t, 0, 3, str.tostring(maLen) + "本平均")
    table.cell(t, 1, 3, str.tostring(turnoverMA, "#,##0.00") + " " + unitType)

    table.cell(t, 0, 4, "平均比")
    table.cell(t, 1, 4, str.tostring(turnoverRatio, "#,##0.00") + "倍")

    table.cell(t, 0, 5, "状態")
    table.cell(t, 1, 5, isLowerTfValid ? "下位足集計" : "概算表示")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// インジケーター名表示
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table indicatorNameTable = table.new(position.middle_right, 1, 1)

if barstate.islast
    table.cell(
         indicatorNameTable,
         0,
         0,
         showIndicatorName ? "売買代金" : "",
         text_color=color.white,
         text_size=size.small,
         bgcolor=color.new(color.black, 100)
    )

売買代金回転率

当日累積売買代金を時価総額で割り、売買代金回転率として表示します。普段より売買が活発かどうかを確認する補助指標です。

  • 指定時間足から当日売買代金を集計
  • 発行済株式数から時価総額を計算
  • 売買代金回転率を棒グラフ表示
  • 設定期間の平均値を表示
Pine Script v6
//@version=6
indicator(
     "売買代金回転率",
     shorttitle="売買代金回転率",
     overlay=false,
     format=format.percent,
     precision=2
     )

//────────────────────────────────────
// 設定
//────────────────────────────────────
turnoverTf = input.timeframe(
     "5",
     title="売買代金取得時間足"
     )

avgDays = input.int(
     5,
     title="平均期間(日)",
     minval=1
     )

showIndicatorName = input.bool(true, "インジケーター名を表示")

//────────────────────────────────────
// 5分足単位の当日累積売買代金
// 売買代金 ≒ HLC3 × 出来高
//────────────────────────────────────
f_dayTurnover() =>
    var float cumulativeTurnover = 0.0

    bool newDay = timeframe.change("1D")
    float barTurnover = hlc3 * volume

    if newDay
        cumulativeTurnover := barTurnover
    else
        cumulativeTurnover := nz(cumulativeTurnover[1]) + barTurnover

    cumulativeTurnover

//────────────────────────────────────
// 指定時間足から
// ①当日累積売買代金
// ②現在価格
// を取得
//────────────────────────────────────
[dayTurnover, calcPrice] = request.security(
     syminfo.tickerid,
     turnoverTf,
     [f_dayTurnover(), close],
     gaps=barmerge.gaps_off,
     lookahead=barmerge.lookahead_off,
     ignore_invalid_symbol=true
     )

//────────────────────────────────────
// 総発行株数
//────────────────────────────────────
totalShares = request.financial(
     syminfo.tickerid,
     "TOTAL_SHARES_OUTSTANDING",
     "FQ",
     ignore_invalid_symbol=true
     )

//────────────────────────────────────
// 時価総額
// 総発行株数 × 現在株価
//────────────────────────────────────
marketCap = totalShares * calcPrice

//────────────────────────────────────
// 売買代金回転率
//
// 当日累積売買代金 ÷ 時価総額 × 100
//────────────────────────────────────
turnoverRate =
     not na(marketCap) and marketCap > 0
     ? dayTurnover / marketCap * 100
     : na

//────────────────────────────────────
// 売買代金回転率の平均
// デフォルト:5日
//────────────────────────────────────
newDay = timeframe.change("1D")

var rateHistory = array.new_float()

if newDay and not na(turnoverRate[1])
    array.push(rateHistory, turnoverRate[1])

    maxHistory = avgDays - 1

    while array.size(rateHistory) > maxHistory
        array.shift(rateHistory)

float rateSum = na
int rateCount = 0

if not na(turnoverRate)
    rateSum := turnoverRate
    rateCount := 1

    if array.size(rateHistory) > 0
        for i = 0 to array.size(rateHistory) - 1
            rateSum += array.get(rateHistory, i)
            rateCount += 1

turnoverRateAvg =
     rateCount > 0
     ? rateSum / rateCount
     : na

//────────────────────────────────────
// 棒グラフ表示
//────────────────────────────────────
plot(
     turnoverRate,
     title="売買代金回転率",
     style=plot.style_columns,
     linewidth=2
     )

//────────────────────────────────────
// 平均表示
//────────────────────────────────────
plot(
     turnoverRateAvg,
     title="売買代金回転率 平均",
     linewidth=2
     )

hline(
     0,
     title="0%",
     color=color.gray
     )

//────────────────────────────────────
// インジケーター名表示
//────────────────────────────────────
var table indicatorNameTable = table.new(position.middle_right, 1, 1)

if barstate.islast
    table.cell(
         indicatorNameTable,
         0,
         0,
         showIndicatorName ? "売買代金回転率" : "",
         text_color=color.white,
         text_size=size.small,
         bgcolor=color.new(color.black, 100)
         )

RSI-BB

RSIを中心に、過熱感・ダイバージェンス・メインチャート上の高RSI/低RSIポイントを確認できるインジケーターです。RSIの基準値やマーク表示条件は設定から変更できます。

  • RSIラインをオレンジで表示
  • 70ラインを緑、50ラインを半透明グレー、30ラインを赤で表示
  • RSIが設定値以上になるとメインチャート上に緑色マークを表示(初期値70)
  • RSIが設定値以下になるとメインチャート上に赤色マークを表示(初期値30)
  • 緑・赤マークの表示条件と透明度を設定可能
  • Bull/Bearダイバージェンスを表示
  • RSI EMA・ボリンジャーバンド・BB外側ハイライトは必要に応じて表示可能
Pine Script v6
//@version=6
indicator("RSI-BB", shorttitle="RSI-BB", overlay=false, max_lines_count=500, max_labels_count=500)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Input
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
src      = input.source(close, "RSI Source")
rsiLen   = input.int(14, "RSI Length", minval=1)

emaLen   = input.int(20, "EMA Length", minval=1)
bbLen    = input.int(20, "BB Length", minval=1)
bbMult   = input.float(2.0, "BB Standard Deviation", minval=0.1, step=0.1)

// デフォルト表示:RSI、70/50/30ライン、メインチャート上のRSIマークのみ
showEma         = input.bool(false, "Show RSI EMA")
showBB          = input.bool(false, "Show Bollinger Band")
showBBHighlight = input.bool(false, "Show BB Outside Highlight")
showDiv         = input.bool(true, "Show Divergence")
pivotLen        = input.int(5, "Divergence Pivot Length", minval=1)

showLevel = input.bool(true, "Show 70 / 50 / 30 Lines")
showBounds = input.bool(false, "Show 100 / 0 Lines")

showOverboughtMark = input.bool(true, "緑色マークをメインチャートに表示")
showOversoldMark   = input.bool(true, "赤色マークをメインチャートに表示")
overboughtLevel    = input.float(70.0, "緑色マーク表示 RSI以上", minval=0, maxval=100, step=1)
oversoldLevel      = input.float(30.0, "赤色マーク表示 RSI以下", minval=0, maxval=100, step=1)
overboughtTransp   = input.int(50, "緑色マーク透明度", minval=0, maxval=100)
oversoldTransp     = input.int(50, "赤色マーク透明度", minval=0, maxval=100)

showIndicatorName = input.bool(true, "インジケーター名を表示")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// RSI / EMA / Bollinger Band
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
rsi = ta.rsi(src, rsiLen)

rsiEma = ta.ema(rsi, emaLen)

bbBasis = ta.ema(rsi, bbLen)
bbDev   = ta.stdev(rsi, bbLen) * bbMult
bbUpper = bbBasis + bbDev
bbLower = bbBasis - bbDev

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Plot
// 右側の価格スケールに表示する値はRSIのみ
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plot(rsi, "RSI", color=color.orange, linewidth=2, display=display.all)

plot(showEma ? rsiEma : na, "RSI EMA", color=color.white, linewidth=2, display=display.pane)

upperPlot = plot(showBB ? bbUpper : na, "BB Upper", color=color.new(color.gray, 100), display=display.pane)
lowerPlot = plot(showBB ? bbLower : na, "BB Lower", color=color.new(color.gray, 100), display=display.pane)

fill(upperPlot, lowerPlot, color=showBB ? color.new(color.gray, 65) : na, title="RSI BB Fill")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Level Lines
// 70=緑、50=グレー(透明度50)、30=赤
// 右側スケールには表示しない
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plot(showLevel ? 70 : na, "70 Line", color=color.green, linewidth=1, style=plot.style_line, display=display.pane)
plot(showLevel ? 50 : na, "50 Line", color=color.new(color.gray, 50), linewidth=1, style=plot.style_line, display=display.pane)
plot(showLevel ? 30 : na, "30 Line", color=color.red, linewidth=1, style=plot.style_line, display=display.pane)

plot(showBounds ? 100 : na, "100 Line", color=color.new(color.white, 85), linewidth=1, display=display.pane)
plot(showBounds ? 0 : na, "0 Line", color=color.new(color.white, 85), linewidth=1, display=display.pane)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// メインチャート RSIマーク
// RSI >= 70:緑、ローソク足の上
// RSI <= 30:赤、ローソク足の下
// デフォルト透明度:50
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
plotshape(showOverboughtMark and rsi >= overboughtLevel, title="RSI 緑色マーク", style=shape.circle, location=location.abovebar, color=color.new(color.green, overboughtTransp), size=size.small, force_overlay=true)
plotshape(showOversoldMark and rsi <= oversoldLevel, title="RSI 赤色マーク", style=shape.circle, location=location.belowbar, color=color.new(color.red, oversoldTransp), size=size.small, force_overlay=true)

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BB Outside Highlight
// デフォルト非表示
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
upperBreak = rsi > bbUpper
lowerBreak = rsi < bbLower

bgcolor(showBBHighlight and upperBreak ? color.new(color.red, 85) : na, title="RSI Above Upper BB")
bgcolor(showBBHighlight and lowerBreak ? color.new(color.green, 85) : na, title="RSI Below Lower BB")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Divergence
// Bear:価格は高値切り上げ、RSIは高値切り下げ
// Bull:価格は安値切り下げ、RSIは安値切り上げ
// 判定ピボット期間:pivotLen、デフォルト5
// デフォルト非表示
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
rsiPH = ta.pivothigh(rsi, pivotLen, pivotLen)
rsiPL = ta.pivotlow(rsi, pivotLen, pivotLen)

var float prevRsiHigh   = na
var float prevPriceHigh = na
var int   prevHighBar   = na

var float prevRsiLow    = na
var float prevPriceLow  = na
var int   prevLowBar    = na

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Bearish Divergence
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if showDiv and not na(rsiPH)
    currentRsiHigh   = rsiPH
    currentPriceHigh = high[pivotLen]
    currentHighBar   = bar_index - pivotLen

    bearDiv = not na(prevRsiHigh) and currentPriceHigh > prevPriceHigh and currentRsiHigh < prevRsiHigh

    if bearDiv
        line.new(x1=prevHighBar, y1=prevRsiHigh, x2=currentHighBar, y2=currentRsiHigh, xloc=xloc.bar_index, extend=extend.none, color=color.new(color.red, 0), style=line.style_dotted, width=2)
        label.new(x=currentHighBar, y=currentRsiHigh, text="Bear", xloc=xloc.bar_index, style=label.style_label_down, color=color.new(color.red, 25), textcolor=color.white, size=size.small)

    prevRsiHigh   := currentRsiHigh
    prevPriceHigh := currentPriceHigh
    prevHighBar   := currentHighBar

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Bullish Divergence
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if showDiv and not na(rsiPL)
    currentRsiLow   = rsiPL
    currentPriceLow = low[pivotLen]
    currentLowBar   = bar_index - pivotLen

    bullDiv = not na(prevRsiLow) and currentPriceLow < prevPriceLow and currentRsiLow > prevRsiLow

    if bullDiv
        line.new(x1=prevLowBar, y1=prevRsiLow, x2=currentLowBar, y2=currentRsiLow, xloc=xloc.bar_index, extend=extend.none, color=color.new(color.lime, 0), style=line.style_dotted, width=2)
        label.new(x=currentLowBar, y=currentRsiLow, text="Bull", xloc=xloc.bar_index, style=label.style_label_up, color=color.new(color.green, 25), textcolor=color.white, size=size.small)

    prevRsiLow   := currentRsiLow
    prevPriceLow := currentPriceLow
    prevLowBar   := currentLowBar

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// Alert
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(ta.crossover(rsi, rsiEma), title="RSI Cross Up EMA", message="RSI crossed above EMA")
alertcondition(ta.crossunder(rsi, rsiEma), title="RSI Cross Down EMA", message="RSI crossed below EMA")
alertcondition(upperBreak, title="RSI Above Upper BB", message="RSI is above upper Bollinger Band")
alertcondition(lowerBreak, title="RSI Below Lower BB", message="RSI is below lower Bollinger Band")
alertcondition(rsi >= 70, title="RSI 70以上", message="RSI is 70 or above")
alertcondition(rsi <= 30, title="RSI 30以下", message="RSI is 30 or below")

//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// インジケーター名表示
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table indicatorNameTable = table.new(position.middle_right, 1, 1)

if barstate.islast
    table.cell(indicatorNameTable, 0, 0, showIndicatorName ? "RSI" : "", text_color=color.white, text_size=size.small, bgcolor=color.new(color.black, 100))
本ページのインジケーターは情報提供・学習目的です。表示・計算結果の完全性や正確性を保証するものではありません。投資判断は公式情報や取引所情報なども確認したうえで、ご自身の責任で行ってください。
また、インジケーターの無料ダウンロード・無料配布は予告なく停止する場合があります。
ストップ高研究所
タイトルとURLをコピーしました