MTF ATR(1H,4H,1D,1W,1M) by ogudora v4

ogudora0812 · study · 970 行 · 点赞 13 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//Made by @yohei ogura with <3
//Modified for MTF (Multi-Timeframe) Supertrend
//Enhanced with Advanced Features & ATH Finder
//v2: Overheating Line改修 - 前日確定ATR基準 + タッチシグナル + ステータステーブル
//v3: 週足/月足Supertrend追加
//v4: 統合ステータステーブル(過熱テーブル置換)+ BRK列 + 1W/1Mシグナル日足スイッチ
//v5: テーブル改修 - BRK列廃止 → 100株損失 / 旧サポ凍結 / 逸失% 追加
//v6: テーブル改修 - ↑↓→UP/DN / 過熱・VWAP廃止 / ATR%列追加(1Dのみ) / 高値落ち列追加
//v6.1: ATH描画バッファ超過エラー修正 + max_bars_back宣言追加
//v7: 1D追加ライン(1.5×/2.0×) + 過熱ライン既定1.6・薄緑 + 旧サポライン + 過熱タッチアラート
//v7.1: 勉強会配布向け調整(2026/08/04)
//    - 旧サポライン: 点線表示・既定OFF(終値>=旧サポ=緑/未満=赤。王道は 1d⚡ Break)
//    - 過熱タッチシグナルの色をラインと同色(薄緑)に統一
//    - 配色調整: 4H DNライン=明るい紫 / 1W DNライン=明るいピンク
//    - Highlighter 濃度の既定を濃いめに変更(1H=96 / 4H=90 / 1D=90 / 1W=94)
//      ※入力化するとTVが「非定数色」としてプロット枠を余分に消費し64制限を超えるため
//        固定値で埋め込み。個別調整は Style タブで行うこと
//v7.2: プロット64制限対策(alertcondition もプロット枠にカウントされるため)
//    - 2.0×ライン削除(1.5×は継続、色 #056656)
//    - 1M Warning/Break の alertcondition 削除(チャート上のシグナル表示は継続)
//v7.3: (2026/08/04)
//    - 過熱ライン: plot方式に戻し「直近20本のみ」描画(line.new が表示されない環境があるため)
//    - 1.5×ライン シグナル追加: 1D(1.0)の実装踏襲、表記 1d-d⚠️ / 1d-d⚡
//    - Highlighter を実測値に更新: 4H up #7b1fa2/透過49・dn #4e0f60/97、
//      1D up #4caf50/77・dn #8c101a/57、1W up #a5d6a7/86・dn #f23645/83
//    - 枠確保のため 1W Warning/Break の alertcondition と 1M トレンド転換サークルを削除
//v7.4: 過熱ラインを従来の全期間描画に戻す(直近20本方式は断片が浮くため撤回)。
//      ラベル上限500対策: 過熱の値ラベル廃止・1.5×ラベルは頻度半減
//v7.5: 1.5× Down ライン追加(#490c11、シグナル 1d-2⚡ も同色)/ 表記 1d-d → 1d-2 /
//      旧サポの赤を 1.0 と同じ #8c101a に・タイトル変更で circle 既定を再適用
//v7.6: (2026/09/01)
//    - 「Hide All ATR Lines on Daily+」を追加(既定ON): 日足以上では ATR系ライン・
//      始点●・[xx ATR]ラベル・過熱ライン・1.5×/2.0×・旧サポを一切描画しない。
//      Highlighter(塗り)はそのまま。Warning/Break シグナルと ATH ラインは従来のスイッチ通り
//    - 2.0× Up/Down ライン復活(既定ON、色 Up #00897b / Down #7a1f2a)。
//      プロット枠確保のため「Current TF Supertrend」(既定OFFだった2枠)を削除して充当。
//      2.0× は表示のみ(始点●なし・シグナルなし)。1.5× も始点●なし、1M も●なし(v7.3で削除済)
//v7.6.1: プロット65になりRE10140が発生したため3枠削減(→62/64、余裕2枠)
//    - 過熱タッチ🔥 と 1d-2⚠️/⚡ を plotshape → label.new に変換。
//      label.new はプロット枠(64)を消費せずラベル上限(500)側でカウントされるため。
//      表示位置・色は同じ。副作用: Styleタブに項目が出なくなる(入力でON/OFF)・
//      画面に残る履歴は直近500個まで(シグナルは稀なので実用上問題なし)
//    - さらに枠が必要になったら 1W/1M シグナルも同様に label.new 化で各2枠ずつ解放可能
//v7.6.2: 「Hide Highlighter below Daily」追加(既定ON): 日足未満ではHighlighter(塗り)を
//      全TF無効に。日足以上=塗り / 日足未満=ライン という役割分担になる。
//      条件変更のみでプロット枠の増減なし(62/64のまま)
//v7.6.3: 過熱の日足非表示を修正。v7.6で「Hide All ATR Lines on Daily+」(linesOK)を
//      過熱ラインにも掛けたため、グループ側の設定と競合して日足で消えていた。
//      過熱ライン・🔥タッチは linesOK の対象外に戻し「Overheating Line v2」グループ専用で制御。
//      あわせて同グループの Hide Line/Signals on Daily+ の既定を OFF に変更(日足でも表示)
//v7.6.4: Highlighter 既定色を実測値(Styleタブでの本人調整)に更新:
//      1D up #5cd73c/不透明度39%(透過61) ・ 1D dn #f7525f/70%(透過30)
//      1W up #66bb6a/34%(透過66) ・ 1W dn #e91e63/48%(透過52)
//      ※v7.1の経緯通り fill の色は入力化せず固定値で埋め込み(非定数色によるプロット枠消費を回避)。
//        微調整は従来通り Style タブで
//v7.6.5: シグナル表記の整理と暗色修正
//    - 1.5×シグナルの表記を 1d-2 → 1d-1.5 に変更(v7.5当時は追加ラインが1.5のみだった名残)
//    - 2.0×ライン用シグナル 1d-2⚠️/⚡ を新設(1.5×の実装踏襲・label.new方式でプロット枠消費なし)
//    - Down既定色を明るく: 1.5× #490c11 → #ef5350(明るい赤) / 2.0× #7a1f2a → #ff8a65(橙赤)
//v7.6.6: (2026-09-05)
//    - Down色は明色をやめ「乗数が大きいほど暗い赤」のグラデーションに:
//      1.0 #8c101a(既存) → 1.5 #6e0d15 → 2.0 #500a10
//    - 1d-1.5⚠️⚡ / 1d-2⚠️⚡ シグナルにON/OFF入力を新設し既定OFF(ごちゃつき対策。ラインは既定ONのまま)
//    - 1.5×/2.0×の線名ラベルをDown側にも表示(従来はUp側のみで線の正体が分からなかった)。
//      表記を [1D1.5 ATR] / [1D2.0 ATR] に統一(他TFの [1D ATR] 系と同形式)
//v7.6.7: (2026-09-05)
//    - Down色のグラデーション(暗赤3段階)は1.5と2.0の判別が困難→v7.6.5の配色に戻す:
//      1.5× #ef5350(明るい赤) / 2.0× #ff8a65(橙赤)
//    - 1.5×/2.0×はシグナルだけでなくライン表示も既定OFFに(使う時だけON)
//v7.6.8: (2026-09-05)
//    - マスタースイッチ「Show 1.5×/2.0×」を新設(既定OFF)。1.5以上のライン・シグナルを一括ON/OFF。
//      個別スイッチはマスターON時の絞り込み用(ライン既定ON・シグナル既定OFF)に戻した。
//      新設入力のため既存チャートにも既定OFFが即適用され、リセット不要で非表示になる
//v7.6.9: (2026-10-17) 既定値を実運用設定に合わせて変更(ロジック変更なし)
//    - Master Highlighter: ON → OFF
//    - Hide All ATR Lines on Daily+: ON → OFF
//    - 過熱 Hide Signals on Daily+ / Hide Line on Daily+: OFF → ON
//    - Show 1.5×/2.0× (マスター): OFF → ON / Show 1D 1.5× Line: ON → OFF
 
//@version=6
indicator('MTF ATR(1H,4H,1D,1W,1M) by ogudora v4', shorttitle = 'MTF ATR(1H,4H,1D,1W,1M) by ogudora v4', overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back = 500)
 
