本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Motion Flow [Quanty] - v0.9 - 2026-11-05 - awaiting first compile
// Research. Build. Refine.
// Tick 1h, 4h, daily or weekly, any number at once, separately for high/low lines and for separators. A period that takes the previous period's high only (HH + HL) is bullish, the low only
// (LH + LL) is bearish, both or neither is range. The tag shows the state and how many periods in a row it has held.
// No plot, no scale.
indicator("Motion Flow [Quanty]", shorttitle="Quanty MFLOW", overlay=true, max_lines_count=500, max_labels_count=8)
hl1h = input.bool(false, "1h", inline="hl", group="High / Low")
hl4h = input.bool(false, "4h", inline="hl", group="High / Low")
hlD = input.bool(true, "Daily", inline="hl", group="High / Low")
hlW = input.bool(false, "Weekly", inline="hl", group="High / Low")
sep1h = input.bool(false, "1h", inline="sep", group="Separators")
sep4h = input.bool(false, "4h", inline="sep", group="Separators")
sepD = input.bool(true, "Daily", inline="sep", group="Separators")
sepW = input.bool(false, "Weekly", inline="sep", group="Separators")
keep = input.int(15, "Periods shown", minval=1, maxval=30)
showTag = input.bool(true, "State tag")
colUp = input.color(#0FA88A, "Bullish")
colDn = input.color(#E23D4B, "Bearish")
colRng = input.color(#8A94A6, "Range")
type Tf
string name
int secs
bool onHL
bool onSep
int width
array<line> stack
float curH
float curL
float prevH
float prevL
line hi
line lo
label tag
int last = 0
int streak = 0
method state(Tf t) =>
bool tookH = t.curH > t.prevH
bool tookL = t.curL < t.prevL
tookH and not tookL ? 1 : tookL and not tookH ? -1 : 0
stateColor(int s) =>
s == 1 ? colUp : s == -1 ? colDn : colRng
stateName(int s) =>
s == 1 ? "Bullish" : s == -1 ? "Bearish" : "Range"
method step(Tf t, bool isNew) =>
if (t.onHL or t.onSep) and timeframe.in_seconds() <= t.secs
if isNew
if not na(t.prevH)
int done = t.state()
t.streak := done == t.last ? t.streak + 1 : 1
t.last := done
t.prevH := t.curH
t.prevL := t.curL
t.curH := high
t.curL := low
if t.onHL
t.hi := line.new(time, high, time_close, high, xloc=xloc.bar_time, color=colRng, width=t.width, force_overlay=true)
t.lo := line.new(time, low, time_close, low, xloc=xloc.bar_time, color=colRng, width=t.width, force_overlay=true)
t.stack.push(t.hi)
t.stack.push(t.lo)
if t.onSep
t.stack.push(line.new(time, high, time, low, xloc=xloc.bar_time, extend=extend.both, color=color.new(colRng, 70), width=1, force_overlay=true))
while t.stack.size() > keep * 3
line.delete(t.stack.shift())
else if not na(t.hi)
if high > t.curH
t.curH := high
line.set_y1(t.hi, high)
line.set_y2(t.hi, high)
if low < t.curL
t.curL := low
line.set_y1(t.lo, low)
line.set_y2(t.lo, low)
if not na(t.hi)
int now = t.state()
color c = stateColor(now)
line.set_x2(t.hi, time_close)
line.set_x2(t.lo, time_close)
line.set_color(t.hi, c)
line.set_color(t.lo, c)
if showTag and not na(t.prevH)
int run = now == t.last ? t.streak + 1 : 1
if na(t.tag)
t.tag := label.new(time_close, t.curH, "", xloc=xloc.bar_time, style=label.style_label_left, color=color.new(c, 100), size=size.tiny, force_overlay=true)
label.set_xy(t.tag, time_close, t.curH)
label.set_text(t.tag, t.name + " " + stateName(now) + " " + str.tostring(run))
label.set_textcolor(t.tag, c)
var Tf tf1 = Tf.new("1H", 3600, hl1h, sep1h, 1, array.new<line>())
var Tf tf4 = Tf.new("4H", 14400, hl4h, sep4h, 1, array.new<line>())
var Tf tfD = Tf.new("D", 86400, hlD, sepD, 2, array.new<line>())
var Tf tfW = Tf.new("W", 604800, hlW, sepW, 3, array.new<line>())
bool c1 = timeframe.change("60")
bool c4 = timeframe.change("240")
bool cD = timeframe.change("D")
bool cW = timeframe.change("W")
tfW.step(cW)
tfD.step(cD)
tf4.step(c4)
tf1.step(c1)