本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("NORN WEAVE | Dow Theory", overlay=true, precision=4, max_labels_count=50, max_lines_count=50)
// =====================================================================
// スイング設定 / SWING
// =====================================================================
swingLen = input.int(5, "Swing Length (bars each side)",
minval=2, maxval=50, group="[ SWING ]",
tooltip="Bars on each side used to confirm a swing high/low.\nGuide: short 2-3 / standard 5 / mid 10 / major 15+\nConfirmation lags by this many bars. Same length is used for higher TFs.\n\n高値・安値の左右それぞれ何本で山・谷を判定するか。\n目安: 短期 2〜3 / 標準 5 / 中期 10 / 大きな波 15〜\n右側の本数ぶん確定が遅れます。上位足にも同じ本数を使います。")
// =====================================================================
// マルチタイムフレーム / MTF(現在足より上位の足だけ表示)
// =====================================================================
useD = input.bool(true, "1D", inline="mtf1", group="[ MTF ]")
useH8 = input.bool(true, "8H", inline="mtf1", group="[ MTF ]")
useH4 = input.bool(true, "4H", inline="mtf2", group="[ MTF ]")
useH2 = input.bool(true, "2H", inline="mtf2", group="[ MTF ]",
tooltip="Only timeframes higher than the chart are shown.\ne.g. 2H chart -> 4H, 8H, 1D / 8H chart -> 1D only\n\n現在のチャートより上位の時間足だけが表示されます。\n例: 2H足 → 4H・8H・日足 / 8H足 → 日足のみ")
showMtfLine = input.bool(true, "HTF Key Lines", group="[ MTF ]",
tooltip="Draws only the currently active key level of each HTF, from where it was set to the right edge.\n\n現在有効な押し安値(上昇中)/ 戻り高値(下降中)だけを、そのラインが確定した位置から右端まで引きます。")
// =====================================================================
// 環境認識 / ENVIRONMENT
// =====================================================================
colorFlips = input.bool(true, "Color Flips by Next HTF", group="[ ENVIRONMENT ]",
tooltip="Flip in the same direction as the next higher TF (e.g. 4H on a 2H chart) = gold & larger. Otherwise = gray.\nThe next higher TF is the nearest enabled HTF above the chart.\n\n1つ上の時間足(例: 2H足なら4H)と同じ方向への転換 → 金色・大きめ。逆方向 → グレー。\n1つ上の足は、表示がONの上位足のうち一番近いもの。")
// =====================================================================
// 表示設定 / Display
// =====================================================================
showDowZone = input.bool(true, "Dow Zone", group="[ DISPLAY ]")
showSwingLine = input.bool(true, "Swing Line", group="[ DISPLAY ]")
showSwingPts = input.bool(false, "Swing Points", group="[ DISPLAY ]")
showFlip = input.bool(true, "Trend Flip Marks", group="[ DISPLAY ]")
showTable = input.bool(true, "Status Table", group="[ DISPLAY ]")
showLegend = input.bool(true, "Show Legend", group="[ DISPLAY ]",
tooltip="Shows how to read marks and lines under the status table.\n\nステータステーブルの下に、マーク・ラインの見方を表示します。")
tablePos = input.string("Top Right", "Table Position",
group="[ DISPLAY ]",
options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"])
tableSize = input.string("Normal", "Table Text Size",
group="[ DISPLAY ]", options=["Small", "Normal", "Large"])
// =====================================================================
// ダウ理論判定
// =====================================================================
f_dow(int len) =>
bool sh = high[len] == ta.highest(high, len * 2 + 1)
bool sl = low[len] == ta.lowest(low, len * 2 + 1)
var float lsh = na
var float lsl = na
lsh := sh ? high[len] : lsh
lsl := sl ? low[len] : lsl
var int tr = 0
if not na(lsh) and close > lsh and tr != 1
tr := 1
if not na(lsl) and close < lsl and tr != -1
tr := -1
[tr, lsh, lsl]
// 上位足用:確定済みの足の値だけを返す(リペイント防止)
f_dowConfirmed(int len) =>
[tr, lsh, lsl] = f_dow(len)
[tr[1], lsh[1], lsl[1]]
// =====================================================================
// 現在足(確定足のみ)
// 未確定のリアルタイム足では、1本前(確定済み)の値をそのまま使う。
// =====================================================================
isSwingHighRaw = high[swingLen] == ta.highest(high, swingLen * 2 + 1)
isSwingLowRaw = low[swingLen] == ta.lowest(low, swingLen * 2 + 1)
[trRaw, shRaw, slRaw] = f_dow(swingLen)
bool isConf = barstate.isconfirmed
bool isSwingHigh = isConf ? isSwingHighRaw : false
bool isSwingLow = isConf ? isSwingLowRaw : false
int trend = isConf ? trRaw : nz(trRaw[1])
float lastSwingHigh = isConf ? shRaw : shRaw[1]
float lastSwingLow = isConf ? slRaw : slRaw[1]
float confClose = isConf ? close : close[1]
flipUp = trend == 1 and trend[1] != 1
flipDown = trend == -1 and trend[1] != -1
// =====================================================================
// 上位足(日足・8H・4H・2H)
// =====================================================================
chartSec = timeframe.in_seconds()
showD = useD and timeframe.in_seconds("D") > chartSec
showH8 = useH8 and timeframe.in_seconds("480") > chartSec
showH4 = useH4 and timeframe.in_seconds("240") > chartSec
showH2 = useH2 and timeframe.in_seconds("120") > chartSec
[trD, shD, slD ] = request.security(syminfo.tickerid, "D", f_dowConfirmed(swingLen), lookahead=barmerge.lookahead_on)
[trH8, shH8, slH8] = request.security(syminfo.tickerid, "480", f_dowConfirmed(swingLen), lookahead=barmerge.lookahead_on)
[trH4, shH4, slH4] = request.security(syminfo.tickerid, "240", f_dowConfirmed(swingLen), lookahead=barmerge.lookahead_on)
[trH2, shH2, slH2] = request.security(syminfo.tickerid, "120", f_dowConfirmed(swingLen), lookahead=barmerge.lookahead_on)
// 監視ライン:上昇中=押し安値 / 下降中=戻り高値
f_key(int tr, float sh, float sl) =>
tr == 1 ? sl : tr == -1 ? sh : na
keyD = f_key(trD, shD, slD)
keyH8 = f_key(trH8, shH8, slH8)
keyH4 = f_key(trH4, shH4, slH4)
keyH2 = f_key(trH2, shH2, slH2)
// ラインの切り替わり判定(na も考慮)
f_changed(float k, float kPrev, int tr, int trPrev) =>
na(k) != na(kPrev) or (not na(k) and k != kPrev) or tr != trPrev
chgD = f_changed(keyD, keyD[1], trD, trD[1])
chgH8 = f_changed(keyH8, keyH8[1], trH8, trH8[1])
chgH4 = f_changed(keyH4, keyH4[1], trH4, trH4[1])
chgH2 = f_changed(keyH2, keyH2[1], trH2, trH2[1])
// 各上位足ラインの起点(ラインが現在の値になったバー)
var int stD = na
var int stH8 = na
var int stH4 = na
var int stH2 = na
stD := chgD ? bar_index : stD
stH8 := chgH8 ? bar_index : stH8
stH4 := chgH4 ? bar_index : stH4
stH2 := chgH2 ? bar_index : stH2
// =====================================================================
// カラー
// =====================================================================
C_BULL = #e8eaf0
C_BEAR = #c0152a
C_GOLD = #c9a84c
C_NEU = #8892a4
f_trCol(int tr, int transp) =>
tr == 1 ? color.new(C_BULL, transp) : tr == -1 ? color.new(C_BEAR, transp) : color.new(C_NEU, transp)
// =====================================================================
// 1つ上の時間足(表示ONの上位足のうち一番近いもの)
// 例: 1H足→2H / 2H足→4H / 4H足→8H / 8H足→日足
// =====================================================================
bool hasNext = showH2 or showH4 or showH8 or showD
int nextTr = showH2 ? trH2 : showH4 ? trH4 : showH8 ? trH8 : showD ? trD : 0
string nextName = showH2 ? "2H" : showH4 ? "4H" : showH8 ? "8H" : showD ? "1D" : "-"
// =====================================================================
// 1. ダウゾーン(現在足)
// =====================================================================
barPrice = confClose
sh_b = trend == -1 ? lastSwingHigh : na
sh_q1 = trend == -1 ? lastSwingHigh - (lastSwingHigh - barPrice) * 0.22 : na
sh_q2 = trend == -1 ? lastSwingHigh - (lastSwingHigh - barPrice) * 0.50 : na
sh_q3 = trend == -1 ? lastSwingHigh - (lastSwingHigh - barPrice) * 0.78 : na
sh_e = trend == -1 ? barPrice : na
p_shb = plot(showDowZone ? sh_b : na, "Bear zone base", display=display.none, editable=false)
p_shq1 = plot(showDowZone ? sh_q1 : na, "Bear zone q1", display=display.none, editable=false)
p_shq2 = plot(showDowZone ? sh_q2 : na, "Bear zone q2", display=display.none, editable=false)
p_shq3 = plot(showDowZone ? sh_q3 : na, "Bear zone q3", display=display.none, editable=false)
p_she = plot(showDowZone ? sh_e : na, "Bear zone end", display=display.none, editable=false)
fill(p_shb, p_shq1, color.new(C_BEAR, 40), title="Bear Zone 1")
fill(p_shq1, p_shq2, color.new(C_BEAR, 60), title="Bear Zone 2")
fill(p_shq2, p_shq3, color.new(C_BEAR, 78), title="Bear Zone 3")
fill(p_shq3, p_she, color.new(C_BEAR, 90), title="Bear Zone 4")
sl_b = trend == 1 ? lastSwingLow : na
sl_q1 = trend == 1 ? lastSwingLow + (barPrice - lastSwingLow) * 0.22 : na
sl_q2 = trend == 1 ? lastSwingLow + (barPrice - lastSwingLow) * 0.50 : na
sl_q3 = trend == 1 ? lastSwingLow + (barPrice - lastSwingLow) * 0.78 : na
sl_e = trend == 1 ? barPrice : na
p_slb = plot(showDowZone ? sl_b : na, "Bull zone base", display=display.none, editable=false)
p_slq1 = plot(showDowZone ? sl_q1 : na, "Bull zone q1", display=display.none, editable=false)
p_slq2 = plot(showDowZone ? sl_q2 : na, "Bull zone q2", display=display.none, editable=false)
p_slq3 = plot(showDowZone ? sl_q3 : na, "Bull zone q3", display=display.none, editable=false)
p_sle = plot(showDowZone ? sl_e : na, "Bull zone end", display=display.none, editable=false)
fill(p_slb, p_slq1, color.new(C_BULL, 40), title="Bull Zone 1")
fill(p_slq1, p_slq2, color.new(C_BULL, 60), title="Bull Zone 2")
fill(p_slq2, p_slq3, color.new(C_BULL, 78), title="Bull Zone 3")
fill(p_slq3, p_sle, color.new(C_BULL, 90), title="Bull Zone 4")
// =====================================================================
// 2. スイングライン(現在足)
// =====================================================================
plot(showSwingLine and trend == -1 ? lastSwingHigh : na, "Resist Outer", color=color.new(C_BEAR, 55), linewidth=3, style=plot.style_linebr, display=display.pane)
plot(showSwingLine and trend == -1 ? lastSwingHigh : na, "Resist Core", color=color.new(C_BEAR, 5), linewidth=1, style=plot.style_linebr, display=display.pane)
plot(showSwingLine and trend == 1 ? lastSwingLow : na, "Support Outer", color=color.new(C_BULL, 55), linewidth=3, style=plot.style_linebr, display=display.pane)
plot(showSwingLine and trend == 1 ? lastSwingLow : na, "Support Core", color=color.new(C_BULL, 5), linewidth=1, style=plot.style_linebr, display=display.pane)
// =====================================================================
// 3. スイング点 / 4. 転換マーク
// =====================================================================
plotshape(showSwingPts and isSwingHigh ? high[swingLen] : na, "Swing High",
style=shape.circle, location=location.absolute, color=color.new(C_BEAR, 30), size=size.tiny, offset=-swingLen, display=display.pane)
plotshape(showSwingPts and isSwingLow ? low[swingLen] : na, "Swing Low",
style=shape.circle, location=location.absolute, color=color.new(C_BULL, 30), size=size.tiny, offset=-swingLen, display=display.pane)
// 1つ上の足と同じ方向 → 金色・大きめ / それ以外 → グレー
bool useEnvCol = colorFlips and hasNext
bool upAligned = flipUp and nextTr == 1
bool dnAligned = flipDown and nextTr == -1
C_FLIP_OFF = color.new(C_NEU, 35)
plotshape(showFlip and flipUp and useEnvCol and upAligned, "Flip Up (Aligned)", style=shape.triangleup, location=location.belowbar, color=color.new(C_GOLD, 0), size=size.small, display=display.pane)
plotshape(showFlip and flipDown and useEnvCol and dnAligned, "Flip Down (Aligned)", style=shape.triangledown, location=location.abovebar, color=color.new(C_GOLD, 0), size=size.small, display=display.pane)
plotshape(showFlip and flipUp and useEnvCol and not upAligned, "Flip Up (Counter)", style=shape.triangleup, location=location.belowbar, color=C_FLIP_OFF, size=size.tiny, display=display.pane)
plotshape(showFlip and flipDown and useEnvCol and not dnAligned, "Flip Down (Counter)", style=shape.triangledown, location=location.abovebar, color=C_FLIP_OFF, size=size.tiny, display=display.pane)
plotshape(showFlip and flipUp and not useEnvCol, "Flip Up", style=shape.triangleup, location=location.belowbar, color=color.new(C_BULL, 10), size=size.tiny, display=display.pane)
plotshape(showFlip and flipDown and not useEnvCol, "Flip Down", style=shape.triangledown, location=location.abovebar, color=color.new(C_BEAR, 10), size=size.tiny, display=display.pane)
// ◇ 1つ上の足が追いついて方向が揃った瞬間(現在足は転換していない)
// 例: 1Hが先に下降 → あとから2Hも下降 → ◇(上側)
bool catchUpUp = isConf and useEnvCol and not flipUp and trend == 1 and nextTr == 1 and nextTr[1] != 1
bool catchUpDn = isConf and useEnvCol and not flipDown and trend == -1 and nextTr == -1 and nextTr[1] != -1
plotchar(showFlip and catchUpUp, "Catch-up Up", char="◇", location=location.belowbar, color=color.new(C_GOLD, 0), size=size.small, display=display.pane)
plotchar(showFlip and catchUpDn, "Catch-up Down", char="◇", location=location.abovebar, color=color.new(C_GOLD, 0), size=size.small, display=display.pane)
// =====================================================================
// 5. 上位足ライン(現在有効なラインのみ・起点から右端まで)
// 1D = 実線 5px / 8H = 実線 4px / 4H = 破線 3px / 2H = 点線 3px
// =====================================================================
f_mtfDraw(line oldL, label oldLb, bool show, int tr, float key, int st, string name, int w, string ls, int transp) =>
line.delete(oldL)
label.delete(oldLb)
line l = na
label lb = na
if show and not na(key) and not na(st)
xEnd = bar_index + 4
l := line.new(st, key, xEnd, key, color=f_trCol(tr, transp), width=w, style=ls)
lb := label.new(xEnd, key, name + " " + (tr == 1 ? "▲" : tr == -1 ? "▼" : "─") + " " + str.tostring(key, format.mintick),
style=label.style_label_left, size=size.large,
color=color.new(#0d0520, 10), textcolor=f_trCol(tr, 0))
[l, lb]
var line lnD = na
var line lnH8 = na
var line lnH4 = na
var line lnH2 = na
var label lbD = na
var label lbH8 = na
var label lbH4 = na
var label lbH2 = na
if barstate.islast
[a1, b1] = f_mtfDraw(lnD, lbD, showMtfLine and showD, trD, keyD, stD, "1D", 5, line.style_solid, 10)
[a2, b2] = f_mtfDraw(lnH8, lbH8, showMtfLine and showH8, trH8, keyH8, stH8, "8H", 4, line.style_solid, 20)
[a3, b3] = f_mtfDraw(lnH4, lbH4, showMtfLine and showH4, trH4, keyH4, stH4, "4H", 3, line.style_dashed, 25)
[a4, b4] = f_mtfDraw(lnH2, lbH2, showMtfLine and showH2, trH2, keyH2, stH2, "2H", 3, line.style_dotted, 30)
lnD := a1
lbD := b1
lnH8 := a2
lbH8 := b2
lnH4 := a3
lbH4 := b3
lnH2 := a4
lbH2 := b4
// 他スクリプト連携用(データウィンドウのみ)
plot(trend, "Trend (1/-1/0)", display=display.data_window)
plot(showD ? trD : na, "1D Trend", display=display.data_window)
plot(showH8 ? trH8 : na, "8H Trend", display=display.data_window)
plot(showH4 ? trH4 : na, "4H Trend", display=display.data_window)
plot(showH2 ? trH2 : na, "2H Trend", display=display.data_window)
// =====================================================================
// 6. ステータステーブル
// =====================================================================
tPos = tablePos == "Top Right" ? position.top_right :
tablePos == "Top Left" ? position.top_left :
tablePos == "Bottom Right" ? position.bottom_right :
position.bottom_left
tsMain = tableSize == "Small" ? size.small : tableSize == "Large" ? size.large : size.normal
tsSub = tableSize == "Small" ? size.tiny : tableSize == "Large" ? size.normal : size.small
C_BG = color.new(#0d0520, 20)
C_HEAD = color.new(#1c0f3a, 10)
f_trendTxt(int tr) =>
tr == 1 ? "▲ Bull" : tr == -1 ? "▼ Bear" : "─ Neutral"
f_row(table tb, int row, string name, int tr, float key) =>
table.cell(tb, 0, row, name, text_color=color.new(C_NEU, 0), text_size=tsMain, bgcolor=C_BG, text_halign=text.align_left)
table.cell(tb, 1, row, f_trendTxt(tr), text_color=f_trCol(tr, 5), text_size=tsMain, bgcolor=C_BG, text_halign=text.align_center)
table.cell(tb, 2, row, na(key) ? "-" : str.tostring(key, format.mintick), text_color=color.new(C_NEU, 0), text_size=tsMain, bgcolor=C_BG, text_halign=text.align_right)
var table t = na
if showTable and barstate.islast
if na(t)
t := table.new(tPos, 3, 14,
bgcolor=color.new(#0d0520, 8), border_color=color.new(C_GOLD, 75),
border_width=1, frame_color=color.new(C_GOLD, 45), frame_width=1)
table.clear(t, 0, 0, 2, 13)
table.cell(t, 0, 0, "TF",
text_color=color.new(C_GOLD, 10), text_size=tsMain, bgcolor=C_HEAD, text_halign=text.align_left)
table.cell(t, 1, 0, "Trend",
text_color=color.new(C_GOLD, 10), text_size=tsMain, bgcolor=C_HEAD, text_halign=text.align_center)
table.cell(t, 2, 0, "Key Level",
text_color=color.new(C_GOLD, 10), text_size=tsMain, bgcolor=C_HEAD, text_halign=text.align_right)
int r = 1
if showD
f_row(t, r, "1D", trD, keyD)
r += 1
if showH8
f_row(t, r, "8H", trH8, keyH8)
r += 1
if showH4
f_row(t, r, "4H", trH4, keyH4)
r += 1
if showH2
f_row(t, r, "2H", trH2, keyH2)
r += 1
keyCur = f_key(trend, lastSwingHigh, lastSwingLow)
f_row(t, r, "Chart ±" + str.tostring(swingLen), trend, keyCur)
r += 1
// 1つ上の足との一致
if hasNext
bool isAligned = trend != 0 and nextTr == trend
alignTxt = isAligned ? "● Aligned" : "○ Not aligned"
alignCol = isAligned ? color.new(C_GOLD, 0) : color.new(C_NEU, 0)
table.cell(t, 0, r, "vs " + nextName, text_color=color.new(C_NEU, 0), text_size=tsMain, bgcolor=C_HEAD, text_halign=text.align_left)
table.cell(t, 1, r, alignTxt, text_color=alignCol, text_size=tsMain, bgcolor=C_HEAD, text_halign=text.align_center)
table.cell(t, 2, r, "", bgcolor=C_HEAD)
table.merge_cells(t, 1, r, 2, r)
r += 1
// ── 凡例 ──
if showLegend
C_LBG = color.new(#0d0520, 35)
C_LTXT = color.new(C_NEU, 10)
table.cell(t, 0, r, "Legend", text_color=color.new(C_GOLD, 10), text_size=tsSub, bgcolor=C_HEAD, text_halign=text.align_left)
table.cell(t, 1, r, "", bgcolor=C_HEAD)
table.cell(t, 2, r, "", bgcolor=C_HEAD)
table.merge_cells(t, 0, r, 2, r)
r += 1
if showFlip and colorFlips and hasNext
table.cell(t, 0, r, "▲▼", text_color=color.new(C_GOLD, 0), text_size=tsMain, bgcolor=C_LBG, text_halign=text.align_center)
table.cell(t, 1, r, "Flip with " + nextName + " (with the flow)",
text_color=C_LTXT, text_size=tsSub, bgcolor=C_LBG, text_halign=text.align_left)
table.merge_cells(t, 1, r, 2, r)
r += 1
table.cell(t, 0, r, "▲▼", text_color=color.new(C_NEU, 35), text_size=tsSub, bgcolor=C_LBG, text_halign=text.align_center)
table.cell(t, 1, r, "Flip against " + nextName + " (against the flow)",
text_color=C_LTXT, text_size=tsSub, bgcolor=C_LBG, text_halign=text.align_left)
table.merge_cells(t, 1, r, 2, r)
r += 1
table.cell(t, 0, r, "◇", text_color=color.new(C_GOLD, 0), text_size=tsMain, bgcolor=C_LBG, text_halign=text.align_center)
table.cell(t, 1, r, nextName + " caught up - now aligned",
text_color=C_LTXT, text_size=tsSub, bgcolor=C_LBG, text_halign=text.align_left)
table.merge_cells(t, 1, r, 2, r)
r += 1
if showMtfLine and hasNext
table.cell(t, 0, r, "━", text_color=color.new(C_BULL, 10), text_size=tsMain, bgcolor=C_LBG, text_halign=text.align_center)
table.cell(t, 1, r, "━ 1D / ━ 8H / ╍ 4H / ┈ 2H\nwhite = key low / red = key high",
text_color=C_LTXT, text_size=tsSub, bgcolor=C_LBG, text_halign=text.align_left)
table.merge_cells(t, 1, r, 2, r)
r += 1
// =====================================================================
// アラート(flipUp / flipDown は確定足でしか true にならない)
// =====================================================================
alertcondition(flipUp, "Dow Flip → Bull", "NORN WEAVE | Dow | {{ticker}} | Bullish flip @ {{close}}")
alertcondition(flipDown, "Dow Flip → Bear", "NORN WEAVE | Dow | {{ticker}} | Bearish flip @ {{close}}")
alertcondition(flipUp or flipDown, "Dow Flip (Any)", "NORN WEAVE | Dow | {{ticker}} | Trend flip @ {{close}}")
alertcondition(catchUpUp, "Catch-up ◇ Bull", "NORN WEAVE | Dow | {{ticker}} | HTF caught up, aligned bullish @ {{close}}")
alertcondition(catchUpDn, "Catch-up ◇ Bear", "NORN WEAVE | Dow | {{ticker}} | HTF caught up, aligned bearish @ {{close}}")