Perfected FlowScript
key level
MTF Open Levels (Calendar Math) is indexed as 203_key_level.flowscript. The exact FlowScript is viewable here; chart observe and trading automation use the current mmflow chart/recipe signal proxy until FlowScript v2 transpilation is available.
This exact FlowScript uses the v2 source dialect. It is viewable and connected to the chart/automation proxy, but direct editor execution needs the FlowScript v2 transpiler.
Dialect
flowscript-v2
Compatibility
flowscript-v2-needs-transpile
Position
onchart
Axis
false
Size
3.9 KB
Lines
128
Native Signal Candidates
6 source-level chart marker triggers extracted from guarded FlowScript v2 blocks.
Daily Open reclaim buy
line 100:5
Trigger
close > val_d && close[1] <= val_d[1]
Value
val_d
Deps
close:builtin, val_d:static
Daily Open breakdown sell
line 100:5
Trigger
close < val_d && close[1] >= val_d[1]
Value
val_d
Deps
close:builtin, val_d:static
Weekly Open reclaim buy
line 110:5
Trigger
close > val_w && close[1] <= val_w[1]
Value
val_w
Deps
close:builtin, val_w:static
Weekly Open breakdown sell
line 110:5
Trigger
close < val_w && close[1] >= val_w[1]
Value
val_w
Deps
close:builtin, val_w:static
Monthly Open reclaim buy
line 120:5
Trigger
close > val_m && close[1] <= val_m[1]
Value
val_m
Deps
close:builtin, val_m:static
Monthly Open breakdown sell
line 120:5
Trigger
close < val_m && close[1] >= val_m[1]
Value
val_m
Deps
close:builtin, val_m:static
203_key_level.flowscript
source path: kscripts/perfected/203_key_level.flowscript · sha256:f120a8d042683122ee9a0dac611b417596635b09940d9417d4af047459f3cf4a
//@version=2
// Source: kiyotaka.ai/hub/kscript (original)
define(
title="MTF Open Levels (Calendar Math)",
position="onchart",
axis=false
)
// -----------------------------------------------------------------------------
// User Inputs
// -----------------------------------------------------------------------------
var showDaily = input(name="showDaily", type="boolean", defaultValue=true, label="Show Daily Open")
var dailyColor = input(name="dailyColor", type="color", defaultValue="#2962ff", label="Daily Open Color")
var showWeekly = input(name="showWeekly", type="boolean", defaultValue=true, label="Show Weekly Open")
var weeklyColor = input(name="weeklyColor", type="color", defaultValue="#ff6d00", label="Weekly Open Color")
var showMonthly = input(name="showMonthly", type="boolean", defaultValue=true, label="Show Monthly Open")
var monthlyColor = input(name="monthlyColor", type="color", defaultValue="#d50000", label="Monthly Open Color")
var dotSize = input(name="dotSize", type="number", defaultValue=2, label="Line Thickness")
// -----------------------------------------------------------------------------
// Data Sources (Global Timeseries)
// -----------------------------------------------------------------------------
timeseries bars = ohlcv(symbol=currentSymbol, exchange=currentExchange)
timeseries t = bars.time
timeseries o = bars.open
// 确保在数据加载完成前不执行后续计算,防止 NaN 报错
if (isnan(t[0]) || isnan(o[0])) {
return
}
// -----------------------------------------------------------------------------
// Calculations: The "Perpetual Calendar" Algorithm
// -----------------------------------------------------------------------------
// === 1. 日线 (Daily) ===
// 86400000 = 1天的毫秒数
var day_id = math.floor(t[0] / 86400000)
static last_day_id = -1
static val_d = 0.0
if (last_day_id == -1) {
last_day_id = day_id
val_d = o[0]
} else if (day_id > last_day_id) {
last_day_id = day_id
val_d = o[0]
}
// === 2. 周线 (Weekly) ===
// 1970-01-01 是周四。为了让周一作为新一周起点,偏移3天。
var week_id = math.floor((day_id + 3) / 7)
static last_week_id = -1
static val_w = 0.0
if (last_week_id == -1) {
last_week_id = week_id
val_w = o[0]
} else if (week_id > last_week_id) {
last_week_id = week_id
val_w = o[0]
}
// === 3. 月线 (Monthly - Precise Calendar Math) ===
var z = day_id + 719468
var era = math.floor(z / 146097)
var doe = z - era * 146097
var yoe = math.floor((doe - math.floor(doe / 1460) + math.floor(doe / 36524) - math.floor(doe / 146096)) / 365)
var y = yoe + era * 400
var doy = doe - (365 * yoe + math.floor(yoe / 4) - math.floor(yoe / 100))
var mp = math.floor((5 * doy + 2) / 153)
var m = mp + (mp < 10 ? 3 : -9)
var year_final = y + (m <= 2 ? 1 : 0)
var month_id = year_final * 12 + m
static last_month_id = -1
static val_m = 0.0
if (last_month_id == -1) {
last_month_id = month_id
val_m = o[0]
} else if (month_id > last_month_id) {
last_month_id = month_id
val_m = o[0]
}
// -----------------------------------------------------------------------------
// Plotting (Using professional step lines)
// -----------------------------------------------------------------------------
if (showDaily) {
plotLine(
value = val_d,
width = dotSize,
colors = [dailyColor],
label = ["Daily Open"],
desc = ["Start price of the current day (00:00 UTC)"]
)
}
if (showWeekly) {
plotLine(
value = val_w,
width = dotSize,
colors = [weeklyColor],
label = ["Weekly Open"],
desc = ["Start price of the current week (Monday 00:00 UTC)"]
)
}
if (showMonthly) {
plotLine(
value = val_m,
width = dotSize,
colors = [monthlyColor],
label = ["Monthly Open"],
desc = ["Start price of the current calendar month (1st Day)"]
)
}