// ============================================================================
// Master Highlighter Control
// ============================================================================
masterHighlighter = input.bool(title = 'Master Highlighter (All Timeframes)', defval = false, group = 'Master Control')
masterSignals = input.bool(title = 'Master Signals (All Timeframes)', defval = true, group = 'Master Control')
masterUpTrend = input.bool(title = 'Master Up Trend Lines & Circles (All Timeframes)', defval = true, group = 'Master Control')
masterDownTrend = input.bool(title = 'Master Down Trend Lines & Circles (All Timeframes)', defval = true, group = 'Master Control')
 
// ============================================================================
// Timeframe Control
// ============================================================================
hideOnDailyOrAbove = input.bool(title = 'Hide Indicators on Daily+ (except 1D/1W ATR)', defval = true, group = 'Timeframe Control')
show1W1MSignalsOnDaily = input.bool(title = 'Show 1W/1M Signals on Daily+ (日足以上で1W/1Mシグナル表示)', defval = false, group = 'Timeframe Control')
hideAllLinesOnDaily = input.bool(title = 'Hide All ATR Lines on Daily+ (日足以上でライン・●・ラベル非表示、Highlighterは維持)', defval = false, group = 'Timeframe Control')
hideHighlighterIntraday = input.bool(title = 'Hide Highlighter below Daily (日足未満でHighlighter非表示)', defval = true, group = 'Timeframe Control')
 
isDailyOrAbove = timeframe.isdaily or timeframe.isweekly or timeframe.ismonthly
showOnChart = not(hideOnDailyOrAbove and isDailyOrAbove)
show1DOnChart = true
show1WOnChart = true
show1W1MSignals = not isDailyOrAbove or show1W1MSignalsOnDaily
linesOK = not(hideAllLinesOnDaily and isDailyOrAbove) // v7.6: ライン・●・ラベルの描画可否(塗りは対象外)
hlOK = not(hideHighlighterIntraday and not isDailyOrAbove) // v7.6.2: Highlighter(塗り)の描画可否
 
// ============================================================================
// ATH Finder Settings
// ============================================================================
showATH = input.bool(title = 'Show ATH Line', defval = true, group = 'ATH Finder')
showATHLabel = input.bool(title = 'Show ATH Label', defval = true, group = 'ATH Finder')
athLineColor = input.color(title = 'ATH Line Color', defval = color.new(color.lime, 0), group = 'ATH Finder')
athLineWidth = input.int(title = 'ATH Line Width', defval = 2, minval = 1, maxval = 5, group = 'ATH Finder')
 
