OPEN-SOURCE SCRIPT

H

150
//version=5
indicator("H", overlay=true)

// 設定計算的周期
length = input(30, title="Length")

// 計算最近的高點和低點
highestHigh = ta.highest(high, length)
lowestLow = ta.lowest(low, length)

// 畫出支撐和壓力線
line.new(x1=bar_index[length - 2], y1=highestHigh, x2=bar_index, y2=highestHigh, color=color.red, width=2, extend=extend.right)
line.new(x1=bar_index[length - 2], y1=lowestLow, x2=bar_index, y2=lowestLow, color=color.blue, width=2, extend=extend.right)

// --- SAR 計算與背景顏色 ---
sar = ta.sar(0.3, 0.3, 0.11)
bgcolor(close > sar ? color.new(color.red, 80) : color.new(color.green, 80))
// Hide the SAR plot by setting color with full transparency using `color.new`
plot(sar, style=plot.style_cross, color=color.new(color.blue, 100), linewidth=2)

// --- 定義時間範圍 ---
var int startHour = 8
var int startMinute = 45
var int endHour = 13
var int endMinute = 45

// 取得當前時間
currentTime = timestamp("GMT+8", year, month, dayofmonth, hour, minute)
startTime = timestamp("GMT+8", year, month, dayofmonth, startHour, startMinute)
endTime = timestamp("GMT+8", year, month, dayofmonth, endHour, endMinute)

// 價差計算
ix0001_price = request.security("IX0001", "1", close)
txf1_price = request.security("TXF1!", "1", close)
price_diff = (ix0001_price - txf1_price) / txf1_price

// 判斷條件:價差達到正或負0.004%且在指定時間範圍內
positive_condition = (price_diff >= 0.004) and (currentTime >= startTime) and (currentTime <= endTime)
negative_condition = (price_diff <= -0.004) and (currentTime >= startTime) and (currentTime <= endTime)

// 根據條件變更背景顏色
bgcolor(positive_condition ? color.new(color.red, 40) : na)
bgcolor(negative_condition ? color.new(color.green, 40) : na)

// --- KD Divergence Marker for 9,3 ---
k_9 = ta.sma(ta.stoch(close, high, low, 9), 3)
d_9 = ta.sma(k_9, 3)

var float lastHighPrice_9 = na
var float lastLowPrice_9 = na
var float lastHighKD_9 = na
var float lastLowKD_9 = na

isTopDivergence_9 = (k_9 > 93 and close < lastHighPrice_9 and k_9 < lastHighKD_9)
isBottomDivergence_9 = (k_9 < 15 and close > lastLowPrice_9 and k_9 > lastLowKD_9)

if ta.crossover(k_9, 97)
lastHighPrice_9 := high
lastHighKD_9 := k_9

if ta.crossunder(k_9, 15)
lastLowPrice_9 := close
lastLowKD_9 := k_9

plotshape(series=isTopDivergence_9, location=location.abovebar, color=color.orange, style=shape.labeldown, text="頂部轉折")
plotshape(series=isBottomDivergence_9, location=location.belowbar, color=color.green, style=shape.labelup, text="底部轉折")

// --- KD Divergence Marker for 14,3 ---
k_14 = ta.sma(ta.stoch(close, high, low, 14), 3)
d_14 = ta.sma(k_14, 3)

var float lastHighPrice_14 = na
var float lastLowPrice_14 = na
var float lastHighKD_14 = na
var float lastLowKD_14 = na

isTopDivergence_14 = (k_14 > 93 and close < lastHighPrice_14 and k_14 < lastHighKD_14)
isBottomDivergence_14 = (k_14 < 15 and close > lastLowPrice_14 and k_14 > lastLowKD_14)

if ta.crossover(k_14, 97)
lastHighPrice_14 := high
lastHighKD_14 := k_14

if ta.crossunder(k_14, 15)
lastLowPrice_14 := close
lastLowKD_14 := k_14

plotshape(series=isTopDivergence_14, location=location.abovebar, color=color.orange, style=shape.labeldown, text="頂部轉折")
plotshape(series=isBottomDivergence_14, location=location.belowbar, color=color.green, style=shape.labelup, text="底部轉折")

// --- Range Breakout ---
// Define the range
range_length = 23
highest_high = ta.highest(high, range_length)
lowest_low = ta.lowest(low, range_length)

// Determine if price is within the range
isInRange = (close >= lowest_low and close <= highest_high)

// Track when price re-enters the range after leaving it
var bool leftRange = false

if close < lowest_low or close > highest_high
leftRange := true
if leftRange and close >= lowest_low and close <= highest_high
leftRange := false

// Plot range only when price is within range
plot(isInRange and not leftRange ? highest_high : na, title="最高盤整區間", color=color.red, linewidth=1, style=plot.style_stepline)
plot(isInRange and not leftRange ? lowest_low : na, title="最低盤整區間", color=color.green, linewidth=1, style=plot.style_stepline)

// --- Volume Crossover Indicator ---
short_ma_length = 5
long_ma_length = 10
volume_multiplier = 3.5

short_ma_volume = ta.sma(volume, short_ma_length)
long_ma_volume = ta.sma(volume, long_ma_length)

current_volume_ratio = volume / short_ma_volume
crossover_condition = ta.crossover(short_ma_volume, long_ma_volume)
volume_condition = current_volume_ratio > volume_multiplier

plotshape(series=crossover_condition and volume_condition and isInRange, location=location.abovebar, color=color.red, style=shape.labelup, text="變盤")

Thông báo miễn trừ trách nhiệm

Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.