OPEN-SOURCE SCRIPT
MA5 — 四點高低 + H1/L1 水平線 + 突破/回買 + 月季線交叉

//version=5
indicator("MA5 — 四點高低 + H1/L1 水平線 + 突破/回買 + 月季線交叉", overlay=true)
// 1. 均線設定
ma5 = ta.sma(close, 5)
ma10 = ta.sma(close, 10)
ma20 = ta.sma(close, 20)
ma60 = ta.sma(close, 60) // ← 加上這一行
// 畫出均線
plot(ma5, title="MA5", color=color.red)
plot(ma10, title="MA10", color=color.orange)
plot(ma20, title="MA20", color=color.yellow)
plot(ma60, title="MA60", color=color.green)
// 2. 全域變數:方向、區段極值
var int direction = na
var float segHigh = na
var int segHighBar = na
var float segLow = na
var int segLowBar = na
// 3. 全域變數:儲存兩組高低
var float high1 = na
var int high1Bar = na
var float high2 = na
var int high2Bar = na
var float low1 = na
var int low1Bar = na
var float low2 = na
var int low2Bar = na
// 4. 全域變數:標籤與線段句柄
var label highLbl1 = na
var label highLbl2 = na
var label lowLbl1 = na
var label lowLbl2 = na
var line highLine = na
var line lowLine = na
var line h1Line = na
var line l1Line = na
// 5. 全域變數:回買訊號控制
var bool buyBackShown = false
// 6. 判斷當前段方向
currDir = close > ma5 ? 1 : close < ma5 ? -1 : direction
// 7. 首次初始化
if na(direction)
direction := currDir
segHigh := high
segHighBar := bar_index
segLow := low
segLowBar := bar_index
// 8. 同段內更新極值
if currDir == 1 and high > segHigh
segHigh := high
segHighBar := bar_index
if currDir == -1 and low < segLow
segLow := low
segLowBar := bar_index
// 9. 段落切換:推舊值→更新 H1/L1→刪舊標籤/線→畫新標籤/線→重置 seg*
if currDir != direction
high2 := high1
high2Bar := high1Bar
low2 := low1
low2Bar := low1Bar
if direction == 1
high1 := segHigh
high1Bar := segHighBar
else
low1 := segLow
low1Bar := segLowBar
buyBackShown := false
if not na(highLbl1)
label.delete(highLbl1)
if not na(highLbl2)
label.delete(highLbl2)
if not na(lowLbl1)
label.delete(lowLbl1)
if not na(lowLbl2)
label.delete(lowLbl2)
if not na(high2)
highLbl2 := label.new(high2Bar, high2, "H2", style=label.style_label_down, color=color.blue, textcolor=color.white)
if not na(high1)
highLbl1 := label.new(high1Bar, high1, "H1", style=label.style_label_down, color=color.blue, textcolor=color.white)
if not na(low2)
lowLbl2 := label.new(low2Bar, low2, "L2", style=label.style_label_up, color=color.purple, textcolor=color.white)
if not na(low1)
lowLbl1 := label.new(low1Bar, low1, "L1", style=label.style_label_up, color=color.purple, textcolor=color.white)
if not na(highLine)
line.delete(highLine)
if not na(high1) and not na(high2)
highLine := line.new(high2Bar, high2, high1Bar, high1, color=color.blue, width=2)
if not na(lowLine)
line.delete(lowLine)
if not na(low1) and not na(low2)
lowLine := line.new(low2Bar, low2, low1Bar, low1, color=color.purple, width=2)
if not na(h1Line)
line.delete(h1Line)
if not na(high1)
h1Line := line.new(high1Bar, high1, bar_index, high1, xloc=xloc.bar_index, extend=extend.right, color=color.green, style=line.style_dashed)
if not na(l1Line)
line.delete(l1Line)
if not na(low1)
l1Line := line.new(low1Bar, low1, bar_index, low1, xloc=xloc.bar_index, extend=extend.right, color=color.red, style=line.style_dashed)
segHigh := high
segHighBar := bar_index
segLow := low
segLowBar := bar_index
// 10. 更新方向
direction := currDir
// 11. 突破訊號:收盤首次突破 H1 且 ma5>ma10>ma20
buySignal = not na(high1) and ta.crossover(close, high1) and ma5 > ma10 and ma10 > ma20
if buySignal
label.new(bar_index, low, "突破", style=label.style_label_up, color=color.green, textcolor=color.white)
// 12. 回買訊號:L1 之後任一 K 棒,首次收盤突破 MA5,且高於 L1、漲幅>2%、ma5>ma10>ma20、且收盤>ma20
buyBackSignal = not na(low1) and bar_index > low1Bar and ta.crossover(close, ma5) and high > low1 and (close - open) / open > 0.02 and ma5 > ma10 and ma10 > ma20 and close > ma20 and not buyBackShown
if buyBackSignal
label.new(bar_index, low, "回買", style=label.style_label_up, color=color.green, textcolor=color.white)
buyBackShown := true
// 13. 月季線交叉且四線多頭排列時,在 K 棒正下方標示放大三角形
if ta.cross(ma20, ma60) and ma5 > ma10 and ma10 > ma20 and ma20 > ma60
label.new(bar_index, low, "▲", xloc=xloc.bar_index, yloc=yloc.belowbar, style=label.style_label_center, color=color.new(color.white, 100), textcolor=color.white, size=size.large)
indicator("MA5 — 四點高低 + H1/L1 水平線 + 突破/回買 + 月季線交叉", overlay=true)
// 1. 均線設定
ma5 = ta.sma(close, 5)
ma10 = ta.sma(close, 10)
ma20 = ta.sma(close, 20)
ma60 = ta.sma(close, 60) // ← 加上這一行
// 畫出均線
plot(ma5, title="MA5", color=color.red)
plot(ma10, title="MA10", color=color.orange)
plot(ma20, title="MA20", color=color.yellow)
plot(ma60, title="MA60", color=color.green)
// 2. 全域變數:方向、區段極值
var int direction = na
var float segHigh = na
var int segHighBar = na
var float segLow = na
var int segLowBar = na
// 3. 全域變數:儲存兩組高低
var float high1 = na
var int high1Bar = na
var float high2 = na
var int high2Bar = na
var float low1 = na
var int low1Bar = na
var float low2 = na
var int low2Bar = na
// 4. 全域變數:標籤與線段句柄
var label highLbl1 = na
var label highLbl2 = na
var label lowLbl1 = na
var label lowLbl2 = na
var line highLine = na
var line lowLine = na
var line h1Line = na
var line l1Line = na
// 5. 全域變數:回買訊號控制
var bool buyBackShown = false
// 6. 判斷當前段方向
currDir = close > ma5 ? 1 : close < ma5 ? -1 : direction
// 7. 首次初始化
if na(direction)
direction := currDir
segHigh := high
segHighBar := bar_index
segLow := low
segLowBar := bar_index
// 8. 同段內更新極值
if currDir == 1 and high > segHigh
segHigh := high
segHighBar := bar_index
if currDir == -1 and low < segLow
segLow := low
segLowBar := bar_index
// 9. 段落切換:推舊值→更新 H1/L1→刪舊標籤/線→畫新標籤/線→重置 seg*
if currDir != direction
high2 := high1
high2Bar := high1Bar
low2 := low1
low2Bar := low1Bar
if direction == 1
high1 := segHigh
high1Bar := segHighBar
else
low1 := segLow
low1Bar := segLowBar
buyBackShown := false
if not na(highLbl1)
label.delete(highLbl1)
if not na(highLbl2)
label.delete(highLbl2)
if not na(lowLbl1)
label.delete(lowLbl1)
if not na(lowLbl2)
label.delete(lowLbl2)
if not na(high2)
highLbl2 := label.new(high2Bar, high2, "H2", style=label.style_label_down, color=color.blue, textcolor=color.white)
if not na(high1)
highLbl1 := label.new(high1Bar, high1, "H1", style=label.style_label_down, color=color.blue, textcolor=color.white)
if not na(low2)
lowLbl2 := label.new(low2Bar, low2, "L2", style=label.style_label_up, color=color.purple, textcolor=color.white)
if not na(low1)
lowLbl1 := label.new(low1Bar, low1, "L1", style=label.style_label_up, color=color.purple, textcolor=color.white)
if not na(highLine)
line.delete(highLine)
if not na(high1) and not na(high2)
highLine := line.new(high2Bar, high2, high1Bar, high1, color=color.blue, width=2)
if not na(lowLine)
line.delete(lowLine)
if not na(low1) and not na(low2)
lowLine := line.new(low2Bar, low2, low1Bar, low1, color=color.purple, width=2)
if not na(h1Line)
line.delete(h1Line)
if not na(high1)
h1Line := line.new(high1Bar, high1, bar_index, high1, xloc=xloc.bar_index, extend=extend.right, color=color.green, style=line.style_dashed)
if not na(l1Line)
line.delete(l1Line)
if not na(low1)
l1Line := line.new(low1Bar, low1, bar_index, low1, xloc=xloc.bar_index, extend=extend.right, color=color.red, style=line.style_dashed)
segHigh := high
segHighBar := bar_index
segLow := low
segLowBar := bar_index
// 10. 更新方向
direction := currDir
// 11. 突破訊號:收盤首次突破 H1 且 ma5>ma10>ma20
buySignal = not na(high1) and ta.crossover(close, high1) and ma5 > ma10 and ma10 > ma20
if buySignal
label.new(bar_index, low, "突破", style=label.style_label_up, color=color.green, textcolor=color.white)
// 12. 回買訊號:L1 之後任一 K 棒,首次收盤突破 MA5,且高於 L1、漲幅>2%、ma5>ma10>ma20、且收盤>ma20
buyBackSignal = not na(low1) and bar_index > low1Bar and ta.crossover(close, ma5) and high > low1 and (close - open) / open > 0.02 and ma5 > ma10 and ma10 > ma20 and close > ma20 and not buyBackShown
if buyBackSignal
label.new(bar_index, low, "回買", style=label.style_label_up, color=color.green, textcolor=color.white)
buyBackShown := true
// 13. 月季線交叉且四線多頭排列時,在 K 棒正下方標示放大三角形
if ta.cross(ma20, ma60) and ma5 > ma10 and ma10 > ma20 and ma20 > ma60
label.new(bar_index, low, "▲", xloc=xloc.bar_index, yloc=yloc.belowbar, style=label.style_label_center, color=color.new(color.white, 100), textcolor=color.white, size=size.large)
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.