// ============================================================================
// Overheating Line Settings (v7: 既定1.6=EXIT-1 P90再較正、色=薄緑)
// ============================================================================
showOverheatingLine = input.bool(title = 'Show Overheating Line', defval = true, group = 'Overheating Line v2')
overheatingMultiplier = input.float(title = 'Overheating Multiplier', defval = 1.6, step = 0.1, group = 'Overheating Line v2')
overheatingColor = input.color(title = 'Overheating Line Color (薄緑)', defval = color.new(#a5d6a7, 0), group = 'Overheating Line v2')
showOverheatingSignal = input.bool(title = 'Show Touch Signal', defval = false, group = 'Overheating Line v2')
hideSignalOnDaily = input.bool(title = 'Hide Signals on Daily+ (日足以上で非表示)', defval = true, group = 'Overheating Line v2')
hideLineOnDaily = input.bool(title = 'Hide Line on Daily+ (日足以上でライン非表示)', defval = true, group = 'Overheating Line v2')
 
// シグナル表示条件
showOHSignals = showOverheatingSignal and not(hideSignalOnDaily and isDailyOrAbove)
// v7.6.3: 過熱は Hide All ATR Lines on Daily+ (linesOK) の対象外。このグループの設定のみで制御
showOHLine = not(hideLineOnDaily and isDailyOrAbove)
 
// ============================================================================
// v7: 1D Extra Lines(表示専用。ハイライト/シグナルなし ※1.5×のみシグナルあり)
// ============================================================================
showExtraLines = input.bool(title = 'Show 1.5×/2.0× (マスター・1.5以上をまとめてON/OFF)', defval = true, group = '1D Extra Lines v7')
showLine15 = input.bool(title = 'Show 1D 1.5× Line (深緑)', defval = false, group = '1D Extra Lines v7')
mult15 = input.float(title = 'Multiplier A', defval = 1.5, step = 0.05, group = '1D Extra Lines v7')
color15 = input.color(title = 'Color A Up (深緑)', defval = color.new(#056656, 0), group = '1D Extra Lines v7')
color15dn = input.color(title = 'Color A Down (明るい赤)', defval = color.new(#ef5350, 0), group = '1D Extra Lines v7')
showSig15 = input.bool(title = 'Show 1.5× Signals (1d-1.5⚠️⚡)', defval = false, group = '1D Extra Lines v7')
showLine20 = input.bool(title = 'Show 1D 2.0× Line (青緑)', defval = true, group = '1D Extra Lines v7')
mult20 = input.float(title = 'Multiplier B', defval = 2.0, step = 0.05, group = '1D Extra Lines v7')
color20 = input.color(title = 'Color B Up (青緑)', defval = color.new(#00897b, 0), group = '1D Extra Lines v7')
color20dn = input.color(title = 'Color B Down (橙赤)', defval = color.new(#ff8a65, 0), group = '1D Extra Lines v7')
showSig20 = input.bool(title = 'Show 2.0× Signals (1d-2⚠️⚡)', defval = false, group = '1D Extra Lines v7')
showKyuSapoMark = input.bool(title = 'Show 旧サポライン (1D DN中・点線)', defval = false, group = '1D Extra Lines v7')
 
// v7.6.8: マスター×個別の合成(マスターOFFなら1.5×/2.0×のライン・シグナルは全て非表示)
show15on = showExtraLines and showLine15
show20on = showExtraLines and showLine20
sig15on = showExtraLines and showSig15
sig20on = showExtraLines and showSig20
 
// ============================================================================
// 統合ステータステーブル Settings
// ============================================================================
showStatusTable = input.bool(title = 'Show Status Table', defval = false, group = 'Status Table')
 
// ============================================================================
// ATH Finder Logic  ★v6.1修正: バッファ超過エラー対策
// ============================================================================
var float ath = na
var int ath_bar = na
var line ath_line = na
var label ath_label = na
 
if high > ath or na(ath)
    ath := high
    ath_bar := bar_index
    ath_bar
 
if showATH and barstate.islast
    if not na(ath_line)
        line.delete(ath_line)
    if not na(ath_label)
        label.delete(ath_label)
 
    // ★v6.1修正: 利用可能な過去バー数を bar_index で頭打ちにしてバッファ超過を防止
    max_lookback = math.min(499, bar_index)
    line_start_bar = math.max(ath_bar, bar_index - max_lookback)
    line_end_bar = bar_index == ath_bar ? bar_index + 1 : bar_index
    ath_line := line.new(line_start_bar, ath, line_end_bar, ath, width = athLineWidth, color = athLineColor, extend = extend.right, style = line.style_solid)
 
    if showATHLabel
        is_current_ath = high == ath and bar_index == ath_bar
        label_x = is_current_ath ? bar_index : bar_index + 5
        label_y = ath + ath * 0.01
        label_style = is_current_ath ? label.style_label_lower_left : label.style_label_left
        label_color = is_current_ath ? color.new(color.lime, 0) : color.new(color.red, 0)
        ath_label := label.new(label_x, label_y, text = 'ATH: ' + str.tostring(ath, '#.##'), style = label_style, color = label_color, textcolor = color.white, size = size.small)
        ath_label
 
// ============================================================================
// v7.6: Current TF Supertrend は削除(プロット2枠を 2.0× ラインへ充当)
// ============================================================================
 
// ============================================================================
// MTF Supertrend - 1 Hour
// ============================================================================
show1H = input.bool(title = 'Show 1H Supertrend', defval = true, group = 'MTF 1 Hour Supertrend')
Periods1H = input.int(title = 'ATR Period', defval = 10, group = 'MTF 1 Hour Supertrend')
Multiplier1H = input.float(title = 'ATR Multiplier', step = 0.1, defval = 1.0, group = 'MTF 1 Hour Supertrend')
changeATR1H = input.bool(title = 'Change ATR Calculation Method ?', defval = true, group = 'MTF 1 Hour Supertrend')
showLabel1H = input.bool(title = 'Show Label', defval = true, group = 'MTF 1 Hour Supertrend')
showSignals1H = input.bool(title = 'Show Warning/Break Signals ?', defval = true, group = 'MTF 1 Hour Supertrend')
highlighting1H = input.bool(title = 'Highlighter On/Off ?', defval = true, group = 'MTF 1 Hour Supertrend')
 
[atr1H, hl2_1H, close1H] = request.security(syminfo.tickerid, '60', [changeATR1H ? ta.atr(Periods1H) : ta.sma(ta.tr, Periods1H), hl2, close], lookahead = barmerge.lookahead_off)
 
var float up1H = na
var float dn1H = na
var int trend1H = 1
 
up1H_calc = hl2_1H - Multiplier1H * atr1H
up1H := na(up1H[1]) ? up1H_calc : close1H[1] > up1H[1] ? math.max(up1H_calc, up1H[1]) : up1H_calc
 
dn1H_calc = hl2_1H + Multiplier1H * atr1H
dn1H := na(dn1H[1]) ? dn1H_calc : close1H[1] < dn1H[1] ? math.min(dn1H_calc, dn1H[1]) : dn1H_calc
 
trend1H := na(trend1H[1]) ? 1 : trend1H[1] == -1 and close1H > dn1H[1] ? 1 : trend1H[1] == 1 and close1H < up1H[1] ? -1 : trend1H[1]
 
var float lastUp1H = na
if trend1H == -1 and trend1H[1] == 1
    lastUp1H := up1H[1]
    lastUp1H
if trend1H == 1
    lastUp1H := na
    lastUp1H
 
plot(masterUpTrend and showOnChart and linesOK and show1H and trend1H == 1 ? up1H : na, title = '1H Up Trend', style = plot.style_linebr, linewidth = 3, color = color.new(#1848cc, 0))
plot(masterDownTrend and showOnChart and linesOK and show1H and trend1H == -1 ? dn1H : na, title = '1H Down Trend', style = plot.style_linebr, linewidth = 2, color = color.new(#210ba2, 0))
 
trend1H_changed = trend1H != trend1H[1]
plotshape(masterUpTrend and showOnChart and linesOK and show1H and trend1H_changed and trend1H == 1 ? up1H : na, title = '1H UpTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#1848cc, 0))
plotshape(masterDownTrend and showOnChart and linesOK and show1H and trend1H_changed and trend1H == -1 ? dn1H : na, title = '1H DownTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#210ba2, 0))
 
var int warning1H_time = 0
var int break1H_time = 0
var int trend1H_change_time = 0
 
if trend1H_changed == true
    trend1H_change_time := time
    trend1H_change_time
 
timeSinceTrendChange1H = (time - trend1H_change_time) / 60000
 
warning1H = trend1H == 1 and close < up1H and time - warning1H_time >= 14400000 and (timeSinceTrendChange1H <= 10 or trend1H == 1)
break1H = trend1H == -1 and close > dn1H and time - break1H_time >= 3600000 and (timeSinceTrendChange1H <= 10 or trend1H == -1)
 
if warning1H == true
    warning1H_time := time
    warning1H_time
 
if break1H == true
    break1H_time := time
    break1H_time
 
plotshape(masterSignals and showOnChart and showSignals1H and warning1H ? up1H : na, title = '1H Warning', text = '1hr⚠️', location = location.absolute, style = shape.labeldown, size = size.small, color = color.new(#1848cc, 0), textcolor = color.new(color.white, 0))
plotshape(masterSignals and showOnChart and showSignals1H and break1H ? dn1H : na, title = '1H Break', text = '1hr⚡', location = location.absolute, style = shape.labelup, size = size.small, color = color.new(#210ba2, 0), textcolor = color.new(color.white, 0))
 
if show1H and showOnChart and linesOK and showLabel1H and bar_index % 20 == 0
    if trend1H == 1
        label.new(bar_index, up1H, text = '[1H ATR]', style = label.style_none, textcolor = color.new(#1848cc, 0), size = size.tiny, yloc = yloc.price)
    else
        label.new(bar_index, dn1H, text = '[1H ATR]', style = label.style_none, textcolor = color.new(#210ba2, 0), size = size.tiny, yloc = yloc.price)
 
upPlot1H = plot(masterHighlighter and hlOK and showOnChart and show1H and highlighting1H and trend1H == 1 ? up1H : na, title = '1H Up Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#1848cc, 0), display = display.none)
dnPlot1H = plot(masterHighlighter and hlOK and showOnChart and show1H and highlighting1H and trend1H == -1 ? dn1H : na, title = '1H Down Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#210ba2, 0), display = display.none)
pricePlot1H = plot(masterHighlighter and hlOK and showOnChart and show1H and highlighting1H ? close : na, title = 'Price Fill 1H', style = plot.style_linebr, linewidth = 1, display = display.none)
fill(pricePlot1H, upPlot1H, color = color.new(#1848cc, 96), title = '1H Up Trend Highlighter')
fill(pricePlot1H, dnPlot1H, color = color.new(#210ba2, 96), title = '1H Down Trend Highlighter')
 
// ============================================================================
// MTF Supertrend - 4 Hour
// ============================================================================
show4H = input.bool(title = 'Show 4H Supertrend', defval = true, group = 'MTF 4 Hour Supertrend')
Periods4H = input.int(title = 'ATR Period', defval = 10, group = 'MTF 4 Hour Supertrend')
Multiplier4H = input.float(title = 'ATR Multiplier', step = 0.1, defval = 1.0, group = 'MTF 4 Hour Supertrend')
changeATR4H = input.bool(title = 'Change ATR Calculation Method ?', defval = true, group = 'MTF 4 Hour Supertrend')
showLabel4H = input.bool(title = 'Show Label', defval = true, group = 'MTF 4 Hour Supertrend')
showSignals4H = input.bool(title = 'Show Warning/Break Signals ?', defval = true, group = 'MTF 4 Hour Supertrend')
highlighting4H = input.bool(title = 'Highlighter On/Off ?', defval = true, group = 'MTF 4 Hour Supertrend')
 
[atr4H, hl2_4H, close4H] = request.security(syminfo.tickerid, '240', [changeATR4H ? ta.atr(Periods4H) : ta.sma(ta.tr, Periods4H), hl2, close], lookahead = barmerge.lookahead_off)
 
var float up4H = na
var float dn4H = na
var int trend4H = 1
 
up4H_calc = hl2_4H - Multiplier4H * atr4H
up4H := na(up4H[1]) ? up4H_calc : close4H[1] > up4H[1] ? math.max(up4H_calc, up4H[1]) : up4H_calc
 
dn4H_calc = hl2_4H + Multiplier4H * atr4H
dn4H := na(dn4H[1]) ? dn4H_calc : close4H[1] < dn4H[1] ? math.min(dn4H_calc, dn4H[1]) : dn4H_calc
 
trend4H := na(trend4H[1]) ? 1 : trend4H[1] == -1 and close4H > dn4H[1] ? 1 : trend4H[1] == 1 and close4H < up4H[1] ? -1 : trend4H[1]
 
var float lastUp4H = na
if trend4H == -1 and trend4H[1] == 1
    lastUp4H := up4H[1]
    lastUp4H
if trend4H == 1
    lastUp4H := na
    lastUp4H
 
plot(masterUpTrend and showOnChart and linesOK and show4H and trend4H == 1 ? up4H : na, title = '4H Up Trend', style = plot.style_linebr, linewidth = 3, color = color.new(#7b1fa2, 0))
plot(masterDownTrend and showOnChart and linesOK and show4H and trend4H == -1 ? dn4H : na, title = '4H Down Trend', style = plot.style_linebr, linewidth = 2, color = color.new(#ba68c8, 0))
 
trend4H_changed = trend4H != trend4H[1]
plotshape(masterUpTrend and showOnChart and linesOK and show4H and trend4H_changed and trend4H == 1 ? up4H : na, title = '4H UpTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#7b1fa2, 0))
plotshape(masterDownTrend and showOnChart and linesOK and show4H and trend4H_changed and trend4H == -1 ? dn4H : na, title = '4H DownTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#ba68c8, 0))
 
var int warning4H_time = 0
var int break4H_time = 0
var int warning4H_count = 0
var int break4H_count = 0
var int trend4H_change_time = 0
 
if bool(ta.change(time('D')))
    warning4H_count := 0
    break4H_count := 0
    break4H_count
 
if trend4H_changed == true
    trend4H_change_time := time
    trend4H_change_time
 
timeSinceTrendChange4H = (time - trend4H_change_time) / 60000
 
warning4H = trend4H == 1 and close < up4H and time - warning4H_time >= 14400000 and warning4H_count < 2 and (timeSinceTrendChange4H <= 10 or trend4H == 1)
break4H = trend4H == -1 and close > dn4H and time - break4H_time >= 3600000 and break4H_count < 2 and (timeSinceTrendChange4H <= 10 or trend4H == -1)
 
if warning4H == true
    warning4H_time := time
    warning4H_count := warning4H_count + 1
    warning4H_count
 
if break4H == true
    break4H_time := time
    break4H_count := break4H_count + 1
    break4H_count
 
plotshape(masterSignals and showOnChart and showSignals4H and warning4H ? up4H : na, title = '4H Warning', text = '4hr⚠️', location = location.absolute, style = shape.labeldown, size = size.normal, color = color.new(#7b1fa2, 0), textcolor = color.new(color.white, 0))
plotshape(masterSignals and showOnChart and showSignals4H and break4H ? dn4H : na, title = '4H Break', text = '4hr⚡', location = location.absolute, style = shape.labelup, size = size.normal, color = color.new(#ba68c8, 0), textcolor = color.new(color.white, 0))
 
if show4H and showOnChart and linesOK and showLabel4H and bar_index % 30 == 0
    if trend4H == 1
        label.new(bar_index, up4H, text = '[4H ATR]', style = label.style_none, textcolor = color.new(#7b1fa2, 0), size = size.tiny, yloc = yloc.price)
    else
        label.new(bar_index, dn4H, text = '[4H ATR]', style = label.style_none, textcolor = color.new(#ba68c8, 0), size = size.tiny, yloc = yloc.price)
 
upPlot4H = plot(masterHighlighter and hlOK and showOnChart and show4H and highlighting4H and trend4H == 1 ? up4H : na, title = '4H Up Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#7b1fa2, 0), display = display.none)
dnPlot4H = plot(masterHighlighter and hlOK and showOnChart and show4H and highlighting4H and trend4H == -1 ? dn4H : na, title = '4H Down Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#ba68c8, 0), display = display.none)
pricePlot4H = plot(masterHighlighter and hlOK and showOnChart and show4H and highlighting4H ? close : na, title = 'Price Fill 4H', style = plot.style_linebr, linewidth = 1, display = display.none)
fill(pricePlot4H, upPlot4H, color = color.new(#7b1fa2, 49), title = '4H Up Trend Highlighter')
fill(pricePlot4H, dnPlot4H, color = color.new(#4e0f60, 97), title = '4H Down Trend Highlighter')
 
// ============================================================================
// MTF Supertrend - 1 Day (前日確定データ for ATR Line)
// ============================================================================
show1D = input.bool(title = 'Show 1D Supertrend', defval = true, group = 'MTF 1 Day Supertrend')
Periods1D = input.int(title = 'ATR Period', defval = 10, group = 'MTF 1 Day Supertrend')
Multiplier1D = input.float(title = 'ATR Multiplier', step = 0.1, defval = 1.0, group = 'MTF 1 Day Supertrend')
changeATR1D = input.bool(title = 'Change ATR Calculation Method ?', defval = true, group = 'MTF 1 Day Supertrend')
showLabel1D = input.bool(title = 'Show Label', defval = true, group = 'MTF 1 Day Supertrend')
showSignals1D = input.bool(title = 'Show Warning/Break Signals ?', defval = true, group = 'MTF 1 Day Supertrend')
highlighting1D = input.bool(title = 'Highlighter On/Off ?', defval = true, group = 'MTF 1 Day Supertrend')
 
[atr1D_prev, hl2_1D_prev, close1D_prev] = request.security(syminfo.tickerid, 'D', [changeATR1D ? ta.atr(Periods1D) : ta.sma(ta.tr, Periods1D), hl2, close], lookahead = barmerge.lookahead_off)
 
[atr1D_current, hl2_1D_current, close1D_current] = request.security(syminfo.tickerid, 'D', [changeATR1D ? ta.atr(Periods1D) : ta.sma(ta.tr, Periods1D), hl2, close], lookahead = barmerge.lookahead_on)
 
var float up1D = na
var float dn1D = na
var int trend1D = 1
 
up1D_calc = hl2_1D_prev - Multiplier1D * atr1D_prev
up1D := na(up1D[1]) ? up1D_calc : close1D_prev[1] > up1D[1] ? math.max(up1D_calc, up1D[1]) : up1D_calc
 
dn1D_calc = hl2_1D_prev + Multiplier1D * atr1D_prev
dn1D := na(dn1D[1]) ? dn1D_calc : close1D_prev[1] < dn1D[1] ? math.min(dn1D_calc, dn1D[1]) : dn1D_calc
 
trend1D := na(trend1D[1]) ? 1 : trend1D[1] == -1 and close1D_prev > dn1D[1] ? 1 : trend1D[1] == 1 and close1D_prev < up1D[1] ? -1 : trend1D[1]
 
var float lastUp1D = na
if trend1D == -1 and trend1D[1] == 1
    lastUp1D := up1D[1]
    lastUp1D
if trend1D == 1
    lastUp1D := na
    lastUp1D
 
plot(masterUpTrend and show1DOnChart and linesOK and show1D and trend1D == 1 ? up1D : na, title = '1D Up Trend', style = plot.style_linebr, linewidth = 3, color = color.new(#4caf50, 0))
plot(masterDownTrend and show1DOnChart and linesOK and show1D and trend1D == -1 ? dn1D : na, title = '1D Down Trend', style = plot.style_linebr, linewidth = 2, color = color.new(#8c101a, 0))
 
// ============================================================================
// v7: 1D 見せライン(乗数1.5、前日確定基準・表示のみ)
// ============================================================================
var float up15_1D = na
var float dn15_1D = na
var int trend15_1D = 1
 
up15_calc = hl2_1D_prev - mult15 * atr1D_prev
up15_1D := na(up15_1D[1]) ? up15_calc : close1D_prev[1] > up15_1D[1] ? math.max(up15_calc, up15_1D[1]) : up15_calc
 
dn15_calc = hl2_1D_prev + mult15 * atr1D_prev
dn15_1D := na(dn15_1D[1]) ? dn15_calc : close1D_prev[1] < dn15_1D[1] ? math.min(dn15_calc, dn15_1D[1]) : dn15_calc
 
trend15_1D := na(trend15_1D[1]) ? 1 : trend15_1D[1] == -1 and close1D_prev > dn15_1D[1] ? 1 : trend15_1D[1] == 1 and close1D_prev < up15_1D[1] ? -1 : trend15_1D[1]
 
// 1.5×ライン: Up/Down 両側描画(ハイライトなし・始点●なし)
plot(show1DOnChart and linesOK and show1D and show15on and trend15_1D == 1 ? up15_1D : na, title = '1D 1.5× Up', style = plot.style_linebr, linewidth = 2, color = color15)
plot(show1DOnChart and linesOK and show1D and show15on and trend15_1D == -1 ? dn15_1D : na, title = '1D 1.5× Down', style = plot.style_linebr, linewidth = 2, color = color15dn)
 
// ラベル上限(500)対策: 1.5×/2.0×ラベルの頻度は他TFの半分。v7.6.6: Down側にも線名を表示
if show1DOnChart and linesOK and show1D and show15on and bar_index % 80 == 20
    if trend15_1D == 1
        label.new(bar_index, up15_1D, text = '[1D1.5 ATR]', style = label.style_none, textcolor = color15, size = size.tiny, yloc = yloc.price)
    else
        label.new(bar_index, dn15_1D, text = '[1D1.5 ATR]', style = label.style_none, textcolor = color15dn, size = size.tiny, yloc = yloc.price)
 
// ============================================================================
// v7.6: 1D 見せライン(乗数2.0、前日確定基準・表示のみ・始点●なし・シグナルなし)
// ============================================================================
var float up20_1D = na
var float dn20_1D = na
var int trend20_1D = 1
 
up20_calc = hl2_1D_prev - mult20 * atr1D_prev
up20_1D := na(up20_1D[1]) ? up20_calc : close1D_prev[1] > up20_1D[1] ? math.max(up20_calc, up20_1D[1]) : up20_calc
 
dn20_calc = hl2_1D_prev + mult20 * atr1D_prev
dn20_1D := na(dn20_1D[1]) ? dn20_calc : close1D_prev[1] < dn20_1D[1] ? math.min(dn20_calc, dn20_1D[1]) : dn20_calc
 
trend20_1D := na(trend20_1D[1]) ? 1 : trend20_1D[1] == -1 and close1D_prev > dn20_1D[1] ? 1 : trend20_1D[1] == 1 and close1D_prev < up20_1D[1] ? -1 : trend20_1D[1]
 
plot(show1DOnChart and linesOK and show1D and show20on and trend20_1D == 1 ? up20_1D : na, title = '1D 2.0× Up', style = plot.style_linebr, linewidth = 2, color = color20)
plot(show1DOnChart and linesOK and show1D and show20on and trend20_1D == -1 ? dn20_1D : na, title = '1D 2.0× Down', style = plot.style_linebr, linewidth = 2, color = color20dn)
 
if show1DOnChart and linesOK and show1D and show20on and bar_index % 80 == 60
    if trend20_1D == 1
        label.new(bar_index, up20_1D, text = '[1D2.0 ATR]', style = label.style_none, textcolor = color20, size = size.tiny, yloc = yloc.price)
    else
        label.new(bar_index, dn20_1D, text = '[1D2.0 ATR]', style = label.style_none, textcolor = color20dn, size = size.tiny, yloc = yloc.price)
 
// ============================================================================
// v7.3: 1.5×ライン シグナル(1Dの実装踏襲。v7.6.5で表記 1d-2 → 1d-1.5 に変更)
// ============================================================================
trend15_changed = trend15_1D != trend15_1D[1]
 
var int warning15_time = 0
var int break15_time = 0
var int warning15_count = 0
var int break15_count = 0
var int trend15_change_time = 0
 
if bool(ta.change(time('D')))
    warning15_count := 0
    break15_count := 0
    break15_count
 
if trend15_changed == true
    trend15_change_time := time
    trend15_change_time
 
timeSinceTrendChange15 = (time - trend15_change_time) / 60000
 
warning15 = trend15_1D == 1 and close < up15_1D and time - warning15_time >= 14400000 and warning15_count < 2 and (timeSinceTrendChange15 <= 10 or trend15_1D == 1)
break15 = trend15_1D == -1 and close > dn15_1D and time - break15_time >= 3600000 and break15_count < 2 and (timeSinceTrendChange15 <= 10 or trend15_1D == -1)
 
if warning15 == true
    warning15_time := time
    warning15_count := warning15_count + 1
    warning15_count
 
if break15 == true
    break15_time := time
    break15_count := break15_count + 1
    break15_count
 
// v7.6.1: plotshape → label.new (プロット枠2枠解放。位置・色は従来と同じ)
if masterSignals and show1DOnChart and show1D and sig15on and warning15
    label.new(bar_index, up15_1D, text = '1d-1.5⚠️', style = label.style_label_down, color = color15, textcolor = color.new(color.white, 0), size = size.normal)
if masterSignals and show1DOnChart and show1D and sig15on and break15
    label.new(bar_index, dn15_1D, text = '1d-1.5⚡', style = label.style_label_up, color = color15dn, textcolor = color.new(color.white, 0), size = size.normal)
 
// ============================================================================
// v7.6.5: 2.0×ライン シグナル(1.5×の実装踏襲、表記 1d-2。label.new方式=プロット枠消費なし)
// ============================================================================
trend20_changed = trend20_1D != trend20_1D[1]
 
var int warning20_time = 0
var int break20_time = 0
var int warning20_count = 0
var int break20_count = 0
var int trend20_change_time = 0
 
if bool(ta.change(time('D')))
    warning20_count := 0
    break20_count := 0
    break20_count
 
if trend20_changed == true
    trend20_change_time := time
    trend20_change_time
 
timeSinceTrendChange20 = (time - trend20_change_time) / 60000
 
warning20 = trend20_1D == 1 and close < up20_1D and time - warning20_time >= 14400000 and warning20_count < 2 and (timeSinceTrendChange20 <= 10 or trend20_1D == 1)
break20 = trend20_1D == -1 and close > dn20_1D and time - break20_time >= 3600000 and break20_count < 2 and (timeSinceTrendChange20 <= 10 or trend20_1D == -1)
 
if warning20 == true
    warning20_time := time
    warning20_count := warning20_count + 1
    warning20_count
 
if break20 == true
    break20_time := time
    break20_count := break20_count + 1
    break20_count
 
if masterSignals and show1DOnChart and show1D and sig20on and warning20
    label.new(bar_index, up20_1D, text = '1d-2⚠️', style = label.style_label_down, color = color20, textcolor = color.new(color.white, 0), size = size.normal)
if masterSignals and show1DOnChart and show1D and sig20on and break20
    label.new(bar_index, dn20_1D, text = '1d-2⚡', style = label.style_label_up, color = color20dn, textcolor = color.new(color.white, 0), size = size.normal)
 
// ============================================================================
// v7.5: 旧サポ(1D DN中、割れた旧サポートラインを circle 点線で表示)
// 色は終値との位置関係で変化: 終値 >= 旧サポ = 緑 / 未満 = 1.0の赤(#8c101a)
// ※タイトルを変更してスタイル既定(circle)を再適用させている
// ============================================================================
plot(showKyuSapoMark and show1DOnChart and linesOK and show1D and trend1D == -1 and not na(lastUp1D) ? lastUp1D : na, title = '旧サポ', style = plot.style_circles, linewidth = 2, color = close >= lastUp1D ? color.new(#4caf50, 0) : color.new(#8c101a, 0))
 
// ============================================================================
// 改修版 Overheating Line
// ============================================================================
var float up1D_current = na
var float dn1D_current = na
var int trend1D_current = 1
 
up1D_current_calc = hl2_1D_current - Multiplier1D * atr1D_current
up1D_current := na(up1D_current[1]) ? up1D_current_calc : close1D_current[1] > up1D_current[1] ? math.max(up1D_current_calc, up1D_current[1]) : up1D_current_calc
 
dn1D_current_calc = hl2_1D_current + Multiplier1D * atr1D_current
dn1D_current := na(dn1D_current[1]) ? dn1D_current_calc : close1D_current[1] < dn1D_current[1] ? math.min(dn1D_current_calc, dn1D_current[1]) : dn1D_current_calc
 
trend1D_current := na(trend1D_current[1]) ? 1 : trend1D_current[1] == -1 and close1D_current > dn1D_current[1] ? 1 : trend1D_current[1] == 1 and close1D_current < up1D_current[1] ? -1 : trend1D_current[1]
 
overheatingLine_v2 = up1D_current + atr1D_prev * overheatingMultiplier
 
// v7.4: 過熱ラインは従来通り全期間 plot 描画に戻す(ラベル色はラインと統一)
plot(showOverheatingLine and showOHLine and show1DOnChart and show1D and trend1D_current == 1 ? overheatingLine_v2 : na, title = '過熱ライン v2 (Fixed ATR)', style = plot.style_linebr, linewidth = 3, color = overheatingColor)
 
if showOverheatingLine and showOHLine and show1D and show1DOnChart and showLabel1D and bar_index % 40 == 0 and trend1D_current == 1
    label.new(bar_index, overheatingLine_v2, text = '[過熱]', style = label.style_none, textcolor = overheatingColor, size = size.tiny, yloc = yloc.price)
 
// ============================================================================
// 過熱ライン タッチシグナル & ステータス管理
// ============================================================================
var bool oh_touched_today = false
var int oh_touch_bar = 0
var float oh_touch_price = na
var float oh_high_after_touch = na
var float oh_low_after_touch = na
var bool oh_below_line = false
 
if bool(ta.change(time('D')))
    oh_touched_today := false
    oh_touch_bar := 0
    oh_touch_price := na
    oh_high_after_touch := na
    oh_low_after_touch := na
    oh_below_line := false
    oh_below_line
 
oh_touch_now = high >= overheatingLine_v2 and trend1D_current == 1 and not oh_touched_today
 
if oh_touch_now
    oh_touched_today := true
    oh_touch_bar := bar_index
    oh_touch_price := high
    oh_high_after_touch := high
    oh_low_after_touch := low
    oh_low_after_touch
 
if oh_touched_today and bar_index > oh_touch_bar
    oh_high_after_touch := math.max(nz(oh_high_after_touch, high), high)
    oh_low_after_touch := math.min(nz(oh_low_after_touch, low), low)
    if close < overheatingLine_v2
        oh_below_line := true
        oh_below_line
 
// v7.6.1: plotshape → label.new (プロット枠1枠解放。位置・色は従来と同じ)
if showOHSignals and oh_touch_now
    label.new(bar_index, high, text = '🔥', style = label.style_label_down, color = overheatingColor, textcolor = color.new(color.white, 0), size = size.small)
 
// ============================================================================
// 1D Trend Change Markers and Signals
// ============================================================================
trend1D_changed = trend1D != trend1D[1]
plotshape(masterUpTrend and show1DOnChart and linesOK and show1D and trend1D_changed and trend1D == 1 ? up1D : na, title = '1D UpTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#4caf50, 0))
plotshape(masterDownTrend and show1DOnChart and linesOK and show1D and trend1D_changed and trend1D == -1 ? dn1D : na, title = '1D DownTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#8c101a, 0))
 
var int warning1D_time = 0
var int break1D_time = 0
var int warning1D_count = 0
var int break1D_count = 0
var int trend1D_change_time = 0
 
if bool(ta.change(time('D')))
    warning1D_count := 0
    break1D_count := 0
    break1D_count
 
if trend1D_changed == true
    trend1D_change_time := time
    trend1D_change_time
 
timeSinceTrendChange1D = (time - trend1D_change_time) / 60000
 
warning1D = trend1D == 1 and close < up1D and time - warning1D_time >= 14400000 and warning1D_count < 2 and (timeSinceTrendChange1D <= 10 or trend1D == 1)
break1D = trend1D == -1 and close > dn1D and time - break1D_time >= 3600000 and break1D_count < 2 and (timeSinceTrendChange1D <= 10 or trend1D == -1)
 
if warning1D == true
    warning1D_time := time
    warning1D_count := warning1D_count + 1
    warning1D_count
 
if break1D == true
    break1D_time := time
    break1D_count := break1D_count + 1
    break1D_count
 
plotshape(masterSignals and show1DOnChart and showSignals1D and warning1D ? up1D : na, title = '1D Warning', text = '1d⚠️', location = location.absolute, style = shape.labeldown, size = size.normal, color = color.new(#4caf50, 0), textcolor = color.new(color.white, 0))
plotshape(masterSignals and show1DOnChart and showSignals1D and break1D ? dn1D : na, title = '1D Break', text = '1d⚡', location = location.absolute, style = shape.labelup, size = size.normal, color = color.new(#8c101a, 0), textcolor = color.new(color.white, 0))
 
if show1D and show1DOnChart and linesOK and showLabel1D and bar_index % 40 == 0
    if trend1D == 1
        label.new(bar_index, up1D, text = '[1D ATR]', style = label.style_none, textcolor = color.new(#4caf50, 0), size = size.tiny, yloc = yloc.price)
    else
        label.new(bar_index, dn1D, text = '[1D ATR]', style = label.style_none, textcolor = color.new(#8c101a, 0), size = size.tiny, yloc = yloc.price)
 
upPlot1D = plot(masterHighlighter and hlOK and show1DOnChart and show1D and highlighting1D and trend1D == 1 ? up1D : na, title = '1D Up Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#4caf50, 0), display = display.none)
dnPlot1D = plot(masterHighlighter and hlOK and show1DOnChart and show1D and highlighting1D and trend1D == -1 ? dn1D : na, title = '1D Down Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#8c101a, 0), display = display.none)
pricePlot1D = plot(masterHighlighter and hlOK and show1DOnChart and show1D and highlighting1D ? close : na, title = 'Price Fill 1D', style = plot.style_linebr, linewidth = 1, display = display.none)
fill(pricePlot1D, upPlot1D, color = color.new(#5cd73c, 61), title = '1D Up Trend Highlighter')
fill(pricePlot1D, dnPlot1D, color = color.new(#f7525f, 30), title = '1D Down Trend Highlighter')
 
// ============================================================================
// MTF Supertrend - 1 Week (前週確定データ基準)
// ============================================================================
show1W = input.bool(title = 'Show 1W Supertrend', defval = true, group = 'MTF 1 Week Supertrend')
Periods1W = input.int(title = 'ATR Period', defval = 10, group = 'MTF 1 Week Supertrend')
Multiplier1W = input.float(title = 'ATR Multiplier', step = 0.1, defval = 1.0, group = 'MTF 1 Week Supertrend')
changeATR1W = input.bool(title = 'Change ATR Calculation Method ?', defval = true, group = 'MTF 1 Week Supertrend')
showLabel1W = input.bool(title = 'Show Label', defval = true, group = 'MTF 1 Week Supertrend')
showSignals1W = input.bool(title = 'Show Warning/Break Signals ?', defval = true, group = 'MTF 1 Week Supertrend')
highlighting1W = input.bool(title = 'Highlighter On/Off ?', defval = true, group = 'MTF 1 Week Supertrend')
 
[atr1W_prev, hl2_1W_prev, close1W_prev] = request.security(syminfo.tickerid, 'W', [changeATR1W ? ta.atr(Periods1W) : ta.sma(ta.tr, Periods1W), hl2, close], lookahead = barmerge.lookahead_off)
 
var float up1W = na
var float dn1W = na
var int trend1W = 1
 
up1W_calc = hl2_1W_prev - Multiplier1W * atr1W_prev
up1W := na(up1W[1]) ? up1W_calc : close1W_prev[1] > up1W[1] ? math.max(up1W_calc, up1W[1]) : up1W_calc
 
dn1W_calc = hl2_1W_prev + Multiplier1W * atr1W_prev
dn1W := na(dn1W[1]) ? dn1W_calc : close1W_prev[1] < dn1W[1] ? math.min(dn1W_calc, dn1W[1]) : dn1W_calc
 
trend1W := na(trend1W[1]) ? 1 : trend1W[1] == -1 and close1W_prev > dn1W[1] ? 1 : trend1W[1] == 1 and close1W_prev < up1W[1] ? -1 : trend1W[1]
 
var float lastUp1W = na
if trend1W == -1 and trend1W[1] == 1
    lastUp1W := up1W[1]
    lastUp1W
if trend1W == 1
    lastUp1W := na
    lastUp1W
 
plot(masterUpTrend and show1WOnChart and linesOK and show1W and trend1W == 1 ? up1W : na, title = '1W Up Trend', style = plot.style_linebr, linewidth = 2, color = color.new(#f06292, 0))
plot(masterDownTrend and show1WOnChart and linesOK and show1W and trend1W == -1 ? dn1W : na, title = '1W Down Trend', style = plot.style_linebr, linewidth = 2, color = color.new(#e91e63, 0))
 
trend1W_changed = trend1W != trend1W[1]
plotshape(masterUpTrend and show1WOnChart and linesOK and show1W and trend1W_changed and trend1W == 1 ? up1W : na, title = '1W UpTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#f06292, 0))
plotshape(masterDownTrend and show1WOnChart and linesOK and show1W and trend1W_changed and trend1W == -1 ? dn1W : na, title = '1W DownTrend Begins', location = location.absolute, style = shape.circle, size = size.tiny, color = color.new(#e91e63, 0))
 
var int warning1W_time = 0
var int break1W_time = 0
var int warning1W_count = 0
var int break1W_count = 0
var int trend1W_change_time = 0
 
if bool(ta.change(time('M')))
    warning1W_count := 0
    break1W_count := 0
    break1W_count
 
if trend1W_changed == true
    trend1W_change_time := time
    trend1W_change_time
 
timeSinceTrendChange1W = (time - trend1W_change_time) / 60000
 
warning1W = trend1W == 1 and close < up1W and time - warning1W_time >= 1209600000 and warning1W_count < 2 and (timeSinceTrendChange1W <= 10 or trend1W == 1)
break1W = trend1W == -1 and close > dn1W and time - break1W_time >= 1209600000 and break1W_count < 2 and (timeSinceTrendChange1W <= 10 or trend1W == -1)
 
if warning1W == true
    warning1W_time := time
    warning1W_count := warning1W_count + 1
    warning1W_count
 
if break1W == true
    break1W_time := time
    break1W_count := break1W_count + 1
    break1W_count
 
plotshape(masterSignals and show1WOnChart and show1W1MSignals and showSignals1W and warning1W ? up1W : na, title = '1W Warning', text = '1W⚠️', location = location.absolute, style = shape.labeldown, size = size.normal, color = color.new(#f06292, 0), textcolor = color.new(color.white, 0))
plotshape(masterSignals and show1WOnChart and show1W1MSignals and showSignals1W and break1W ? dn1W : na, title = '1W Break', text = '1W⚡', location = location.absolute, style = shape.labelup, size = size.normal, color = color.new(#e91e63, 0), textcolor = color.new(color.white, 0))
 
if show1W and show1WOnChart and linesOK and showLabel1W and bar_index % 50 == 0
    if trend1W == 1
        label.new(bar_index, up1W, text = '[1W ATR]', style = label.style_none, textcolor = color.new(#f06292, 0), size = size.tiny, yloc = yloc.price)
    else
        label.new(bar_index, dn1W, text = '[1W ATR]', style = label.style_none, textcolor = color.new(#e91e63, 0), size = size.tiny, yloc = yloc.price)
 
upPlot1W = plot(masterHighlighter and hlOK and show1WOnChart and show1W and highlighting1W and trend1W == 1 ? up1W : na, title = '1W Up Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#f06292, 0), display = display.none)
dnPlot1W = plot(masterHighlighter and hlOK and show1WOnChart and show1W and highlighting1W and trend1W == -1 ? dn1W : na, title = '1W Down Trend Fill', style = plot.style_linebr, linewidth = 1, color = color.new(#e91e63, 0), display = display.none)
pricePlot1W = plot(masterHighlighter and hlOK and show1WOnChart and show1W and highlighting1W ? close : na, title = 'Price Fill 1W', style = plot.style_linebr, linewidth = 1, display = display.none)
fill(pricePlot1W, upPlot1W, color = color.new(#66bb6a, 66), title = '1W Up Trend Highlighter')
fill(pricePlot1W, dnPlot1W, color = color.new(#e91e63, 52), title = '1W Down Trend Highlighter')
 
// ============================================================================
// MTF Supertrend - 1 Month (前月確定データ基準)
// ============================================================================
show1M = input.bool(title = 'Show 1M Supertrend', defval = true, group = 'MTF 1 Month Supertrend')
Periods1M = input.int(title = 'ATR Period', defval = 10, group = 'MTF 1 Month Supertrend')
Multiplier1M = input.float(title = 'ATR Multiplier', step = 0.1, defval = 1.0, group = 'MTF 1 Month Supertrend')
changeATR1M = input.bool(title = 'Change ATR Calculation Method ?', defval = true, group = 'MTF 1 Month Supertrend')
showLabel1M = input.bool(title = 'Show Label', defval = true, group = 'MTF 1 Month Supertrend')
showSignals1M = input.bool(title = 'Show Warning/Break Signals ?', defval = true, group = 'MTF 1 Month Supertrend')
 
[atr1M_prev, hl2_1M_prev, close1M_prev] = request.security(syminfo.tickerid, 'M', [changeATR1M ? ta.atr(Periods1M) : ta.sma(ta.tr, Periods1M), hl2, close], lookahead = barmerge.lookahead_off)
 
var float up1M = na
var float dn1M = na
var int trend1M = 1
 
up1M_calc = hl2_1M_prev - Multiplier1M * atr1M_prev
up1M := na(up1M[1]) ? up1M_calc : close1M_prev[1] > up1M[1] ? math.max(up1M_calc, up1M[1]) : up1M_calc
 
dn1M_calc = hl2_1M_prev + Multiplier1M * atr1M_prev
dn1M := na(dn1M[1]) ? dn1M_calc : close1M_prev[1] < dn1M[1] ? math.min(dn1M_calc, dn1M[1]) : dn1M_calc
 
trend1M := na(trend1M[1]) ? 1 : trend1M[1] == -1 and close1M_prev > dn1M[1] ? 1 : trend1M[1] == 1 and close1M_prev < up1M[1] ? -1 : trend1M[1]
 
var float lastUp1M = na
if trend1M == -1 and trend1M[1] == 1
    lastUp1M := up1M[1]
    lastUp1M
if trend1M == 1
    lastUp1M := na
    lastUp1M
 
// ============================================================================
// v6追加: D-ATR↑開始以降の最高値トラッキング(高値落ち計算用)
// ============================================================================
var float dAtrUpHigh = na
if trend1D == 1 and trend1D[1] == -1
    dAtrUpHigh := high
    dAtrUpHigh
if trend1D == 1
    dAtrUpHigh := math.max(nz(dAtrUpHigh, high), high)
    dAtrUpHigh
if trend1D == -1
    dAtrUpHigh := na
    dAtrUpHigh
dAtrDrawdown = not na(dAtrUpHigh) and dAtrUpHigh > 0 ? (close - dAtrUpHigh) / dAtrUpHigh * 100 : na
 
// ============================================================================
// v6追加: 1D ATR% (= ATR(10) ÷ Close × 100)
// ============================================================================
atrPct1D = close != 0 ? atr1D_prev / close * 100 : 0
 
// ============================================================================
// 1M Plot & Signals
// ============================================================================
plot(masterUpTrend and show1WOnChart and linesOK and show1M and trend1M == 1 ? up1M : na, title = '1M Up Trend', style = plot.style_linebr, linewidth = 2, color = color.new(#f44336, 0))
plot(masterDownTrend and show1WOnChart and linesOK and show1M and trend1M == -1 ? dn1M : na, title = '1M Down Trend', style = plot.style_linebr, linewidth = 2, color = color.new(#b71c1c, 0))
 
trend1M_changed = trend1M != trend1M[1]
// v7.3: 1M トレンド転換サークルはプロット枠節約のため削除(ライン・シグナルは継続)
 
var int warning1M_time = 0
var int break1M_time = 0
var int warning1M_count = 0
var int break1M_count = 0
var int trend1M_change_time = 0
 
if bool(ta.change(time('M')))
    warning1M_count := 0
    break1M_count := 0
    break1M_count
 
if trend1M_changed == true
    trend1M_change_time := time
    trend1M_change_time
 
timeSinceTrendChange1M = (time - trend1M_change_time) / 60000
 
warning1M = trend1M == 1 and close < up1M and time - warning1M_time >= 2592000000 and warning1M_count < 2 and (timeSinceTrendChange1M <= 10 or trend1M == 1)
break1M = trend1M == -1 and close > dn1M and time - break1M_time >= 2592000000 and break1M_count < 2 and (timeSinceTrendChange1M <= 10 or trend1M == -1)
 
if warning1M == true
    warning1M_time := time
    warning1M_count := warning1M_count + 1
    warning1M_count
 
if break1M == true
    break1M_time := time
    break1M_count := break1M_count + 1
    break1M_count
 
plotshape(masterSignals and show1WOnChart and show1W1MSignals and showSignals1M and warning1M ? up1M : na, title = '1M Warning', text = '1M⚠️', location = location.absolute, style = shape.labeldown, size = size.normal, color = color.new(#c12b37, 0), textcolor = color.new(color.white, 0))
plotshape(masterSignals and show1WOnChart and show1W1MSignals and showSignals1M and break1M ? dn1M : na, title = '1M Break', text = '1M⚡', location = location.absolute, style = shape.labelup, size = size.normal, color = color.new(#8b1a2b, 0), textcolor = color.new(color.white, 0))
 
if show1M and show1WOnChart and linesOK and showLabel1M and bar_index % 60 == 0
    if trend1M == 1
        label.new(bar_index, up1M, text = '[1M ATR]', style = label.style_none, textcolor = color.new(#f44336, 0), size = size.tiny, yloc = yloc.price)
    else
        label.new(bar_index, dn1M, text = '[1M ATR]', style = label.style_none, textcolor = color.new(#b71c1c, 0), size = size.tiny, yloc = yloc.price)
 
// ============================================================================
// 統合ステータステーブル v6 (STOP System対応)
// UP/DN表記 / ATR%列(1Dのみ) / 高値落ち列 / 過熱・VWAP廃止
// ============================================================================
if showStatusTable and barstate.islast
    var table statusTbl = table.new(position.bottom_right, 8, 8, bgcolor = color.new(#000000, 80), border_width = 0)
 
    // --- ヘッダー ---
    table.cell(statusTbl, 0, 0, 'TF', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 1, 0, '状態', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 2, 0, 'ライン値', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 3, 0, '乖離%', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 4, 0, 'ATR%', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 5, 0, '100株損失', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 6, 0, '旧サポ', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 7, 0, '高値落ち', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_center)
 
    // --- 1H ---
    dir1H_text = trend1H == 1 ? 'UP' : 'DN'
    dir1H_color = trend1H == 1 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    st1H_val = trend1H == 1 ? up1H : dn1H
    dev1H_val = close != 0 ? (close - st1H_val) / close * 100 : 0
    devC1H = dev1H_val >= 0 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    loss1H_val = trend1H == 1 ? (close - up1H) * 100 : na
 
    table.cell(statusTbl, 0, 1, '1H', text_color = color.new(#1848cc, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 1, 1, dir1H_text, text_color = dir1H_color, text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 2, 1, str.tostring(st1H_val, '#'), text_color = color.new(#cccccc, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 3, 1, str.tostring(dev1H_val, '#.##') + '%', text_color = devC1H, text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 4, 1, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 5, 1, not na(loss1H_val) ? str.tostring(-math.abs(loss1H_val), '#') : '---', text_color = not na(loss1H_val) ? color.new(#f44336, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 6, 1, not na(lastUp1H) ? str.tostring(lastUp1H, '#') : '---', text_color = not na(lastUp1H) ? color.new(#ff9800, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 7, 1, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
 
    // --- 4H ---
    dir4H_text = trend4H == 1 ? 'UP' : 'DN'
    dir4H_color = trend4H == 1 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    st4H_val = trend4H == 1 ? up4H : dn4H
    dev4H_val = close != 0 ? (close - st4H_val) / close * 100 : 0
    devC4H = dev4H_val >= 0 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    loss4H_val = trend4H == 1 ? (close - up4H) * 100 : na
 
    table.cell(statusTbl, 0, 2, '4H', text_color = color.new(#7b1fa2, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 1, 2, dir4H_text, text_color = dir4H_color, text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 2, 2, str.tostring(st4H_val, '#'), text_color = color.new(#cccccc, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 3, 2, str.tostring(dev4H_val, '#.##') + '%', text_color = devC4H, text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 4, 2, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 5, 2, not na(loss4H_val) ? str.tostring(-math.abs(loss4H_val), '#') : '---', text_color = not na(loss4H_val) ? color.new(#f44336, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 6, 2, not na(lastUp4H) ? str.tostring(lastUp4H, '#') : '---', text_color = not na(lastUp4H) ? color.new(#ff9800, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 7, 2, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
 
    // --- 1D ★ ATR%と高値落ちあり ---
    dir1D_text = trend1D == 1 ? 'UP' : 'DN'
    dir1D_color = trend1D == 1 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    st1D_val = trend1D == 1 ? up1D : dn1D
    dev1D_val = close != 0 ? (close - st1D_val) / close * 100 : 0
    devC1D = dev1D_val >= 0 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    loss1D_val = trend1D == 1 ? (close - up1D) * 100 : na
    atrPctClr = atrPct1D >= 2.0 ? color.new(#f44336, 0) : atrPct1D >= 1.5 ? color.new(#ff9800, 0) : color.new(#00bcd4, 0)
    ddClr = not na(dAtrDrawdown) ? dAtrDrawdown <= -5 ? color.new(#f44336, 0) : dAtrDrawdown <= -2 ? color.new(#ff9800, 0) : color.new(#4caf50, 0) : color.new(#666666, 0)
    ddTxt = not na(dAtrDrawdown) ? str.tostring(dAtrDrawdown, '#.##') + '%' : '---'
 
    table.cell(statusTbl, 0, 3, '1D', text_color = color.new(#4caf50, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 1, 3, dir1D_text, text_color = dir1D_color, text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 2, 3, str.tostring(st1D_val, '#'), text_color = color.new(#cccccc, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 3, 3, str.tostring(dev1D_val, '#.##') + '%', text_color = devC1D, text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 4, 3, str.tostring(atrPct1D, '#.##') + '%', text_color = atrPctClr, text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 5, 3, not na(loss1D_val) ? str.tostring(-math.abs(loss1D_val), '#') : '---', text_color = not na(loss1D_val) ? color.new(#f44336, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 6, 3, not na(lastUp1D) ? str.tostring(lastUp1D, '#') : '---', text_color = not na(lastUp1D) ? color.new(#ff9800, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 7, 3, ddTxt, text_color = ddClr, text_size = size.small, text_halign = text.align_right)
 
    // --- 1W ---
    dir1W_text = trend1W == 1 ? 'UP' : 'DN'
    dir1W_color = trend1W == 1 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    st1W_val = trend1W == 1 ? up1W : dn1W
    dev1W_val = close != 0 ? (close - st1W_val) / close * 100 : 0
    devC1W = dev1W_val >= 0 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    loss1W_val = trend1W == 1 ? (close - up1W) * 100 : na
 
    table.cell(statusTbl, 0, 4, '1W', text_color = color.new(#f06292, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 1, 4, dir1W_text, text_color = dir1W_color, text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 2, 4, str.tostring(st1W_val, '#'), text_color = color.new(#cccccc, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 3, 4, str.tostring(dev1W_val, '#.##') + '%', text_color = devC1W, text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 4, 4, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 5, 4, not na(loss1W_val) ? str.tostring(-math.abs(loss1W_val), '#') : '---', text_color = not na(loss1W_val) ? color.new(#f44336, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 6, 4, not na(lastUp1W) ? str.tostring(lastUp1W, '#') : '---', text_color = not na(lastUp1W) ? color.new(#ff9800, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 7, 4, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
 
    // --- 1M ---
    dir1M_text = trend1M == 1 ? 'UP' : 'DN'
    dir1M_color = trend1M == 1 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    st1M_val = trend1M == 1 ? up1M : dn1M
    dev1M_val = close != 0 ? (close - st1M_val) / close * 100 : 0
    devC1M = dev1M_val >= 0 ? color.new(#4caf50, 0) : color.new(#f44336, 0)
    loss1M_val = trend1M == 1 ? (close - up1M) * 100 : na
 
    table.cell(statusTbl, 0, 5, '1M', text_color = color.new(#f44336, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 1, 5, dir1M_text, text_color = dir1M_color, text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 2, 5, str.tostring(st1M_val, '#'), text_color = color.new(#cccccc, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 3, 5, str.tostring(dev1M_val, '#.##') + '%', text_color = devC1M, text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 4, 5, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 5, 5, not na(loss1M_val) ? str.tostring(-math.abs(loss1M_val), '#') : '---', text_color = not na(loss1M_val) ? color.new(#f44336, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 6, 5, not na(lastUp1M) ? str.tostring(lastUp1M, '#') : '---', text_color = not na(lastUp1M) ? color.new(#ff9800, 0) : color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 7, 5, '---', text_color = color.new(#666666, 0), text_size = size.small, text_halign = text.align_right)
 
    // --- セパレーター ---
    table.cell(statusTbl, 0, 6, '', text_size = size.tiny)
    table.cell(statusTbl, 1, 6, '', text_size = size.tiny)
    table.cell(statusTbl, 2, 6, '', text_size = size.tiny)
    table.cell(statusTbl, 3, 6, '', text_size = size.tiny)
    table.cell(statusTbl, 4, 6, '', text_size = size.tiny)
    table.cell(statusTbl, 5, 6, '', text_size = size.tiny)
    table.cell(statusTbl, 6, 6, '', text_size = size.tiny)
    table.cell(statusTbl, 7, 6, '', text_size = size.tiny)
 
    // --- ATH ---
    athDev_val = close != 0 and not na(ath) ? (ath - close) / close * 100 : 0
 
    table.cell(statusTbl, 0, 7, 'ATH', text_color = color.new(color.lime, 0), text_size = size.small, text_halign = text.align_center)
    table.cell(statusTbl, 1, 7, '', text_size = size.small)
    table.cell(statusTbl, 2, 7, str.tostring(ath, '#'), text_color = color.new(#cccccc, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 3, 7, '-' + str.tostring(athDev_val, '#.##') + '%', text_color = color.new(#888888, 0), text_size = size.small, text_halign = text.align_right)
    table.cell(statusTbl, 4, 7, '', text_size = size.small)
    table.cell(statusTbl, 5, 7, '', text_size = size.small)
    table.cell(statusTbl, 6, 7, '', text_size = size.small)
    table.cell(statusTbl, 7, 7, '', text_size = size.small)
 
// ============================================================================
// Alerts
// ============================================================================
alertcondition(warning1H, '1H Warning Alert', '1H ATR Break Down!')
alertcondition(break1H, '1H Break Alert', '1H ATR Break Up!')
alertcondition(warning4H, '4H Warning Alert', '4H ATR Break Down!')
alertcondition(break4H, '4H Break Alert', '4H ATR Break Up!')
alertcondition(warning1D, '1D Warning Alert', '1D ATR Break Down!')
alertcondition(break1D, '1D Break Alert', '1D ATR Break Up!')
// v7.3: 1W/1M Warning/Break の alertcondition はプロット枠節約のため削除(シグナル表示は継続)
// v7: 過熱タッチ
alertcondition(oh_touch_now, '過熱タッチ Alert', '過熱ラインにタッチ!')

← 返回列表