Script API
api
This page is only available in Chinese. It is shown in its original language.
Script API
本文与代码提示框使用同一份类型契约和注释。修改源码注释后运行 pnpm docs:script:generate,使用 pnpm docs:script:check 校验同步状态。
目录
- Color
- Color.Red
- Color.DeepOrange
- Color.Orange
- Color.Amber
- Color.Yellow
- Color.Lime
- Color.LightGreen
- Color.Green
- Color.Teal
- Color.Cyan
- Color.LightBlue
- Color.Blue
- Color.Indigo
- Color.Purple
- Color.Pink
- Color.Brown
- Color.BlueGray
- Color.Gray
- Color.Foreground
- Color.White
- Color.Black
- LineStyle
- LineStyle.style_solid
- LineStyle.style_dashed
- LineStyle.style_dotted
- LineStyle.style_arrow_left
- LineStyle.style_arrow_right
- LineStyle.style_arrow_both
- extend
- extend.none
- extend.left
- extend.right
- extend.both
- xloc
- xloc.bar_index
- xloc.bar_time
- yloc
- yloc.price
- DataSource
- DataSource.Binance
- DataSource.Gotdx
- DataSource.BaoStock
- DataSource.TradingView
- DataSource.MT5
- DataSource.THS
- DataSource.Mock
- Timeframe
- Timeframe.Minute1
- Timeframe.Minute5
- Timeframe.Minute15
- Timeframe.Minute30
- Timeframe.Hour1
- Timeframe.Hour4
- Timeframe.Day
- Timeframe.Week
- Timeframe.Month1
- Timeframe.Month3
- Timeframe.Month12
- PlotKind
- PlotKind.Line
- PlotKind.LineBR
- PlotKind.StepLine
- PlotKind.StepLineBR
- PlotKind.Histogram
- PlotKind.Columns
- PlotKind.Points
- PlotKind.Shape
- PlotKind.Char
- PlotKind.Arrow
- PlotKind.Candle
- PlotKind.Bar
- Format
- Format.Price
- Format.Volume
- Format.Percent
- Format.Mintick
- HLineStyle
- HLineStyle.style_solid
- HLineStyle.style_dashed
- HLineStyle.style_dotted
- ShapeStyle
- ShapeStyle.XCross
- ShapeStyle.Cross
- ShapeStyle.Circle
- ShapeStyle.Square
- ShapeStyle.Diamond
- ShapeStyle.TriangleUp
- ShapeStyle.TriangleDown
- ShapeStyle.ArrowUp
- ShapeStyle.ArrowDown
- ShapeStyle.LabelUp
- ShapeStyle.LabelDown
- ShapeStyle.Flag
- ShapeLocation
- ShapeLocation.AboveBar
- ShapeLocation.BelowBar
- ShapeLocation.Top
- ShapeLocation.Bottom
- ShapeLocation.Absolute
- ShapeSize
- ShapeSize.Auto
- ShapeSize.Tiny
- ShapeSize.Small
- ShapeSize.Normal
- ShapeSize.Large
- ShapeSize.Huge
- console
- console.log
- console.info
- console.warn
- console.error
- console.debug
- box
- box.new
- box.all
- box.set_left
- box.set_top
- box.set_right
- box.set_bottom
- box.set_lefttop
- box.set_rightbottom
- box.set_top_left_point
- box.set_bottom_right_point
- box.set_xloc
- box.set_extend
- box.set_bgcolor
- box.set_border_color
- box.set_border_width
- box.set_border_style
- box.set_text
- box.set_text_color
- box.set_text_size
- box.set_text_halign
- box.set_text_valign
- box.get_left
- box.get_top
- box.get_right
- box.get_bottom
- box.copy
- box.delete
- label
- label.style_none
- label.new
- label.all
- label.set_x
- label.set_y
- label.set_xy
- label.set_text
- label.set_textcolor
- label.set_size
- label.set_textalign
- label.set_yoffset
- label.get_x
- label.get_y
- label.get_text
- label.get_yoffset
- label.copy
- label.delete
- barstate
- barstate.islast
- open
- high
- low
- close
- volume
- time
- bar_index
- bar_index.toString
- bar_index.toFixed
- bar_index.toExponential
- bar_index.toPrecision
- bar_index.valueOf
- bar_index.toLocaleString
- line
- line.style_solid
- line.style_dashed
- line.style_dotted
- line.style_arrow_left
- line.style_arrow_right
- line.style_arrow_both
- line.new
- line.all
- line.set_xy1
- line.set_xy2
- line.set_x1
- line.set_y1
- line.set_x2
- line.set_y2
- line.set_color
- line.set_style
- line.set_width
- line.set_extend
- line.get_x1
- line.get_y1
- line.get_x2
- line.get_y2
- line.get_color
- line.get_style
- line.get_width
- line.get_extend
- line.get_price
- line.copy
- line.delete
- chart
- chart.point
- chart.point.new
- chart.point.now
- chart.point.from_index
- chart.point.from_time
- chart.point.copy
- ta
- ta.rising
- ta.falling
- ta.change
- ta.sma
- ta.sum
- ta.maxsum
- ta.highest
- ta.lowest
- ta.pivothigh
- ta.pivotlow
- ta.highestbars
- ta.lowestbars
- ta.rma
- ta.swma
- ta.alma
- ta.stddev
- ta.ema
- ta.dema
- ta.tema
- ta.t3
- ta.trima
- ta.macd
- ta.wma
- ta.hma
- ta.linreg
- ta.cci
- ta.vwma
- ta.rsi
- ta.stoch
- ta.atr
- ta.supertrend
- ta.mom
- ta.roc
- ta.cmo
- ta.crossover
- ta.crossunder
- Position
- Position.Main
- Position.Sub
- input
- input.int
- input.float
- input.bool
- input.string
- input.timeframe
- defineIndicator
- derive
- plot
- plot.Line
- plot.LineBR
- plot.StepLine
- plot.StepLineBR
- plot.Histogram
- plot.Columns
- plot.Point
- plot.Shape
- plot.Char
- plot.Arrow
- plot.Candle
- plot.Bar
- fill
- fill
- hline
- defineLibrary
- importLibrary
- request
- request.security
- syminfo
- syminfo.tickerid
全局 API
Color
Color: typeof Color@summary 常用色
常用色:主题色别名 + 白 / 黑两个绝对色。
脚本里用 Color.Red 即可;别名与 Theme.colors.scriptPalette 的键一一对应。
Color.Red
Color.Red = "@red"@summary 红
Color.DeepOrange
Color.DeepOrange = "@deepOrange"@summary 深橙
Color.Orange
Color.Orange = "@orange"@summary 橙
Color.Amber
Color.Amber = "@amber"@summary 琥珀
Color.Yellow
Color.Yellow = "@yellow"@summary 黄
Color.Lime
Color.Lime = "@lime"@summary 青柠
Color.LightGreen
Color.LightGreen = "@lightGreen"@summary 浅绿
Color.Green
Color.Green = "@green"@summary 绿
Color.Teal
Color.Teal = "@teal"@summary 蓝绿
Color.Cyan
Color.Cyan = "@cyan"@summary 青
Color.LightBlue
Color.LightBlue = "@lightBlue"@summary 浅蓝
Color.Blue
Color.Blue = "@blue"@summary 蓝
Color.Indigo
Color.Indigo = "@indigo"@summary 靛蓝
Color.Purple
Color.Purple = "@purple"@summary 紫
Color.Pink
Color.Pink = "@pink"@summary 粉
Color.Brown
Color.Brown = "@brown"@summary 棕
Color.BlueGray
Color.BlueGray = "@blueGray"@summary 蓝灰
Color.Gray
Color.Gray = "@gray"@summary 灰
Color.Foreground
Color.Foreground = "@foreground"@summary 前景
Color.White
Color.White = "#ffffff"@summary 白
Color.Black
Color.Black = "#000000"@summary 黑
LineStyle
LineStyle: typeof LineStyle线型:实线、虚线与箭头;手绘和 line API 共用。
LineStyle.style_solid
LineStyle.style_solid = "solid"@summary 实线
LineStyle.style_dashed
LineStyle.style_dashed = "dashed"@summary 虚线
LineStyle.style_dotted
LineStyle.style_dotted = "dotted"@summary 点线
LineStyle.style_arrow_left
LineStyle.style_arrow_left = "arrow_left"@summary 左箭头
LineStyle.style_arrow_right
LineStyle.style_arrow_right = "arrow_right"@summary 右箭头
LineStyle.style_arrow_both
LineStyle.style_arrow_both = "arrow_both"@summary 双箭头
extend
extend: typeof extend延伸沿两锚点的参数方向,与屏幕左右方向无关。
extend.none
extend.none = "none"@summary 不延伸
extend.left
extend.left = "left"@summary 延伸至起点之外
extend.right
extend.right = "right"@summary 延伸至终点之外
extend.both
extend.both = "both"@summary 两端延伸
xloc
xloc: typeof xloc决定 X 是第几根 K 线还是毫秒时间戳。
bar_index 从当前已加载数据的第一根算起;左侧加载更多历史后,同一根 K 线的序号会变大。 允许范围是 0 到当前 bar_index,再向右最多 500 根;越界直接报错。 要让线段跨历史保持在固定的 K 线上,用 bar_time 传 time[offset]。
xloc.bar_index
xloc.bar_index = "bar_index"@summary 第几根 K 线
xloc.bar_time
xloc.bar_time = "bar_time"@summary 毫秒时间戳
yloc
yloc: typeof yloc价格文字锚点;其他定位方式待公共绘图模型支持后再开放。
yloc.price
yloc.price = "price"DataSource
DataSource: typeof DataSource@summary 数据源
内置数据源身份;指定后严格路由,不做跨来源回退。
DataSource.Binance
DataSource.Binance = "binance"@summary 币安
DataSource.Gotdx
DataSource.Gotdx = "gotdx"@summary 通达信
DataSource.BaoStock
DataSource.BaoStock = "baostock"@summary 证券宝
DataSource.TradingView
DataSource.TradingView = "tradingview"@summary TradingView
DataSource.MT5
DataSource.MT5 = "mt5"@summary MetaTrader 5
DataSource.THS
DataSource.THS = "ths"@summary 同花顺
DataSource.Mock
DataSource.Mock = "mock"@summary 模拟数据
Timeframe
Timeframe: typeof Timeframe@summary 目标周期
脚本 request.security 的目标周期,由宿主注入为 VM 全局枚举。
取值是周期短写法,只登记图表已支持的周期;需要新周期时先扩 KLinePeriod,
再在这里登记对应写法,宿主侧 requestPeriod 不接受未登记的值。
Timeframe.Minute1
Timeframe.Minute1 = "1"@summary 1 分钟
Timeframe.Minute5
Timeframe.Minute5 = "5"@summary 5 分钟
Timeframe.Minute15
Timeframe.Minute15 = "15"@summary 15 分钟
Timeframe.Minute30
Timeframe.Minute30 = "30"@summary 30 分钟
Timeframe.Hour1
Timeframe.Hour1 = "60"@summary 1 小时
Timeframe.Hour4
Timeframe.Hour4 = "240"@summary 4 小时
Timeframe.Day
Timeframe.Day = "D"@summary 日线
Timeframe.Week
Timeframe.Week = "W"@summary 周线
Timeframe.Month1
Timeframe.Month1 = "M"@summary 月线
Timeframe.Month3
Timeframe.Month3 = "3M"@summary 季线
Timeframe.Month12
Timeframe.Month12 = "12M"@summary 年线
PlotKind
PlotKind: typeof PlotKind@summary 绘图类型
脚本 plot.* 的图形种类;取值与 Plot 声明的 kind 完全一致。
PlotKind.Line
PlotKind.Line = "line"@summary 折线
PlotKind.LineBR
PlotKind.LineBR = "linebr"@summary 断线折线
PlotKind.StepLine
PlotKind.StepLine = "stepline"@summary 阶梯线
PlotKind.StepLineBR
PlotKind.StepLineBR = "steplinebr"@summary 断线阶梯线
PlotKind.Histogram
PlotKind.Histogram = "histogram"@summary 柱状图
PlotKind.Columns
PlotKind.Columns = "columns"@summary 柱形图
PlotKind.Points
PlotKind.Points = "points"@summary 散点
PlotKind.Shape
PlotKind.Shape = "shape"@summary 形状标记
PlotKind.Char
PlotKind.Char = "char"@summary 字符标记
PlotKind.Arrow
PlotKind.Arrow = "arrow"@summary 箭头
PlotKind.Candle
PlotKind.Candle = "candle"@summary 蜡烛图
PlotKind.Bar
PlotKind.Bar = "bar"@summary 美国线
Format
Format: typeof Format@summary 数值格式
数值格式化档位;脚本里用 Format.Volume 即可,不填时按 Format.Price 处理。
| 成员 | 示例 |
|---|---|
Format.Price | 1234.567 |
Format.Volume | 1.25K、12.30M、3.40B |
Format.Percent | 3.45%、-12.30% |
Format.Mintick | 1234.5678901 |
Format.Price
Format.Price = "price"@summary 价格
Format.Volume
Format.Volume = "volume"@summary 成交量
Format.Percent
Format.Percent = "percent"@summary 百分比
Format.Mintick
Format.Mintick = "mintick"@summary 最小变动单位
HLineStyle
HLineStyle: typeof HLineStyle@summary 水平线线型
hline 的线型档位;与 Pine 的 hline.style_* 对应。
HLineStyle.style_solid
HLineStyle.style_solid = "solid"@summary 实线
HLineStyle.style_dashed
HLineStyle.style_dashed = "dashed"@summary 虚线
HLineStyle.style_dotted
HLineStyle.style_dotted = "dotted"@summary 点线
ShapeStyle
ShapeStyle: typeof ShapeStyle@summary 标记形状
固定形状标记可选的外形;缺省使用 XCross。
ShapeStyle.XCross
ShapeStyle.XCross = "xcross"@summary X 叉
ShapeStyle.Cross
ShapeStyle.Cross = "cross"@summary 十字
ShapeStyle.Circle
ShapeStyle.Circle = "circle"@summary 圆
ShapeStyle.Square
ShapeStyle.Square = "square"@summary 方形
ShapeStyle.Diamond
ShapeStyle.Diamond = "diamond"@summary 菱形
ShapeStyle.TriangleUp
ShapeStyle.TriangleUp = "triangleup"@summary 上三角
ShapeStyle.TriangleDown
ShapeStyle.TriangleDown = "triangledown"@summary 下三角
ShapeStyle.ArrowUp
ShapeStyle.ArrowUp = "arrowup"@summary 上箭头
ShapeStyle.ArrowDown
ShapeStyle.ArrowDown = "arrowdown"@summary 下箭头
ShapeStyle.LabelUp
ShapeStyle.LabelUp = "labelup"@summary 上标签
ShapeStyle.LabelDown
ShapeStyle.LabelDown = "labeldown"@summary 下标签
ShapeStyle.Flag
ShapeStyle.Flag = "flag"@summary 旗形
ShapeLocation
ShapeLocation: typeof ShapeLocation@summary 标记位置
标记相对 K 线的位置;缺省在 K 线上方,Absolute 表示按价格定位。
ShapeLocation.AboveBar
ShapeLocation.AboveBar = "abovebar"@summary 上方
ShapeLocation.BelowBar
ShapeLocation.BelowBar = "belowbar"@summary 下方
ShapeLocation.Top
ShapeLocation.Top = "top"@summary 顶部
ShapeLocation.Bottom
ShapeLocation.Bottom = "bottom"@summary 底部
ShapeLocation.Absolute
ShapeLocation.Absolute = "absolute"@summary 按价格定位
ShapeSize
ShapeSize: typeof ShapeSize@summary 尺寸档位
图形尺寸档位;size 不填则使用 Auto,各档位的尺寸如下。
| 档位 | 折线宽度(px) | 散点直径(px) | 形状 / 字符外框边长(px) | 箭头最大高度(px) | Histogram 柱宽(px) |
|---|---|---|---|---|---|
| ShapeSize.Auto | 1 | 3 | 12 | 50 | 1 |
| ShapeSize.Tiny | 1 | 6 | 6 | 20 | 1 |
| ShapeSize.Small | 1 | 10 | 10 | 30 | 1 |
| ShapeSize.Normal | 2 | 14 | 14 | 40 | 2 |
| ShapeSize.Large | 3 | 20 | 20 | 60 | 3 |
| ShapeSize.Huge | 4 | 28 | 28 | 90 | 4 |
px 为逻辑像素;箭头实际高度随数值幅度变化,最短为最大高度的 10%。 Columns 不接受 size,柱宽随 K 线间距自动调整。
ShapeSize.Auto
ShapeSize.Auto = "auto"@summary 自动
ShapeSize.Tiny
ShapeSize.Tiny = "tiny"@summary 极小
ShapeSize.Small
ShapeSize.Small = "small"@summary 小
ShapeSize.Normal
ShapeSize.Normal = "normal"@summary 常规
ShapeSize.Large
ShapeSize.Large = "large"@summary 大
ShapeSize.Huge
ShapeSize.Huge = "huge"@summary 特大
console
console: { log(...values: unknown[]): void; info(...values: unknown[]): void; warn(...values: unknown[]): void; error(...values: unknown[]): void; debug(...values: unknown[]): void; }输出到编辑器底部的“输出”面板;支持多个参数和对象。
console.log
console.log(...values: unknown[]): voidconsole.info
console.info(...values: unknown[]): voidconsole.warn
console.warn(...values: unknown[]): voidconsole.error
console.error(...values: unknown[]): voidconsole.debug
console.debug(...values: unknown[]): voidbox
box: DrawingBoxApi创建、修改、读取和删除矩形;位置参数顺序与 Pine box.new 一致。
box.new
box.new(left: number, top: number, right: number, bottom: number, border_color?: Color | (string & {}), border_width?: number, border_style?: BoxBorderStyle, extend?: LineExtend, xloc?: LineXLoc, bgcolor?: Color | (string & {}), text?: string, text_size?: number, text_color?: Color | (string & {})): BoxRef
box.new(top_left: ChartPoint, bottom_right: ChartPoint, border_color?: Color | (string & {}), border_width?: number, border_style?: BoxBorderStyle, extend?: LineExtend, xloc?: LineXLoc, bgcolor?: Color | (string & {}), text?: string, text_size?: number, text_color?: Color | (string & {})): BoxRef
box.new(options: BoxOptions): BoxRefbox.all
box.all: readonly BoxRef[]box.set_left
box.set_left(id: BoxRef, left: number): voidbox.set_top
box.set_top(id: BoxRef, top: number): voidbox.set_right
box.set_right(id: BoxRef, right: number): voidbox.set_bottom
box.set_bottom(id: BoxRef, bottom: number): voidbox.set_lefttop
box.set_lefttop(id: BoxRef, left: number, top: number): voidbox.set_rightbottom
box.set_rightbottom(id: BoxRef, right: number, bottom: number): voidbox.set_top_left_point
box.set_top_left_point(id: BoxRef, point: ChartPoint): voidbox.set_bottom_right_point
box.set_bottom_right_point(id: BoxRef, point: ChartPoint): voidbox.set_xloc
box.set_xloc(id: BoxRef, left: number, right: number, xloc: LineXLoc): voidbox.set_extend
box.set_extend(id: BoxRef, extend: LineExtend): voidbox.set_bgcolor
box.set_bgcolor(id: BoxRef, color: Color | (string & {})): voidbox.set_border_color
box.set_border_color(id: BoxRef, color: Color | (string & {})): voidbox.set_border_width
box.set_border_width(id: BoxRef, width: number): voidbox.set_border_style
box.set_border_style(id: BoxRef, style: BoxBorderStyle): voidbox.set_text
box.set_text(id: BoxRef, text: string): voidbox.set_text_color
box.set_text_color(id: BoxRef, color: Color | (string & {})): voidbox.set_text_size
box.set_text_size(id: BoxRef, size: number): voidbox.set_text_halign
box.set_text_halign(id: BoxRef, align: DrawingText["align"]): voidbox.set_text_valign
box.set_text_valign(id: BoxRef, align: DrawingText["verticalAlign"]): voidbox.get_left
box.get_left(id: BoxRef): numberbox.get_top
box.get_top(id: BoxRef): numberbox.get_right
box.get_right(id: BoxRef): numberbox.get_bottom
box.get_bottom(id: BoxRef): numberbox.copy
box.copy(id: BoxRef): BoxRef | nullbox.delete
box.delete(id: BoxRef | null): voidlabel
label: DrawingLabelApi在历史 bar 的价格位置创建纯文字标签,支持 label.style_none。
label.style_none
label.style_none: "none"label.new
label.new(x: number, y: number, text?: string, xloc?: LineXLoc, yloc?: "price", color?: Color | (string & {}), style?: "none", textcolor?: Color | (string & {}), size?: number, textalign?: DrawingText["align"], offsetY?: number): LabelRef
label.new(options: LabelOptions): LabelRef绘制价格锚点标签,位置参数或选项对象二选一。
@summary 绘制标签
返回标签引用;超过 max_labels_count 时最旧的标签被回收。
label.all
label.all: readonly LabelRef[]label.set_x
label.set_x(id: LabelRef, x: number): voidlabel.set_y
label.set_y(id: LabelRef, y: number): voidlabel.set_xy
label.set_xy(id: LabelRef, x: number, y: number): voidlabel.set_text
label.set_text(id: LabelRef, text: string): voidlabel.set_textcolor
label.set_textcolor(id: LabelRef, color: Color | (string & {})): voidlabel.set_size
label.set_size(id: LabelRef, size: number): voidlabel.set_textalign
label.set_textalign(id: LabelRef, align: DrawingText["align"]): voidlabel.set_yoffset
label.set_yoffset(id: LabelRef, offsetY: number): void设置垂直偏移;逻辑像素,正数向上。
@summary 设置垂直偏移
label.get_x
label.get_x(id: LabelRef): numberlabel.get_y
label.get_y(id: LabelRef): numberlabel.get_text
label.get_text(id: LabelRef): string | nulllabel.get_yoffset
label.get_yoffset(id: LabelRef): number读取垂直偏移;标签已删除返回 0。
@summary 垂直偏移
label.copy
label.copy(id: LabelRef): LabelRef | nulllabel.delete
label.delete(id: LabelRef | null): voidbarstate
barstate: { readonly islast: boolean; }当前执行 bar 是否是本次数据的最后一根。
barstate.islast
barstate.islast: booleanopen
open: ScriptSerieshigh
high: ScriptSerieslow
low: ScriptSeriesclose
close: ScriptSeriesvolume
volume: ScriptSeriestime
time: ScriptSeriesbar_index
bar_index: number当前 K 线索引,从 0 开始。
bar_index.toString
bar_index.toString(radix?: number): stringReturns a string representation of an object.
@param radix Specifies a radix for converting numeric values to strings. This value is only used for numbers.
bar_index.toFixed
bar_index.toFixed(fractionDigits?: number): stringReturns a string representing a number in fixed-point notation.
@param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
bar_index.toExponential
bar_index.toExponential(fractionDigits?: number): stringReturns a string containing a number represented in exponential notation.
@param fractionDigits Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.
bar_index.toPrecision
bar_index.toPrecision(precision?: number): stringReturns a string containing a number represented either in exponential or fixed-point notation with a specified number of digits.
@param precision Number of significant digits. Must be in the range 1 - 21, inclusive.
bar_index.valueOf
bar_index.valueOf(): numberReturns the primitive value of the specified object.
bar_index.toLocaleString
bar_index.toLocaleString(locales?: string | string[], options?: Intl.NumberFormatOptions): string
bar_index.toLocaleString(locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions): stringConverts a number to a string by using the current or specified locale.
@param locales A locale string or array of locale strings that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
@param options An object that contains one or more properties that specify comparison options.
@param locales A locale string, array of locale strings, Intl.Locale object, or array of Intl.Locale objects that contain one or more language or locale tags. If you include more than one locale string, list them in descending order of priority so that the first entry is the preferred locale. If you omit this parameter, the default locale of the JavaScript runtime is used.
@param options An object that contains one or more properties that specify comparison options.
line
line: DrawingLineApi创建、修改、读取和删除线段,跨 bar 保留。
只能在 onBar 内新建与修改;引用只在本次运行内有效,重算后旧引用失效。
const id = line.new(bar_index, low[0], bar_index + 5, high[0])
line.set_color(id, Color.Red)line.style_solid
line.style_solid: "solid"@summary 实线
line.style_dashed
line.style_dashed: "dashed"@summary 虚线
line.style_dotted
line.style_dotted: "dotted"@summary 点线
line.style_arrow_left
line.style_arrow_left: "arrow_left"@summary 左箭头
line.style_arrow_right
line.style_arrow_right: "arrow_right"@summary 右箭头
line.style_arrow_both
line.style_arrow_both: "arrow_both"@summary 双箭头
line.new
line.new(first_point: ChartPoint, second_point: ChartPoint, xloc?: LineXLoc, extend?: LineExtend, color?: Color | (string & {}), style?: LineStyle, width?: number): LineRef
line.new(x1: number, y1: number, x2: number, y2: number, xloc?: LineXLoc, extend?: LineExtend, color?: Color | (string & {}), style?: LineStyle, width?: number): LineRef
line.new(options: LineOptions): LineRef绘制线段;两个重载分别接受 chart.point 端点与起止点的 X / Y。
@summary 绘制线段
line.all
line.all: readonly LineRef[]本次运行绘制的全部线段引用,按创建顺序;与创建返回的引用相等,可直接比较。
@summary 全部线段
line.set_xy1
line.set_xy1(id: LineRef, x: number, y: number): void同时设置起点 X 和 Y;X 的取值方式沿用创建时的 xloc。
@summary 设置起点
line.set_xy2
line.set_xy2(id: LineRef, x: number, y: number): void同时设置终点 X 和 Y;X 的取值方式沿用创建时的 xloc。
@summary 设置终点
line.set_x1
line.set_x1(id: LineRef, x: number): void设置起点 X;取值方式沿用创建时的 xloc。
@summary 设置起点 X
line.set_y1
line.set_y1(id: LineRef, y: number): void设置起点价格。
@summary 设置起点价格
line.set_x2
line.set_x2(id: LineRef, x: number): void设置终点 X;取值方式沿用创建时的 xloc。
@summary 设置终点 X
line.set_y2
line.set_y2(id: LineRef, y: number): void设置终点价格。
@summary 设置终点价格
line.set_color
line.set_color(id: LineRef, color: Color | (string & {})): void设置线段颜色,支持 CSS 颜色值;常用色可用 Color 枚举。
@summary 设置颜色
line.set_style
line.set_style(id: LineRef, style: LineStyle): void设置线型,包括实线、虚线和箭头。
@summary 设置线型
line.set_width
line.set_width(id: LineRef, width: number): void设置线宽,正整数逻辑像素。
@summary 设置线宽
line.set_extend
line.set_extend(id: LineRef, extend: LineExtend): void设置延伸方向;left 延伸至起点之外,right 延伸至终点之外。
@summary 设置延伸
line.get_x1
line.get_x1(id: LineRef): number读取起点 X;线段已删除返回 NaN。
@summary 起点 X
line.get_y1
line.get_y1(id: LineRef): number读取起点价格;线段已删除返回 NaN。
@summary 起点价格
line.get_x2
line.get_x2(id: LineRef): number读取终点 X;线段已删除返回 NaN。
@summary 终点 X
line.get_y2
line.get_y2(id: LineRef): number读取终点价格;线段已删除返回 NaN。
@summary 终点价格
line.get_color
line.get_color(id: LineRef): string | null读取颜色;线段已删除返回 null。
@summary 颜色
line.get_style
line.get_style(id: LineRef): LineStyle | null读取线型;线段已删除返回 null。
@summary 线型
line.get_width
line.get_width(id: LineRef): number读取线宽;线段已删除返回 NaN。
@summary 线宽
line.get_extend
line.get_extend(id: LineRef): LineExtend | null读取延伸方向;线段已删除返回 null。
@summary 延伸方向
line.get_price
line.get_price(id: LineRef, x: number): number按线段所在直线求 x 处的价格,与 extend 无关;只支持 xloc.bar_index,垂直线或已删除返回 NaN。
@summary 求价格
line.copy
line.copy(id: LineRef): LineRef | null复制为新线段并返回其引用,副本独立于原线段。
@summary 复制线段
line.delete
line.delete(id: LineRef | null): void删除线段;传入 null 或已删除对象无操作。
@summary 删除线段
chart
chart: { readonly point: { "new"(time: number, index: number, price: number): ChartPoint; now(price: number): ChartPoint; from_index(index: number, price: number): ChartPoint; from_time(time: number, price: number): ChartPoint; copy(point: ChartPoint): ChartPoint; }; }chart.point 坐标工厂;line.new 会复制坐标,不保留 point 对象引用。
chart.point
chart.point: { "new"(time: number, index: number, price: number): ChartPoint; now(price: number): ChartPoint; from_index(index: number, price: number): ChartPoint; from_time(time: number, price: number): ChartPoint; copy(point: ChartPoint): ChartPoint; }chart.point.new
chart.point.new(time: number, index: number, price: number): ChartPoint用时间戳、bar 索引和价格构造 point;xloc 决定 line.new 读取哪个字段。
chart.point.now
chart.point.now(price: number): ChartPoint当前 K 线的 point,索引取 bar_index。
chart.point.from_index
chart.point.from_index(index: number, price: number): ChartPoint只带 bar 索引的 point,用于 xloc.bar_index。
chart.point.from_time
chart.point.from_time(time: number, price: number): ChartPoint只带毫秒时间戳的 point,用于 xloc.bar_time。
chart.point.copy
chart.point.copy(point: ChartPoint): ChartPoint复制 point,得到独立值对象。
ta
ta: TechnicalAnalysisLibrary内建技术分析库 序列结果用 [0] 取当前值、[1] 取上一根值,例如 ta.sma(close, 20)[0]。
ta.rising
ta.rising(source: Series, length: number): boolean当前值严格高于前 length 根中的所有有效值,不要求逐根上涨。
@summary 上涨判断
@param source 数据序列,如 close。
@param length 回看根数,正整数,不包含当前根。
@returns 满足时为 true;当前值为 NaN 或没有有效历史值时为 false,历史 NaN 忽略。
ta.falling
ta.falling(source: Series, length: number): boolean当前值严格低于前 length 根中的所有有效值,不要求逐根下跌。
@summary 下跌判断
@param source 数据序列,如 close。
@param length 回看根数,正整数,不包含当前根。
@returns 满足时为 true;当前值为 NaN 或没有有效历史值时为 false,历史 NaN 忽略。
ta.change
ta.change(source: Series, length?: number): Series当前值减去 length 根之前的值。
@summary 数值变化
@param source 数据序列,如 volume。
@param length 回看根数,正整数,缺省为 1。
@returns 差值序列;历史不足或任一端为 NaN 时为 NaN。
ta.sma
ta.sma(source: Series, length: number): Series简单移动平均(SMA)。
@summary 简单移动平均
@param source 数据序列,如 close。
@param length 周期,正整数。
@returns 均线序列;[0] 取当前值,完整窗口之前为 NaN。
ta.sum
ta.sum(source: Series, length: number): Series窗口求和(SUM)。
@summary 窗口求和
@param source 数据序列,如 volume。
@param length 窗口长度,正整数。
@returns 求和序列;[0] 取当前窗口结果,完整窗口之前为 NaN。
ta.maxsum
ta.maxsum(source: Series, length: number): readonly [Series, Series, Series]最近 length 根内累计值最大的连续区间(最大子段和,Kadane)。
@summary 最大子段和
@param source 有符号数据序列,如对数收益、价格差分或带符号成交量。
@param length 窗口长度,正整数,包含当前根。
@returns [子段和, 起点偏移, 终点偏移];偏移为相对当前根的负值(与 highestbars 一致), 完整窗口之前或窗口内含 NaN 时三者均为 NaN。
ta.highest
ta.highest(source: Series, length: number): Series最近 length 根 K 线的最高值,包含当前 K 线。
@summary 窗口最高值
@param source 数据序列,如 high。
@param length 窗口长度,正整数。
@returns 最高值序列;[0] 取当前窗口的结果。
ta.lowest
ta.lowest(source: Series, length: number): Series最近 length 根 K 线的最低值,包含当前 K 线。
@summary 窗口最低值
@param source 数据序列,如 low。
@param length 窗口长度,正整数。
@returns 最低值序列;[0] 取当前窗口的结果。
ta.pivothigh
ta.pivothigh(source: Series, leftbars: number, rightbars: number): Series确认后的摆动高点;结果出现在右侧窗口完成的 bar,无摆点为 NaN。
ta.pivotlow
ta.pivotlow(source: Series, leftbars: number, rightbars: number): Series确认后的摆动低点;并列极值取更靠右的 bar。
ta.highestbars
ta.highestbars(source: Series, length: number): Series最近 length 根 K 线最高值相对当前 K 线的偏移,负值或 0。
@summary 最高值偏移
@param source 数据序列,如 high。
@param length 窗口长度,正整数。
@returns 偏移序列;并列最高取更早一根,完整窗口之前为 NaN。
ta.lowestbars
ta.lowestbars(source: Series, length: number): Series最近 length 根 K 线最低值相对当前 K 线的偏移,负值或 0。
@summary 最低值偏移
@param source 数据序列,如 low。
@param length 窗口长度,正整数。
@returns 偏移序列;并列最低取更早一根,完整窗口之前为 NaN。
ta.rma
ta.rma(source: Series, length: number): SeriesWilder 平滑均线(RMA),alpha = 1 / length,以首个完整窗口 SMA 初始化。
@summary Wilder 平滑均线
@param source 数据序列,如 close。
@param length 周期,正整数。
@returns 均线序列;完整窗口之前为 NaN。
ta.swma
ta.swma(source: Series): Series对称加权均线,固定 4 根窗口,权重由旧到新为 1/6、2/6、2/6、1/6。
@summary 对称加权均线
@param source 数据序列,如 close。
@returns 均线序列;前 3 根为 NaN。
ta.alma
ta.alma(source: Series, length: number, offset?: number, sigma?: number, floor?: boolean): SeriesArnaud Legoux 均线(ALMA),高斯权重中心位于 offset × (length − 1)。
@summary Arnaud Legoux 均线
@param source 数据序列,如 close。
@param length 窗口长度,正整数。
@param offset 高斯中心在窗口中的相对位置,0–1,缺省 0.85。
@param sigma 高斯宽度,有限正数,缺省 6。
@param floor 为 true 时对中心取下整,缺省 false。
@returns 均线序列;完整窗口之前为 NaN。
ta.stddev
ta.stddev(source: Series, length: number): Series总体标准差(STDDEV),窗口内数值相对窗口均值的偏差,除以 length。
@summary 总体标准差
@param source 数据序列,如 close。
@param length 窗口长度,正整数。
@returns 标准差序列;[0] 取当前窗口结果,完整窗口之前为 NaN。
ta.ema
ta.ema(source: Series, length: number): Series指数移动平均(EMA),以首个完整窗口的 SMA 为初值。
@summary 指数移动平均
@param source 数据序列,如 close。
@param length 周期,正整数。
@returns 均线序列;[0] 取当前值。
ta.dema
ta.dema(source: Series, length: number): Series双重指数均线:2×EMA(source)−EMA(EMA(source))。
@summary 双重指数均线
@param source 数据序列。
@param length 正整数周期,各层 EMA 以完整窗口均值初始化。
@returns DEMA 序列,前 2×(length−1) 根为 NaN。
ta.tema
ta.tema(source: Series, length: number): Series三重指数均线:3×EMA1−3×EMA2+EMA3。
@summary 三重指数均线
@param source 数据序列。
@param length 正整数周期,各层 EMA 以完整窗口均值初始化。
@returns TEMA 序列,前 3×(length−1) 根为 NaN。
ta.t3
ta.t3(source: Series, length: number, volumeFactor?: number): SeriesTillson T3,以六层 EMA 及成交量因子系数组合平滑价格。
@summary Tillson T3 均线
@param source 数据序列。
@param length 正整数周期。
@param volumeFactor 平滑因子,有限数值 0–1,缺省 0.7,不读取成交量。
@returns T3 序列,前 6×(length−1) 根为 NaN;周期 1 时等于输入。
ta.trima
ta.trima(source: Series, length: number): Series三角均线:SMA(SMA(source, ceil(length/2)), floor(length/2)+1)。
@summary 三角移动平均
@param source 数据序列。
@param length 正整数周期。
@returns TRIMA 序列,前 length−1 根为 NaN。
ta.macd
ta.macd(source: Series, fastLength: number, slowLength: number, signalLength: number): readonly [Series, Series, Series]MACD,快慢 EMA 与信号 EMA 均以首个有效值初始化,从该位置逐根输出。
@summary 指数平滑异同平均线
@param source 价格序列,如 close。
@param fastLength 快周期,正整数。
@param slowLength 慢周期,正整数。
@param signalLength 信号周期,正整数。
@returns [DIF, DEA, DIF-DEA] 三个序列;柱体不翻倍,NaN 处留空,后续有效值重新初始化。
ta.wma
ta.wma(source: Series, length: number): Series加权移动平均(WMA),越新的值权重越大。
@summary 加权移动平均
@param source 数据序列,如 close。
@param length 周期,正整数。
@returns 均线序列;[0] 取当前值。
ta.hma
ta.hma(source: Series, length: number): SeriesHull 移动平均,组合 WMA(2×WMA(source, floor(length/2))−WMA(source, length), round(sqrt(length)))。
@summary Hull 移动平均
@param source 数据序列。
@param length 正整数周期,派生窗口最小为 1。
@returns 均线序列,完整组合窗口之前为 NaN。
ta.linreg
ta.linreg(source: Series, length: number, offset?: number): Series线性回归曲线:对窗口做最小二乘拟合,返回相对当前根向前 offset 根的拟合值。
@summary 线性回归
@param source 数据序列,如 close。
@param length 窗口长度,正整数。
@param offset 向前偏移的根数,整数,缺省 0(当前根)。
@returns 回归值序列;完整窗口之前为 NaN。
ta.cci
ta.cci(source: Series, length: number): Series顺势指标:(source−SMA)/(0.015×平均绝对偏差)。
@summary 顺势指标
@param source 数据序列,通常为 (high+low+close)/3。
@param length 正整数周期。
@returns CCI 序列;窗口不足为 NaN,平均绝对偏差为零时为 0。
ta.vwma
ta.vwma(source: Series, volume: Series, length: number): Series成交量加权移动平均(VWMA),按 Σ(价格×成交量)/Σ(成交量) 计算。
@summary 成交量加权移动平均
@param source 价格序列,如 close。
@param volume 成交量序列。
@param length 周期,正整数。
@returns 均线序列;[0] 取当前值。
ta.rsi
ta.rsi(source: Series, length: number): Series相对强弱指数(RSI),使用 Wilder 平滑;窗口内无下跌(含平盘)为 100。
@summary 相对强弱指数
@param source 数据序列,如 close。
@param length 周期,正整数。
@returns RSI 序列,范围 0–100;[0] 取当前值,完整窗口之前为 NaN。
ta.stoch
ta.stoch(source: Series, high: Series, low: Series, length: number): Series随机指标:100 × (source − 窗口最低) / (窗口最高 − 窗口最低)。
@summary 随机指标
@param source 数据序列,如 close。
@param high 最高价序列,如 high。
@param low 最低价序列,如 low。
@param length 窗口长度,正整数。
@returns 随机指标序列,范围 0–100;完整窗口之前为 NaN,零幅窗口输出 50。
ta.atr
ta.atr(length: number): Series平均真实波幅(ATR),首个完整窗口取真实波幅均值,之后使用 Wilder 平滑。
@summary 平均真实波幅
@param length 周期,正整数。
@returns ATR 序列;第一根真实波幅为 high-low,完整窗口之前为 NaN。
ta.supertrend
ta.supertrend(multiplier: number, atrPeriod: number): readonly [Series, Series]Supertrend,保留原生指标的上涨初始方向与 ATR 通道递推规则。
@summary 超级趋势
@param multiplier ATR 倍数,有限正数。
@param atrPeriod ATR 周期,正整数。
@returns [趋势线序列, 方向序列];-1 为上涨、1 为下跌,预热期间两者均为 NaN。
ta.mom
ta.mom(source: Series, length?: number): Series动量(MOM),当前值减去 length 根之前的值。
@summary 动量
@param source 数据序列,如 close。
@param length 回看根数,正整数,缺省为 1。
@returns 差值序列,按数值轴绘制;历史不足时为 NaN。
ta.roc
ta.roc(source: Series, length?: number): Series当前值相对 length 根之前的百分比变化(ROC)。
@summary 变化率
@param source 数据序列,如 close。
@param length 回看根数,正整数,缺省为 1。
@returns 百分比变化序列;历史不足或基准为 0 时为 NaN。
ta.cmo
ta.cmo(source: Series, length: number): SeriesChande 动量振荡器:100 × (涨幅和 − 跌幅和) / (涨幅和 + 跌幅和),窗口含 length 个差分。
@summary 钱德动量振荡器
@param source 数据序列,如 close。
@param length 差分窗口,正整数。
@returns CMO 序列,范围 -100–100;完整窗口之前为 NaN,平盘(分母为零)为 0。
ta.crossover
ta.crossover(left: Series, right: Series): boolean判断当前 K 线是否发生上穿:left 当前大于 right,上一根小于或等于 right。
@summary 上穿
@param left 穿越方序列。
@param right 被穿越方序列。
@returns 发生上穿时为 true。
ta.crossunder
ta.crossunder(left: Series, right: Series): boolean判断当前 K 线是否发生下穿:left 当前小于 right,上一根大于或等于 right。
@summary 下穿
@param left 穿越方序列。
@param right 被穿越方序列。
@returns 发生下穿时为 true。
Position
Position: typeof PositionEnum@summary 渲染位置
指标渲染位置,由宿主注入 VM。
| 取值 | 含义 |
|---|---|
Position.Main | 叠加到主图,与 K 线共用主图价格轴 |
Position.Sub | 独立副图 |
Position.Main
Position.Main = "main"叠加到主图。
@summary 主图
Position.Sub
Position.Sub = "sub"独立副图。
@summary 副图
input
input: ScriptInput输入参数:int / float 支持范围和步长,bool 显示开关,string 支持下拉选项。
input.int
input.int(value: number, options?: NumberInputOptions): number整数输入;min、max 和 step 必须为整数。
@summary 整数
input.float
input.float(value: number, options?: NumberInputOptions): number浮点数输入,支持数值范围与步长。
@summary 浮点数
input.bool
input.bool(value: boolean, options?: InputOptions): boolean布尔输入,在参数面板中显示开关。
@summary 开关
input.string
input.string(value: string, options?: StringInputOptions): string字符串输入;提供 options 时显示下拉选项。
@summary 字符串
input.timeframe
input.timeframe(value: Timeframe, options?: TimeframeInputOptions): Timeframe目标周期输入;缺省列出全部受支持周期,返回值可直接传给 request.security。
@summary 目标周期
defineIndicator
defineIndicator(definition: ScriptIndicatorDeclaration): void定义一个指标。 顶层代码只执行一次,顶层变量跨 bar 保留(等价 Pine 的 var);逐根计算写在 onBar 内。
derive
derive(key: string, compute: (self: Series, offset: number) => number): Series惰性派生序列;读取时按绝对 bar 缓存,不主动填充历史。 key 必须稳定且区分输入与参数;同 key 复用首次注册的回调。 回调用 offset 读取输入历史,用 self[offset + 1] 读取自身上一根;历史越界返回 NaN。 不要捕获当前 bar 的数值快照,应捕获 Series 并按 offset 取值。
plot
plot: ScriptPlot当前 K 线的绘图方法;仅在 onBar 中调用,name 必填,null 主动留空。
| 方法 | 图形 | value 含义 |
|---|---|---|
plot.Line | 普通折线 | 跨空值连接前后有效点 |
plot.LineBR | 断线折线 | 空值处断开 |
plot.StepLine | 阶梯线 | 在相邻有效点的水平中点跳变,跨空值连接 |
plot.StepLineBR | 断线阶梯线 | 空值处断开 |
plot.Histogram | 柱状图 | 柱状图数值 |
plot.Point | 散点 | 散点数值 |
plot.Shape | 形状标记 | 数值或布尔条件;false 留空,absolute 定位时数值为价格 |
plot.Char | 字符标记 | 数值或布尔条件;false 留空,absolute 定位时数值为价格 |
plot.Arrow | 箭头 | 正负决定方向,绝对值决定长度 |
plot.Line
plot.Line(value: number | null, name: string, options?: PlotStyleOptions<"line">): PlotRef输出普通折线点,跨空值连接前后有效点,对应 Pine plot.style_line。
@summary 折线
plot.LineBR
plot.LineBR(value: number | null, name: string, options?: PlotStyleOptions<"linebr">): PlotRef输出断线折线点,空值处断开,对应 Pine plot.style_linebr。
@summary 断线折线
plot.StepLine
plot.StepLine(value: number | null, name: string, options?: PlotStyleOptions<"stepline">): PlotRef输出阶梯线点,在相邻有效点的水平中点跳变,跨空值连接,对应 Pine plot.style_stepline。
@summary 阶梯线
plot.StepLineBR
plot.StepLineBR(value: number | null, name: string, options?: PlotStyleOptions<"steplinebr">): PlotRef输出断线阶梯线点,空值处断开,对应 Pine plot.style_steplinebr。
@summary 断线阶梯线
plot.Histogram
plot.Histogram(value: number | null, name: string, options?: PlotStyleOptions<"histogram">): PlotRef固定像素柱宽;size 接受正数像素或 ShapeSize 枚举,默认 1px。
@summary 柱状图(定宽)
plot.Columns
plot.Columns(value: number | null, name: string, options?: PlotStyleOptions<"columns">): PlotRef输出自动柱宽的柱状图,随 K 线间距缩放,不支持 size。
@summary 柱形图(跟随缩放)
plot.Point
plot.Point(value: number | null, name: string, options?: PlotStyleOptions<"points">): PlotRef输出散点。
@summary 散点
plot.Shape
plot.Shape(value: number | boolean | null, name: string, options?: PlotStyleOptions<"shape">): PlotRef输出形状标记;false 留空,absolute 定位时数值为价格。
@summary 形状标记
plot.Char
plot.Char(value: number | boolean | null, name: string, options?: PlotStyleOptions<"char">): PlotRef输出字符标记;false 留空,absolute 定位时数值为价格。
@summary 字符标记
plot.Arrow
plot.Arrow(value: number | null, name: string, options?: PlotStyleOptions<"arrow">): PlotRef输出数值箭头,正负决定方向,绝对值决定长度。
@summary 箭头
plot.Candle
plot.Candle(open: number | null, high: number | null, low: number | null, close: number | null, name: string, options?: CandlePlotOptions): void输出蜡烛;任一价格缺失时留空,实体、影线和边框可独立着色。
@summary 蜡烛图
plot.Bar
plot.Bar(open: number | null, high: number | null, low: number | null, close: number | null, name: string, options?: BarPlotOptions): void输出美国线;左侧短横线为开盘,右侧短横线为收盘。
@summary 美国线(OHLC)
fill
fill(from: PlotRef, to: PlotRef, color: Color | (string & {}) | null, title?: string, options?: ScriptFillOptions): void
fill(from: HLineRef, to: HLineRef, color: Color | (string & {}) | null, title?: string, options?: ScriptFillOptions): void声明两个 Plot 之间的填充区域;两个句柄由 plot.* 返回,仅在 onBar 中调用。 每根 bar 保存调用处求出的颜色;null 表示该 bar 不填充。
| 参数 | 含义 |
|---|---|
from / to | 填充的两个边界 Plot |
color | 当前 bar 的颜色,支持 CSS 颜色值,常用色可用 Color 枚举,透明度由颜色携带 |
title | 填充标识;不填则按 from/to 生成 |
| 声明两条水平参考线之间的填充区域;整幅宽度、单色,不随 bar 变化。 | |
| 只能在文件顶层调用,两个句柄都必须来自 hline。 |
fill
fill(from: PlotRef, to: PlotRef, color: Color | (string & {}) | null, title?: string, options?: ScriptFillOptions): void
fill(from: HLineRef, to: HLineRef, color: Color | (string & {}) | null, title?: string, options?: ScriptFillOptions): void声明两个 Plot 之间的填充区域;两个句柄由 plot.* 返回,仅在 onBar 中调用。 每根 bar 保存调用处求出的颜色;null 表示该 bar 不填充。
| 参数 | 含义 |
|---|---|
from / to | 填充的两个边界 Plot |
color | 当前 bar 的颜色,支持 CSS 颜色值,常用色可用 Color 枚举,透明度由颜色携带 |
title | 填充标识;不填则按 from/to 生成 |
| 声明两条水平参考线之间的填充区域;整幅宽度、单色,不随 bar 变化。 | |
| 只能在文件顶层调用,两个句柄都必须来自 hline。 |
hline
hline(price: number, options?: HLineOptions): HLineRef图表级水平参考线:固定价格、贯穿整幅宽度,不占用逐 bar 数据列。
只能在文件顶层声明;颜色、线型与线宽在整轮运行内固定,不随 bar 变化。
hline(70, { color: Color.Gray, linestyle: HLineStyle.style_dashed })@param price 水平线价格
@param options 标题、颜色、线型与线宽
@returns 句柄;可交给 fill 与另一条水平线围出带状区域
defineLibrary
defineLibrary<T extends object>(name: string, members: T): Readonly<T>注册一个库,其成员同时绑定到同名全局对象。
importLibrary
importLibrary<K extends keyof LibraryModules>(name: K): LibraryModules[K]读取已注册的库,内置名称由统一库类型目录提供。
request
request: ScriptRequest获取指定品种周期的数据;syminfo.tickerid 是当前图表品种。
request.security
request.security<T extends RequestValue | Series | readonly (RequestValue | Series)[]>(symbol: string, timeframe: Timeframe, expression: () => T, options?: SecurityOptions): RequestResult<T>在指定品种、周期的上下文中计算 expression,再将计算结果对齐到当前图表品种的 K 线时间槽位上。
| 参数 | 类型 | 含义 |
|---|---|---|
symbol | string | 目标品种 |
timeframe | Timeframe | 目标周期 |
expression | () => T | 在目标品种、周期的上下文中执行的计算回调,可访问目标的 OHLC 数据;结果由 security 对齐到当前图表的时间槽位 |
options | SecurityOptions | 来源、预热根数、缺口策略 |
| 返回值 |
|---|
expression 的计算结果,对齐到当前图表品种的 K 线时间槽位;缺口按 options.gaps 策略处理 |
用法:
const [o, h, l, c] = request.security(syminfo.tickerid, Timeframe.Hour1, () => [open, high, low, close] as const)syminfo
syminfo: { readonly tickerid: string; }当前图表品种信息;tickerid 可直接传给 request.security。
syminfo.tickerid
syminfo.tickerid: string相关类型
- Series
- Series.0
- Series.1
- Series.at
- LineRef
- LineRef.id
- BoxRef
- BoxRef.id
- LabelRef
- LabelRef.id
- DrawingBoxApi
- BoxFactory
- ChartPoint
- ChartPoint.index
- ChartPoint.time
- ChartPoint.price
- LineXLoc
- LineExtend
- Color
- BoxBorderStyle
- DrawingText
- DrawingText.value
- DrawingText.align
- DrawingText.verticalAlign
- DrawingText.offsetY
- DrawingLabelApi
- LabelFactory
- ScriptParameters
- DrawingLineApi
- LineFactory
- LineStyle
- TechnicalAnalysisLibrary
- Position
- ScriptInput
- NumberInputOptions
- NumberInputOptions.min
- NumberInputOptions.max
- NumberInputOptions.step
- NumberInputOptions.title
- InputOptions
- StringInputOptions
- StringInputOptions.options
- Timeframe
- TimeframeInputOptions
- TimeframeInputOptions.options
- ScriptIndicatorDeclaration
- ScriptIndicatorDeclaration.onBar
- ScriptIndicatorDeclaration.name
- ScriptIndicatorDeclaration.format
- ScriptIndicatorDeclaration.title
- ScriptIndicatorDeclaration.info
- ScriptIndicatorDeclaration.position
- ScriptIndicatorDeclaration.max_lines_count
- ScriptIndicatorDeclaration.max_boxes_count
- ScriptIndicatorDeclaration.max_labels_count
- ScriptPlot
- PlotStyleOptions
- PlotStyleOptions.label
- PlotStyleOptions.color
- PlotStyleOptions.format
- PlotStyleOptions.offset
- PlotStyleOptions.visible
- PlotRef
- PlotRef.name
- CandlePlotOptions
- CandlePlotOptions.wickColor
- CandlePlotOptions.borderColor
- CandlePlotOptions.label
- CandlePlotOptions.visible
- CandlePlotOptions.offset
- CandlePlotOptions.showLast
- CandlePlotOptions.color
- CandlePlotOptions.format
- BarPlotOptions
- ScriptFillOptions
- ScriptFillOptions.visible
- HLineRef
- HLineRef.hline
- HLineOptions
- HLineOptions.title
- HLineOptions.color
- HLineOptions.linestyle
- HLineOptions.linewidth
- LibraryModules
- LibraryModules.ta
- LibraryModules
- ScriptRequest
- RequestValue
- SecurityOptions
- SecurityOptions.source
- SecurityOptions.calcBarsCount
- SecurityOptions.gaps
- RequestResult
- BoxOptions
- BoxOptions.left
- BoxOptions.top
- BoxOptions.right
- BoxOptions.bottom
- BoxOptions.borderColor
- BoxOptions.borderWidth
- BoxOptions.borderStyle
- BoxOptions.extend
- BoxOptions.xloc
- BoxOptions.backgroundColor
- BoxOptions.text
- BoxOptions.textSize
- BoxOptions.textColor
- LabelOptions
- LabelOptions.x
- LabelOptions.y
- LabelOptions.text
- LabelOptions.xloc
- LabelOptions.color
- LabelOptions.textColor
- LabelOptions.size
- LabelOptions.align
- LabelOptions.offsetY
- LineOptions
- LineOptions.x1
- LineOptions.y1
- LineOptions.x2
- LineOptions.y2
- LineOptions.xloc
- LineOptions.extend
- LineOptions.color
- LineOptions.style
- LineOptions.width
- QuickJSScriptDefinition
- QuickJSScriptDefinition.name
- QuickJSScriptDefinition.title
- QuickJSScriptDefinition.info
- QuickJSScriptDefinition.position
- QuickJSScriptDefinition.format
- QuickJSScriptDefinition.max_lines_count
- QuickJSScriptDefinition.max_boxes_count
- QuickJSScriptDefinition.max_labels_count
- QuickJSScriptDefinition.inputs
- PlotDeclaration
- PlotDeclaration.kind
- PlotDeclaration.name
- PlotDeclaration.label
- PlotDeclaration.color
- PlotDeclaration.format
- PlotDeclaration.offset
- PlotDeclaration.visible
- OhlcPlotOptions
- HLineStyle
- DataSource
- Format
- InputSchema
- ScriptParamValue
- ScalarPlotDeclaration
- ScalarPlotDeclaration.kind
- ScalarPlotDeclaration.name
- ScalarPlotDeclaration.label
- ScalarPlotDeclaration.color
- ScalarPlotDeclaration.format
- ScalarPlotDeclaration.textColor
- ScalarPlotDeclaration.offset
- ScalarPlotDeclaration.visible
- ScalarPlotDeclaration.size
- OhlcPlotDeclaration
- OhlcPlotDeclaration.name
- OhlcPlotDeclaration.kind
- InputDef
- InputDef.default
- InputDef.options
- InputDef.min
- InputDef.max
- InputDef.step
- LinePlotDeclaration
- LinePlotDeclaration.kind
- LinePlotDeclaration.dash
- LinePlotDeclaration.name
- LinePlotDeclaration.label
- LinePlotDeclaration.color
- LinePlotDeclaration.format
- LinePlotDeclaration.textColor
- LinePlotDeclaration.offset
- LinePlotDeclaration.visible
- LinePlotDeclaration.size
- LineBRPlotDeclaration
- LineBRPlotDeclaration.kind
- LineBRPlotDeclaration.dash
- LineBRPlotDeclaration.name
- LineBRPlotDeclaration.label
- LineBRPlotDeclaration.color
- LineBRPlotDeclaration.format
- LineBRPlotDeclaration.textColor
- LineBRPlotDeclaration.offset
- LineBRPlotDeclaration.visible
- LineBRPlotDeclaration.size
- StepLinePlotDeclaration
- StepLinePlotDeclaration.kind
- StepLineBRPlotDeclaration
- StepLineBRPlotDeclaration.kind
- HistogramPlotDeclaration
- HistogramPlotDeclaration.kind
- HistogramPlotDeclaration.baseline
- HistogramPlotDeclaration.size
- HistogramPlotDeclaration.name
- HistogramPlotDeclaration.label
- HistogramPlotDeclaration.color
- HistogramPlotDeclaration.format
- HistogramPlotDeclaration.textColor
- HistogramPlotDeclaration.offset
- HistogramPlotDeclaration.visible
- ColumnsPlotDeclaration
- ColumnsPlotDeclaration.kind
- ColumnsPlotDeclaration.baseline
- ColumnsPlotDeclaration.size
- PointsPlotDeclaration
- PointsPlotDeclaration.kind
- ShapePlotDeclaration
- ShapePlotDeclaration.kind
- ShapePlotDeclaration.style
- ShapePlotDeclaration.location
- ShapePlotDeclaration.text
- CharPlotDeclaration
- CharPlotDeclaration.kind
- CharPlotDeclaration.char
- ArrowPlotDeclaration
- ArrowPlotDeclaration.kind
- ArrowPlotDeclaration.colorUp
- ArrowPlotDeclaration.colorDown
- CandlePlotDeclaration
- CandlePlotDeclaration.name
- CandlePlotDeclaration.kind
- BarPlotDeclaration
- BarPlotDeclaration.name
- BarPlotDeclaration.kind
- PlotDeclarationBase
- ShapeSize
- ShapeOptions
- ShapeOptions.textColor
- CharOptions
- ArrowOptions
- PlotStyleBase
- MarkerOptions
- ShapeStyle
- ShapeLocation
Series
export interface Series {
readonly 0: number;
readonly 1: number;
at(offset: number): number;
readonly [offset: number]: number;
}行情与金融计算共用的只读序列契约。
Series.0
Series.0: numberSeries.1
Series.1: numberSeries.at
Series.at(offset: number): number动态偏移访问,严格 TypeScript 模式下也始终返回 number。
LineRef
export interface LineRef {
readonly id: string;
}不暴露可修改对象本身的引用,只在所属运行内有效。
LineRef.id
LineRef.id: string对象标识;同一对象在 line.all 与创建结果中是同一个引用。
BoxRef
export interface BoxRef {
readonly id: string;
}Box 对象引用,仅在所属运行中有效。
BoxRef.id
BoxRef.id: stringLabelRef
export interface LabelRef {
readonly id: string;
}Label 对象引用,仅在所属运行中有效。
LabelRef.id
LabelRef.id: stringDrawingBoxApi
export interface DrawingBoxApi {
readonly new: BoxFactory;
readonly all: readonly BoxRef[];
set_left(id: BoxRef, left: number): void;
set_top(id: BoxRef, top: number): void;
set_right(id: BoxRef, right: number): void;
set_bottom(id: BoxRef, bottom: number): void;
set_lefttop(id: BoxRef, left: number, top: number): void;
set_rightbottom(id: BoxRef, right: number, bottom: number): void;
set_top_left_point(id: BoxRef, point: ChartPoint): void;
set_bottom_right_point(id: BoxRef, point: ChartPoint): void;
set_xloc(id: BoxRef, left: number, right: number, xloc: LineXLoc): void;
set_extend(id: BoxRef, extend: LineExtend): void;
set_bgcolor(id: BoxRef, color: Color | (string & {})): void;
set_border_color(id: BoxRef, color: Color | (string & {})): void;
set_border_width(id: BoxRef, width: number): void;
set_border_style(id: BoxRef, style: BoxBorderStyle): void;
set_text(id: BoxRef, text: string): void;
set_text_color(id: BoxRef, color: Color | (string & {})): void;
set_text_size(id: BoxRef, size: number): void;
set_text_halign(id: BoxRef, align: DrawingText['align']): void;
set_text_valign(id: BoxRef, align: DrawingText['verticalAlign']): void;
get_left(id: BoxRef): number;
get_top(id: BoxRef): number;
get_right(id: BoxRef): number;
get_bottom(id: BoxRef): number;
copy(id: BoxRef): BoxRef | null;
delete(id: BoxRef | null): void;
}跨 bar 保留的矩形对象;复用手绘 rectangle 模型。
BoxFactory
export interface BoxFactory {
(left: number, top: number, right: number, bottom: number, border_color?: Color | (string & {}), border_width?: number, border_style?: BoxBorderStyle, extend?: LineExtend, xloc?: LineXLoc, bgcolor?: Color | (string & {}), text?: string, text_size?: number, text_color?: Color | (string & {})): BoxRef;
(top_left: ChartPoint, bottom_right: ChartPoint, border_color?: Color | (string & {}), border_width?: number, border_style?: BoxBorderStyle, extend?: LineExtend, xloc?: LineXLoc, bgcolor?: Color | (string & {}), text?: string, text_size?: number, text_color?: Color | (string & {})): BoxRef;
(options: BoxOptions): BoxRef;
}Pine 风格 Box 创建重载;可选参数顺序与 Pine 相同。
ChartPoint
export interface ChartPoint {
readonly index?: number;
readonly time?: number;
readonly price: number;
}chart.point 值对象;绘制线段时复制坐标。
ChartPoint.index
ChartPoint.index?: number | undefinedbar 索引;xloc.bar_index 时 line 读取该字段。
ChartPoint.time
ChartPoint.time?: number | undefinedK 线时间戳(毫秒);xloc.bar_time 时 line 读取该字段。
ChartPoint.price
ChartPoint.price: number价格。
LineXLoc
export type LineXLoc = (typeof xloc)[keyof typeof xloc];LineExtend
export type LineExtend = (typeof extend)[keyof typeof extend];Color
export type Color = (typeof Color)[keyof typeof Color];常用色的字面量联合。
颜色参数的类型为 Color | (string & {}):既接受常用色,也接受任意 CSS 颜色值
(包括 Color.Teal + '80' 这类带 alpha 的拼接结果)。
@summary 常用色
常用色:主题色别名 + 白 / 黑两个绝对色。
脚本里用 Color.Red 即可;别名与 Theme.colors.scriptPalette 的键一一对应。
BoxBorderStyle
export type BoxBorderStyle = 'solid' | 'dashed' | 'dotted';Box 的边框不包含箭头。
DrawingText
export interface DrawingText {
value: string;
align: 'left' | 'center' | 'right';
verticalAlign: 'top' | 'middle' | 'bottom';
offsetY?: number;
}对象文字内容与排版;颜色和字号属于图元样式,统一放在 DrawingStyle.textColor / fontSize。
文字是绘制结果的一部分,不再保留自己的颜色与字号,避免同一属性存两份、 让主题色解析只能覆盖其中一份。
DrawingText.value
DrawingText.value: stringDrawingText.align
DrawingText.align: "left" | "right" | "center"DrawingText.verticalAlign
DrawingText.verticalAlign: "top" | "middle" | "bottom"DrawingText.offsetY
DrawingText.offsetY?: number | undefined垂直像素偏移;正数向上,0 表示贴合锚点。点标签与 Box 文字消费。
DrawingLabelApi
export interface DrawingLabelApi {
readonly style_none: 'none';
readonly new: LabelFactory;
readonly all: readonly LabelRef[];
set_x(id: LabelRef, x: number): void;
set_y(id: LabelRef, y: number): void;
set_xy(id: LabelRef, x: number, y: number): void;
set_text(id: LabelRef, text: string): void;
set_textcolor(id: LabelRef, color: Color | (string & {})): void;
set_size(id: LabelRef, size: number): void;
set_textalign(id: LabelRef, align: DrawingText['align']): void;
set_yoffset(id: LabelRef, offsetY: number): void;
get_x(id: LabelRef): number;
get_y(id: LabelRef): number;
get_text(id: LabelRef): string | null;
get_yoffset(id: LabelRef): number;
copy(id: LabelRef): LabelRef | null;
delete(id: LabelRef | null): void;
}第一版 Label 使用价格锚点和纯文字样式,与 Pine style_none 对应。
LabelFactory
export interface LabelFactory {
(x: number, y: number, text?: string, xloc?: LineXLoc, yloc?: 'price', color?: Color | (string & {}), style?: 'none', textcolor?: Color | (string & {}), size?: number, textalign?: DrawingText['align'], offsetY?: number): LabelRef;
(options: LabelOptions): LabelRef;
}Pine 风格 Label 创建重载:位置参数与选项对象等价。
ScriptParameters
interface ScriptParameters {
}编辑器从当前 inputs 推导并合并具体参数。
DrawingLineApi
export interface DrawingLineApi {
readonly style_solid: typeof LineStyle.style_solid;
readonly style_dashed: typeof LineStyle.style_dashed;
readonly style_dotted: typeof LineStyle.style_dotted;
readonly style_arrow_left: typeof LineStyle.style_arrow_left;
readonly style_arrow_right: typeof LineStyle.style_arrow_right;
readonly style_arrow_both: typeof LineStyle.style_arrow_both;
readonly new: LineFactory;
readonly all: readonly LineRef[];
set_xy1(id: LineRef, x: number, y: number): void;
set_xy2(id: LineRef, x: number, y: number): void;
set_x1(id: LineRef, x: number): void;
set_y1(id: LineRef, y: number): void;
set_x2(id: LineRef, x: number): void;
set_y2(id: LineRef, y: number): void;
set_color(id: LineRef, color: Color | (string & {})): void;
set_style(id: LineRef, style: LineStyle): void;
set_width(id: LineRef, width: number): void;
set_extend(id: LineRef, extend: LineExtend): void;
get_x1(id: LineRef): number;
get_y1(id: LineRef): number;
get_x2(id: LineRef): number;
get_y2(id: LineRef): number;
get_color(id: LineRef): string | null;
get_style(id: LineRef): LineStyle | null;
get_width(id: LineRef): number;
get_extend(id: LineRef): LineExtend | null;
get_price(id: LineRef, x: number): number;
copy(id: LineRef): LineRef | null;
delete(id: LineRef | null): void;
}脚本和原生调用方共用的完整 line API。
线段跨 bar 保留,新建和修改只能在 onBar 内调用;引用只在本次运行内有效, 重算后旧引用失效,需要继续操作时从 line.all 或新的结果重新获取。 线段删除或回收后,set_* 不生效,get_* 返回 NaN 或 null。
| 用法 | 含义 |
|---|---|
line.new(...) | 绘制线段,超出 max_lines_count 时回收最旧 |
line.set_* | 修改端点、颜色、线型、线宽或延伸 |
line.get_* | 读取对应属性;已删除返回 NaN 或 null |
line.get_price(id, x) | 按线段所在直线求价格,只支持 bar_index |
line.copy / line.delete | 复制为新线段 / 删除线段 |
LineFactory
export interface LineFactory {
(first_point: ChartPoint, second_point: ChartPoint, xloc?: LineXLoc, extend?: LineExtend, color?: Color | (string & {}), style?: LineStyle, width?: number): LineRef;
(x1: number, y1: number, x2: number, y2: number, xloc?: LineXLoc, extend?: LineExtend, color?: Color | (string & {}), style?: LineStyle, width?: number): LineRef;
(options: LineOptions): LineRef;
}line.new 的重载:用 chart.point 端点或直接给出起止点的 X / Y 绘制线段。
LineStyle
export type LineStyle = (typeof LineStyle)[keyof typeof LineStyle];线型:实线、虚线与箭头;手绘和 line API 共用。
TechnicalAnalysisLibrary
export type TechnicalAnalysisLibrary = {
rising(source: Series, length: number): boolean;
falling(source: Series, length: number): boolean;
change(source: Series, length?: number): Series;
sma(source: Series, length: number): Series;
sum(source: Series, length: number): Series;
maxsum(source: Series, length: number): readonly [
Series,
Series,
Series
];
highest(source: Series, length: number): Series;
lowest(source: Series, length: number): Series;
pivothigh(source: Series, leftbars: number, rightbars: number): Series;
pivotlow(source: Series, leftbars: number, rightbars: number): Series;
highestbars(source: Series, length: number): Series;
lowestbars(source: Series, length: number): Series;
rma(source: Series, length: number): Series;
swma(source: Series): Series;
alma(source: Series, length: number, offset?: number, sigma?: number, floor?: boolean): Series;
stddev(source: Series, length: number): Series;
ema(source: Series, length: number): Series;
dema(source: Series, length: number): Series;
tema(source: Series, length: number): Series;
t3(source: Series, length: number, volumeFactor?: number): Series;
trima(source: Series, length: number): Series;
macd(source: Series, fastLength: number, slowLength: number, signalLength: number): readonly [
Series,
Series,
Series
];
wma(source: Series, length: number): Series;
hma(source: Series, length: number): Series;
linreg(source: Series, length: number, offset?: number): Series;
cci(source: Series, length: number): Series;
vwma(source: Series, volume: Series, length: number): Series;
rsi(source: Series, length: number): Series;
stoch(source: Series, high: Series, low: Series, length: number): Series;
atr(length: number): Series;
supertrend(multiplier: number, atrPeriod: number): readonly [
Series,
Series
];
mom(source: Series, length?: number): Series;
roc(source: Series, length?: number): Series;
cmo(source: Series, length: number): Series;
crossover(left: Series, right: Series): boolean;
crossunder(left: Series, right: Series): boolean;
};技术分析库公开接口。
Position
export enum Position {
Main = 'main',
Sub = 'sub'
}@summary 渲染位置
指标渲染位置;脚本声明、编辑器与宿主共用同一组取值。
ScriptInput
export interface ScriptInput {
int(value: number, options?: NumberInputOptions): number;
float(value: number, options?: NumberInputOptions): number;
bool(value: boolean, options?: InputOptions): boolean;
string(value: string, options?: StringInputOptions): string;
timeframe(value: Timeframe, options?: TimeframeInputOptions): Timeframe;
}按输入类型声明默认值与对应选项,params 根据返回声明推导值类型。
NumberInputOptions
export interface NumberInputOptions extends InputOptions {
readonly min?: number;
readonly max?: number;
readonly step?: number;
}数值输入的范围与步长。
NumberInputOptions.min
NumberInputOptions.min?: number | undefinedNumberInputOptions.max
NumberInputOptions.max?: number | undefinedNumberInputOptions.step
NumberInputOptions.step?: number | undefinedNumberInputOptions.title
NumberInputOptions.title?: string | undefined参数面板中的显示名;不填则显示参数名。
InputOptions
export interface InputOptions {
readonly title?: string;
}输入参数的公共展示选项。
StringInputOptions
export interface StringInputOptions extends InputOptions {
readonly options?: readonly string[];
}字符串输入可通过 options 渲染下拉选择。
StringInputOptions.options
StringInputOptions.options?: readonly string[] | undefinedTimeframe
export type Timeframe = (typeof Timeframe)[keyof typeof Timeframe];@summary 目标周期
脚本 request.security 的目标周期,由宿主注入为 VM 全局枚举。
取值是周期短写法,只登记图表已支持的周期;需要新周期时先扩 KLinePeriod,
再在这里登记对应写法,宿主侧 requestPeriod 不接受未登记的值。
TimeframeInputOptions
export interface TimeframeInputOptions extends InputOptions {
readonly options?: readonly Timeframe[];
}周期输入的 options 只允许 Timeframe 中登记的周期。
TimeframeInputOptions.options
TimeframeInputOptions.options?: readonly Timeframe[] | undefinedScriptIndicatorDeclaration
export interface ScriptIndicatorDeclaration extends Omit<QuickJSScriptDefinition, 'inputs'> {
onBar(): void;
}完整脚本的声明与逐 bar 执行回调。
ScriptIndicatorDeclaration.onBar
ScriptIndicatorDeclaration.onBar(): void逐根 K 线调用一次
ScriptIndicatorDeclaration.name
ScriptIndicatorDeclaration.name: string稳定身份与选择器短名;注册身份由宿主维护。
ScriptIndicatorDeclaration.format
ScriptIndicatorDeclaration.format?: Format | undefined指标级数值格式;驱动副图轴与图例显示,缺省按价格。
ScriptIndicatorDeclaration.title
ScriptIndicatorDeclaration.title?: string | undefined指标选择器/图例显示的长名称;缺省用 name。
ScriptIndicatorDeclaration.info
ScriptIndicatorDeclaration.info?: string | undefined指标选择器里的说明文本;缺省不展示说明。
ScriptIndicatorDeclaration.position
ScriptIndicatorDeclaration.position: Position指标渲染位置。
| 取值 | 含义 |
|---|---|
Position.Main | 叠加到主图,与 K 线共用主图价格轴 |
Position.Sub | 独立副图 |
ScriptIndicatorDeclaration.max_lines_count
ScriptIndicatorDeclaration.max_lines_count?: number | undefined可保留的 line 对象数;默认 50,范围 1..2000。
ScriptIndicatorDeclaration.max_boxes_count
ScriptIndicatorDeclaration.max_boxes_count?: number | undefined可保留的 Box 数量;默认值与范围由公共 drawing 契约管理。
ScriptIndicatorDeclaration.max_labels_count
ScriptIndicatorDeclaration.max_labels_count?: number | undefined可保留的 Label 数量。
ScriptPlot
export interface ScriptPlot {
Line(value: number | null, name: string, options?: PlotStyleOptions<'line'>): PlotRef;
LineBR(value: number | null, name: string, options?: PlotStyleOptions<'linebr'>): PlotRef;
StepLine(value: number | null, name: string, options?: PlotStyleOptions<'stepline'>): PlotRef;
StepLineBR(value: number | null, name: string, options?: PlotStyleOptions<'steplinebr'>): PlotRef;
Histogram(value: number | null, name: string, options?: PlotStyleOptions<'histogram'>): PlotRef;
Columns(value: number | null, name: string, options?: PlotStyleOptions<'columns'>): PlotRef;
Point(value: number | null, name: string, options?: PlotStyleOptions<'points'>): PlotRef;
Shape(value: number | boolean | null, name: string, options?: PlotStyleOptions<'shape'>): PlotRef;
Char(value: number | boolean | null, name: string, options?: PlotStyleOptions<'char'>): PlotRef;
Arrow(value: number | null, name: string, options?: PlotStyleOptions<'arrow'>): PlotRef;
Candle(open: number | null, high: number | null, low: number | null, close: number | null, name: string, options?: CandlePlotOptions): void;
Bar(open: number | null, high: number | null, low: number | null, close: number | null, name: string, options?: BarPlotOptions): void;
}当前 K 线绘图入口;name 必填,null 留空;单值方法返回 PlotRef,OHLC 方法返回 void。
PlotStyleOptions
export type PlotStyleOptions<K extends PlotDeclaration['kind']> = Omit<Extract<PlotDeclaration, {
kind: K;
}>, 'kind' | 'name'>;从共享声明提取对应图形的样式选项,类型由方法名确定。
PlotStyleOptions.label
PlotStyleOptions.label?: (Extract<LinePlotDeclaration, { kind: K; }> | Extract<LineBRPlotDeclaration, { kind: K; }> | Extract<StepLinePlotDeclaration, { kind: K; }> | Extract<StepLineBRPlotDeclaration, { kind: K; }> | Extract<HistogramPlotDeclaration, { kind: K; }> | Extract<ColumnsPlotDeclaration, { kind: K; }> | Extract<PointsPlotDeclaration, { kind: K; }> | Extract<ShapePlotDeclaration, { kind: K; }> | Extract<CharPlotDeclaration, { kind: K; }> | Extract<ArrowPlotDeclaration, { kind: K; }> | Extract<CandlePlotDeclaration, { kind: K; }> | Extract<BarPlotDeclaration, { kind: K; }>)["label"] | undefined图例名称;不填则取 name。
PlotStyleOptions.color
PlotStyleOptions.color?: (Extract<LinePlotDeclaration, { kind: K; }> | Extract<LineBRPlotDeclaration, { kind: K; }> | Extract<StepLinePlotDeclaration, { kind: K; }> | Extract<StepLineBRPlotDeclaration, { kind: K; }> | Extract<HistogramPlotDeclaration, { kind: K; }> | Extract<ColumnsPlotDeclaration, { kind: K; }> | Extract<PointsPlotDeclaration, { kind: K; }> | Extract<ShapePlotDeclaration, { kind: K; }> | Extract<CharPlotDeclaration, { kind: K; }> | Extract<ArrowPlotDeclaration, { kind: K; }> | Extract<CandlePlotDeclaration, { kind: K; }> | Extract<BarPlotDeclaration, { kind: K; }>)["color"] | undefined图形颜色,支持 CSS 颜色值;常用色可用 Color 枚举,可为每根 K 线设置不同颜色。
实体颜色,支持 CSS 颜色值;常用色可用 Color 枚举,null 隐藏该部分。
PlotStyleOptions.format
PlotStyleOptions.format?: (Extract<LinePlotDeclaration, { kind: K; }> | Extract<LineBRPlotDeclaration, { kind: K; }> | Extract<StepLinePlotDeclaration, { kind: K; }> | Extract<StepLineBRPlotDeclaration, { kind: K; }> | Extract<HistogramPlotDeclaration, { kind: K; }> | Extract<ColumnsPlotDeclaration, { kind: K; }> | Extract<PointsPlotDeclaration, { kind: K; }> | Extract<ShapePlotDeclaration, { kind: K; }> | Extract<CharPlotDeclaration, { kind: K; }> | Extract<ArrowPlotDeclaration, { kind: K; }> | Extract<CandlePlotDeclaration, { kind: K; }> | Extract<BarPlotDeclaration, { kind: K; }>)["format"] | undefined数值格式档位;缺省继承指标级 format,用于图例数值显示。
PlotStyleOptions.offset
PlotStyleOptions.offset?: (Extract<LinePlotDeclaration, { kind: K; }> | Extract<LineBRPlotDeclaration, { kind: K; }> | Extract<StepLinePlotDeclaration, { kind: K; }> | Extract<StepLineBRPlotDeclaration, { kind: K; }> | Extract<HistogramPlotDeclaration, { kind: K; }> | Extract<ColumnsPlotDeclaration, { kind: K; }> | Extract<PointsPlotDeclaration, { kind: K; }> | Extract<ShapePlotDeclaration, { kind: K; }> | Extract<CharPlotDeclaration, { kind: K; }> | Extract<ArrowPlotDeclaration, { kind: K; }> | Extract<CandlePlotDeclaration, { kind: K; }> | Extract<BarPlotDeclaration, { kind: K; }>)["offset"] | undefined图形移动的 K 线根数;正值向右、负值向左,不填则不移动。
PlotStyleOptions.visible
PlotStyleOptions.visible?: (Extract<LinePlotDeclaration, { kind: K; }> | Extract<LineBRPlotDeclaration, { kind: K; }> | Extract<StepLinePlotDeclaration, { kind: K; }> | Extract<StepLineBRPlotDeclaration, { kind: K; }> | Extract<HistogramPlotDeclaration, { kind: K; }> | Extract<ColumnsPlotDeclaration, { kind: K; }> | Extract<PointsPlotDeclaration, { kind: K; }> | Extract<ShapePlotDeclaration, { kind: K; }> | Extract<CharPlotDeclaration, { kind: K; }> | Extract<ArrowPlotDeclaration, { kind: K; }> | Extract<CandlePlotDeclaration, { kind: K; }> | Extract<BarPlotDeclaration, { kind: K; }>)["visible"] | undefined是否显示图形;不填则显示。
PlotRef
export interface PlotRef {
readonly name: string;
}plot.* 返回的绘图句柄;fill 借它引用两个 Plot。
PlotRef.name
PlotRef.name: string句柄所属 Plot 的 name。
CandlePlotOptions
export interface CandlePlotOptions extends OhlcPlotOptions {
readonly wickColor?: Color | (string & {}) | null;
readonly borderColor?: Color | (string & {}) | null;
}蜡烛实体、影线和边框可独立着色。
CandlePlotOptions.wickColor
CandlePlotOptions.wickColor?: Color | (string & {}) | null | undefined影线颜色,支持 CSS 颜色值;常用色可用 Color 枚举,null 隐藏该部分。
CandlePlotOptions.borderColor
CandlePlotOptions.borderColor?: Color | (string & {}) | null | undefined边框颜色,支持 CSS 颜色值;常用色可用 Color 枚举,null 隐藏该部分。
CandlePlotOptions.label
CandlePlotOptions.label?: string | undefinedCandlePlotOptions.visible
CandlePlotOptions.visible?: boolean | undefinedCandlePlotOptions.offset
CandlePlotOptions.offset?: number | undefinedCandlePlotOptions.showLast
CandlePlotOptions.showLast?: number | undefinedCandlePlotOptions.color
CandlePlotOptions.color?: Color | (string & {}) | null | undefined实体颜色,支持 CSS 颜色值;常用色可用 Color 枚举,null 隐藏该部分。
CandlePlotOptions.format
CandlePlotOptions.format?: Format | undefined数值格式档位;缺省继承指标级 format,用于图例数值显示。
BarPlotOptions
export interface BarPlotOptions extends OhlcPlotOptions {
}美国线的竖线和左右短横线共用颜色。
ScriptFillOptions
export interface ScriptFillOptions {
readonly visible?: boolean;
}fill 第 5 个参数的可选样式;title 缺省时按 from/to 生成填充标识。
ScriptFillOptions.visible
ScriptFillOptions.visible?: boolean | undefined是否绘制填充;不填则绘制。
HLineRef
export interface HLineRef {
readonly hline: string;
}hline 返回的句柄;fill 借它引用两条水平线之间的区域。
HLineRef.hline
HLineRef.hline: string句柄所属水平线的 id,只在本轮运行内有效。
HLineOptions
export interface HLineOptions {
readonly title?: string;
readonly color?: Color | (string & {});
readonly linestyle?: HLineStyle;
readonly linewidth?: number;
}hline 的调用样式;价格由位置参数提供。
HLineOptions.title
HLineOptions.title?: string | undefined无障碍标题;缺省不显示。
HLineOptions.color
HLineOptions.color?: Color | (string & {}) | undefined颜色,支持 CSS 颜色值;常用色可用 Color 枚举。
HLineOptions.linestyle
HLineOptions.linestyle?: HLineStyle | undefined线型;缺省实线。
HLineOptions.linewidth
HLineOptions.linewidth?: number | undefined线宽,逻辑像素;缺省 1。
LibraryModules
export interface LibraryModules {
}库的类型目录,由宿主按库名补充,不负责运行时加载。 内置库的类型目录。
LibraryModules.ta
LibraryModules.ta: TechnicalAnalysisLibraryLibraryModules
interface LibraryModules {
ta: TechnicalAnalysisLibrary;
}库的类型目录,由宿主按库名补充,不负责运行时加载。 内置库的类型目录。
ScriptRequest
export interface ScriptRequest {
security<T extends RequestValue | Series | readonly (RequestValue | Series)[]>(symbol: string, timeframe: Timeframe, expression: () => T, options?: SecurityOptions): RequestResult<T>;
}跨品种、跨周期取数入口,等价于 Pine 的 request.security。
RequestValue
export type RequestValue = number | string | boolean | null | readonly RequestValue[];SecurityOptions
export interface SecurityOptions {
readonly source?: DataSource;
readonly calcBarsCount?: number;
readonly gaps?: 'off' | 'on';
}SecurityOptions.source
SecurityOptions.source?: DataSource | undefined目标来源的 sourceId;仅当请求品种与图表品种不同时必须显式指定。
SecurityOptions.calcBarsCount
SecurityOptions.calcBarsCount?: number | undefined图表历史起点之前额外加载的目标周期预热根数,缺省 300。
SecurityOptions.gaps
SecurityOptions.gaps?: "off" | "on" | undefined缺口策略:off 延续最近可用结果,on 只在新目标结果出现时输出,其余点留空。
RequestResult
export type RequestResult<T> = T extends Series ? number : T extends readonly unknown[] ? {
readonly [K in keyof T]: RequestResult<T[K]>;
} : T;BoxOptions
export interface BoxOptions {
readonly left: number;
readonly top: number;
readonly right: number;
readonly bottom: number;
readonly borderColor?: Color | (string & {});
readonly borderWidth?: number;
readonly borderStyle?: BoxBorderStyle;
readonly extend?: LineExtend;
readonly xloc?: LineXLoc;
readonly backgroundColor?: Color | (string & {});
readonly text?: string;
readonly textSize?: number;
readonly textColor?: Color | (string & {});
}Box 的选项对象形态;只写需要的字段,省略只接受单一取值的参数。
BoxOptions.left
BoxOptions.left: number左边界;按 xloc 读取索引或时间戳。
BoxOptions.top
BoxOptions.top: number上边界价格。
BoxOptions.right
BoxOptions.right: number右边界;规则同 left。
BoxOptions.bottom
BoxOptions.bottom: number下边界价格。
BoxOptions.borderColor
BoxOptions.borderColor?: Color | (string & {}) | undefined边框颜色,缺省 Color.Blue。
BoxOptions.borderWidth
BoxOptions.borderWidth?: number | undefined边框宽度,逻辑像素;0 表示不画边框。
BoxOptions.borderStyle
BoxOptions.borderStyle?: BoxBorderStyle | undefined边框线型,缺省 solid。
BoxOptions.extend
BoxOptions.extend?: LineExtend | undefined延伸方向,缺省不延伸。
BoxOptions.xloc
BoxOptions.xloc?: LineXLoc | undefinedX 坐标单位,缺省 bar_index。
BoxOptions.backgroundColor
BoxOptions.backgroundColor?: Color | (string & {}) | undefined填充颜色;缺省与边框同色。
BoxOptions.text
BoxOptions.text?: string | undefined框内文字,缺省为空。
BoxOptions.textSize
BoxOptions.textSize?: number | undefined文字字号,缺省 12。
BoxOptions.textColor
BoxOptions.textColor?: Color | (string & {}) | undefined文字颜色;缺省跟随边框颜色。
LabelOptions
export interface LabelOptions {
readonly x: number;
readonly y: number;
readonly text?: string;
readonly xloc?: LineXLoc;
readonly color?: Color | (string & {});
readonly textColor?: Color | (string & {});
readonly size?: number;
readonly align?: DrawingText['align'];
readonly offsetY?: number;
}Label 的选项对象形态;只写需要的字段,省略 yloc/style 这类只有一个取值的参数。
LabelOptions.x
LabelOptions.x: number锚点 X;按 xloc 读取索引或时间戳。
LabelOptions.y
LabelOptions.y: number锚点价格。
LabelOptions.text
LabelOptions.text?: string | undefined文字,缺省为空字符串。
LabelOptions.xloc
LabelOptions.xloc?: LineXLoc | undefinedX 坐标单位,缺省 bar_index。
LabelOptions.color
LabelOptions.color?: Color | (string & {}) | undefined文字颜色;同时作为标签颜色。
LabelOptions.textColor
LabelOptions.textColor?: Color | (string & {}) | undefined文字颜色覆盖;缺省跟随 color。
LabelOptions.size
LabelOptions.size?: number | undefined字号,逻辑像素,缺省 12。
LabelOptions.align
LabelOptions.align?: "left" | "right" | "center" | undefined水平对齐,缺省 center。
LabelOptions.offsetY
LabelOptions.offsetY?: number | undefined垂直偏移,逻辑像素,正数向上,缺省 0。
LineOptions
export interface LineOptions {
readonly x1: number;
readonly y1: number;
readonly x2: number;
readonly y2: number;
readonly xloc?: LineXLoc;
readonly extend?: LineExtend;
readonly color?: Color | (string & {});
readonly style?: LineStyle;
readonly width?: number;
}Line 的选项对象形态;只写需要的字段,等价于位置参数。
LineOptions.x1
LineOptions.x1: number起点 X;按 xloc 读取索引或时间戳。
LineOptions.y1
LineOptions.y1: number起点价格。
LineOptions.x2
LineOptions.x2: number终点 X;规则同 x1。
LineOptions.y2
LineOptions.y2: number终点价格。
LineOptions.xloc
LineOptions.xloc?: LineXLoc | undefinedX 坐标单位,缺省 bar_index。
LineOptions.extend
LineOptions.extend?: LineExtend | undefined延伸方向,缺省不延伸。
LineOptions.color
LineOptions.color?: Color | (string & {}) | undefined颜色,缺省 Color.Blue。
LineOptions.style
LineOptions.style?: LineStyle | undefined线型或箭头,缺省实线。
LineOptions.width
LineOptions.width?: number | undefined线宽,逻辑像素,缺省 1。
QuickJSScriptDefinition
export interface QuickJSScriptDefinition {
readonly name: string;
readonly title?: string;
readonly info?: string;
readonly position: Position;
readonly format?: Format;
readonly max_lines_count?: number;
readonly max_boxes_count?: number;
readonly max_labels_count?: number;
readonly inputs: InputSchema<Record<string, ScriptParamValue>>;
}从完整脚本文件声明中读取的元数据,函数仍留在 VM 内执行。
QuickJSScriptDefinition.name
QuickJSScriptDefinition.name: string稳定身份与选择器短名;注册身份由宿主维护。
QuickJSScriptDefinition.title
QuickJSScriptDefinition.title?: string | undefined指标选择器/图例显示的长名称;缺省用 name。
QuickJSScriptDefinition.info
QuickJSScriptDefinition.info?: string | undefined指标选择器里的说明文本;缺省不展示说明。
QuickJSScriptDefinition.position
QuickJSScriptDefinition.position: Position指标渲染位置。
| 取值 | 含义 |
|---|---|
Position.Main | 叠加到主图,与 K 线共用主图价格轴 |
Position.Sub | 独立副图 |
QuickJSScriptDefinition.format
QuickJSScriptDefinition.format?: Format | undefined指标级数值格式;驱动副图轴与图例显示,缺省按价格。
QuickJSScriptDefinition.max_lines_count
QuickJSScriptDefinition.max_lines_count?: number | undefined可保留的 line 对象数;默认 50,范围 1..2000。
QuickJSScriptDefinition.max_boxes_count
QuickJSScriptDefinition.max_boxes_count?: number | undefined可保留的 Box 数量;默认值与范围由公共 drawing 契约管理。
QuickJSScriptDefinition.max_labels_count
QuickJSScriptDefinition.max_labels_count?: number | undefined可保留的 Label 数量。
QuickJSScriptDefinition.inputs
QuickJSScriptDefinition.inputs: InputSchema<Record<string, ScriptParamValue>>PlotDeclaration
export type PlotDeclaration = ScalarPlotDeclaration | OhlcPlotDeclaration;PlotDeclaration.kind
PlotDeclaration.kind: "line" | "linebr" | "stepline" | "steplinebr" | "histogram" | "columns" | "points" | "shape" | "char" | "arrow" | "candle" | "bar"绘图类型:折线。 绘图类型:柱状图。 绘图类型:散点。 绘图类型:固定形状标记。 绘图类型:字符标记。 绘图类型:数值箭头,正负决定方向,绝对值决定长度。
PlotDeclaration.name
PlotDeclaration.name: string绘图名称,相同名称的数据会画在同一条线或同一组标记中。
PlotDeclaration.label
PlotDeclaration.label?: string | undefined图例名称;不填则取 name。
PlotDeclaration.color
PlotDeclaration.color?: Color | (string & {}) | null | undefined图形颜色,支持 CSS 颜色值;常用色可用 Color 枚举,可为每根 K 线设置不同颜色。
实体颜色,支持 CSS 颜色值;常用色可用 Color 枚举,null 隐藏该部分。
PlotDeclaration.format
PlotDeclaration.format?: Format | undefined数值格式档位;缺省继承指标级 format,用于图例数值显示。
PlotDeclaration.offset
PlotDeclaration.offset?: number | undefined图形移动的 K 线根数;正值向右、负值向左,不填则不移动。
PlotDeclaration.visible
PlotDeclaration.visible?: boolean | undefined是否显示图形;不填则显示。
OhlcPlotOptions
export interface OhlcPlotOptions {
readonly label?: string;
readonly visible?: boolean;
readonly offset?: number;
readonly showLast?: number;
readonly color?: Color | (string & {}) | null;
readonly format?: Format;
}四价格图形的调用样式;颜色允许逐 bar 变化,null 隐藏对应部分。
HLineStyle
export type HLineStyle = (typeof HLineStyle)[keyof typeof HLineStyle];水平线线型取值。
@summary 水平线线型
hline 的线型档位;与 Pine 的 hline.style_* 对应。
DataSource
export type DataSource = (typeof DataSource)[keyof typeof DataSource];@summary 数据源
内置数据源身份;指定后严格路由,不做跨来源回退。
Format
export type Format = (typeof Format)[keyof typeof Format];@summary 数值格式
数值格式化档位;脚本里用 Format.Volume 即可,不填时按 Format.Price 处理。
| 成员 | 示例 |
|---|---|
Format.Price | 1234.567 |
Format.Volume | 1.25K、12.30M、3.40B |
Format.Percent | 3.45%、-12.30% |
Format.Mintick | 1234.5678901 |
InputSchema
export type InputSchema<P> = {
[K in keyof P]: InputDef<P[K]>;
};输入声明表:键即参数名,P 为解析后的参数值类型。
ScriptParamValue
export type ScriptParamValue = number | string | boolean;可以在脚本中作为 params 读取的输入值。
ScalarPlotDeclaration
export type ScalarPlotDeclaration = LinePlotDeclaration | LineBRPlotDeclaration | StepLinePlotDeclaration | StepLineBRPlotDeclaration | HistogramPlotDeclaration | ColumnsPlotDeclaration | PointsPlotDeclaration | ShapePlotDeclaration | CharPlotDeclaration | ArrowPlotDeclaration;声明的 Plot:按 kind 区分各图形及其专用字段。
ScalarPlotDeclaration.kind
ScalarPlotDeclaration.kind: "line" | "linebr" | "stepline" | "steplinebr" | "histogram" | "columns" | "points" | "shape" | "char" | "arrow"绘图类型:折线。 绘图类型:柱状图。 绘图类型:散点。 绘图类型:固定形状标记。 绘图类型:字符标记。 绘图类型:数值箭头,正负决定方向,绝对值决定长度。
ScalarPlotDeclaration.name
ScalarPlotDeclaration.name: string绘图名称,相同名称的数据会画在同一条线或同一组标记中。
ScalarPlotDeclaration.label
ScalarPlotDeclaration.label?: string | undefined图例名称;不填则取 name。
ScalarPlotDeclaration.color
ScalarPlotDeclaration.color?: Color | (string & {}) | undefined图形颜色,支持 CSS 颜色值;常用色可用 Color 枚举,可为每根 K 线设置不同颜色。
ScalarPlotDeclaration.format
ScalarPlotDeclaration.format?: Format | undefined数值格式档位;缺省继承指标级 format,用于图例数值显示。
ScalarPlotDeclaration.textColor
ScalarPlotDeclaration.textColor?: Color | (string & {}) | undefined标记附加文字的颜色,支持 CSS 颜色值;常用色可用 Color 枚举,默认与图形颜色一致。
ScalarPlotDeclaration.offset
ScalarPlotDeclaration.offset?: number | undefined图形移动的 K 线根数;正值向右、负值向左,不填则不移动。
ScalarPlotDeclaration.visible
ScalarPlotDeclaration.visible?: boolean | undefined是否显示图形;不填则显示。
ScalarPlotDeclaration.size
ScalarPlotDeclaration.size?: number | ShapeSize | undefined图形尺寸档位;不填则使用 ShapeSize.Auto。 折线控制线宽,散点控制直径,形状和字符控制外框,箭头控制最大高度。 具体尺寸见 ShapeSize 的档位对照表。 固定逻辑像素柱宽,或 Size 档位;默认 1px。
OhlcPlotDeclaration
export type OhlcPlotDeclaration = CandlePlotDeclaration | BarPlotDeclaration;OhlcPlotDeclaration.name
OhlcPlotDeclaration.name: stringOhlcPlotDeclaration.kind
OhlcPlotDeclaration.kind: "candle" | "bar"InputDef
export interface InputDef<T> extends InputOptions {
readonly default: T;
readonly options?: readonly string[];
readonly min?: number;
readonly max?: number;
readonly step?: number;
}单个输入参数的声明,由 input() 工厂产出。
InputDef.default
InputDef.default: T默认值,同时决定参数在面板中的编辑类型。
InputDef.options
InputDef.options?: readonly string[] | undefinedInputDef.min
InputDef.min?: number | undefinedInputDef.max
InputDef.max?: number | undefinedInputDef.step
InputDef.step?: number | undefinedLinePlotDeclaration
export interface LinePlotDeclaration extends PlotDeclarationBase {
readonly kind: 'line';
readonly dash?: readonly number[];
}普通折线及其样式,跨空值连接有效点。
LinePlotDeclaration.kind
LinePlotDeclaration.kind: "line"绘图类型:折线。
LinePlotDeclaration.dash
LinePlotDeclaration.dash?: readonly number[] | undefined虚线的线段与间隔长度,单位为逻辑像素;不填或填空数组则画实线。
LinePlotDeclaration.name
LinePlotDeclaration.name: string绘图名称,相同名称的数据会画在同一条线或同一组标记中。
LinePlotDeclaration.label
LinePlotDeclaration.label?: string | undefined图例名称;不填则取 name。
LinePlotDeclaration.color
LinePlotDeclaration.color?: Color | (string & {}) | undefined图形颜色,支持 CSS 颜色值;常用色可用 Color 枚举,可为每根 K 线设置不同颜色。
LinePlotDeclaration.format
LinePlotDeclaration.format?: Format | undefined数值格式档位;缺省继承指标级 format,用于图例数值显示。
LinePlotDeclaration.textColor
LinePlotDeclaration.textColor?: Color | (string & {}) | undefined标记附加文字的颜色,支持 CSS 颜色值;常用色可用 Color 枚举,默认与图形颜色一致。
LinePlotDeclaration.offset
LinePlotDeclaration.offset?: number | undefined图形移动的 K 线根数;正值向右、负值向左,不填则不移动。
LinePlotDeclaration.visible
LinePlotDeclaration.visible?: boolean | undefined是否显示图形;不填则显示。
LinePlotDeclaration.size
LinePlotDeclaration.size?: ShapeSize | undefined图形尺寸档位;不填则使用 ShapeSize.Auto。 折线控制线宽,散点控制直径,形状和字符控制外框,箭头控制最大高度。 具体尺寸见 ShapeSize 的档位对照表。
LineBRPlotDeclaration
export interface LineBRPlotDeclaration extends Omit<LinePlotDeclaration, 'kind'> {
readonly kind: 'linebr';
}断线折线及其样式,空值处断开。
LineBRPlotDeclaration.kind
LineBRPlotDeclaration.kind: "linebr"LineBRPlotDeclaration.dash
LineBRPlotDeclaration.dash?: readonly number[] | undefined虚线的线段与间隔长度,单位为逻辑像素;不填或填空数组则画实线。
LineBRPlotDeclaration.name
LineBRPlotDeclaration.name: string绘图名称,相同名称的数据会画在同一条线或同一组标记中。
LineBRPlotDeclaration.label
LineBRPlotDeclaration.label?: string | undefined图例名称;不填则取 name。
LineBRPlotDeclaration.color
LineBRPlotDeclaration.color?: Color | (string & {}) | undefined图形颜色,支持 CSS 颜色值;常用色可用 Color 枚举,可为每根 K 线设置不同颜色。
LineBRPlotDeclaration.format
LineBRPlotDeclaration.format?: Format | undefined数值格式档位;缺省继承指标级 format,用于图例数值显示。
LineBRPlotDeclaration.textColor
LineBRPlotDeclaration.textColor?: Color | (string & {}) | undefined标记附加文字的颜色,支持 CSS 颜色值;常用色可用 Color 枚举,默认与图形颜色一致。
LineBRPlotDeclaration.offset
LineBRPlotDeclaration.offset?: number | undefined图形移动的 K 线根数;正值向右、负值向左,不填则不移动。
LineBRPlotDeclaration.visible
LineBRPlotDeclaration.visible?: boolean | undefined是否显示图形;不填则显示。
LineBRPlotDeclaration.size
LineBRPlotDeclaration.size?: ShapeSize | undefined图形尺寸档位;不填则使用 ShapeSize.Auto。 折线控制线宽,散点控制直径,形状和字符控制外框,箭头控制最大高度。 具体尺寸见 ShapeSize 的档位对照表。
StepLinePlotDeclaration
export interface StepLinePlotDeclaration extends Omit<LinePlotDeclaration, 'kind'> {
readonly kind: 'stepline';
}阶梯线声明,在相邻有效点的水平中点跳变,跨空值连接。
StepLinePlotDeclaration.kind
StepLinePlotDeclaration.kind: "stepline"StepLineBRPlotDeclaration
export interface StepLineBRPlotDeclaration extends Omit<LinePlotDeclaration, 'kind'> {
readonly kind: 'steplinebr';
}断线阶梯线声明,空值处断开。
StepLineBRPlotDeclaration.kind
StepLineBRPlotDeclaration.kind: "steplinebr"HistogramPlotDeclaration
export interface HistogramPlotDeclaration extends Omit<PlotDeclarationBase, 'size'> {
readonly kind: 'histogram';
readonly baseline?: number;
readonly size?: ShapeSize | number;
}柱状图及其样式。
HistogramPlotDeclaration.kind
HistogramPlotDeclaration.kind: "histogram"绘图类型:柱状图。
HistogramPlotDeclaration.baseline
HistogramPlotDeclaration.baseline?: number | undefined柱状图的起始基线值;不填则取 0。
HistogramPlotDeclaration.size
HistogramPlotDeclaration.size?: number | ShapeSize | undefined固定逻辑像素柱宽,或 Size 档位;默认 1px。
HistogramPlotDeclaration.name
HistogramPlotDeclaration.name: string绘图名称,相同名称的数据会画在同一条线或同一组标记中。
HistogramPlotDeclaration.label
HistogramPlotDeclaration.label?: string | undefined图例名称;不填则取 name。
HistogramPlotDeclaration.color
HistogramPlotDeclaration.color?: Color | (string & {}) | undefined图形颜色,支持 CSS 颜色值;常用色可用 Color 枚举,可为每根 K 线设置不同颜色。
HistogramPlotDeclaration.format
HistogramPlotDeclaration.format?: Format | undefined数值格式档位;缺省继承指标级 format,用于图例数值显示。
HistogramPlotDeclaration.textColor
HistogramPlotDeclaration.textColor?: Color | (string & {}) | undefined标记附加文字的颜色,支持 CSS 颜色值;常用色可用 Color 枚举,默认与图形颜色一致。
HistogramPlotDeclaration.offset
HistogramPlotDeclaration.offset?: number | undefined图形移动的 K 线根数;正值向右、负值向左,不填则不移动。
HistogramPlotDeclaration.visible
HistogramPlotDeclaration.visible?: boolean | undefined是否显示图形;不填则显示。
ColumnsPlotDeclaration
export interface ColumnsPlotDeclaration extends Omit<PlotDeclarationBase, 'size'> {
readonly kind: 'columns';
readonly baseline?: number;
readonly size?: never;
}自动柱宽随 K 线间距缩放,不支持 size。
ColumnsPlotDeclaration.kind
ColumnsPlotDeclaration.kind: "columns"ColumnsPlotDeclaration.baseline
ColumnsPlotDeclaration.baseline?: number | undefinedColumnsPlotDeclaration.size
ColumnsPlotDeclaration.size?: undefinedPointsPlotDeclaration
export interface PointsPlotDeclaration extends PlotDeclarationBase {
readonly kind: 'points';
}点图 Plot 声明;散点直径由公共 size 决定。
PointsPlotDeclaration.kind
PointsPlotDeclaration.kind: "points"绘图类型:散点。
ShapePlotDeclaration
export interface ShapePlotDeclaration extends PlotDeclarationBase, ShapeOptions {
readonly kind: 'shape';
}形状标记及其样式。
ShapePlotDeclaration.kind
ShapePlotDeclaration.kind: "shape"绘图类型:固定形状标记。
ShapePlotDeclaration.style
ShapePlotDeclaration.style?: ShapeStyle | undefined标记形状;不填则使用 ShapeStyle.XCross。
ShapePlotDeclaration.location
ShapePlotDeclaration.location?: ShapeLocation | undefined标记位置;默认在 K 线上方,ShapeLocation.Absolute 表示绘制在 value 指定的价格处。
ShapePlotDeclaration.text
ShapePlotDeclaration.text?: string | undefined标记旁的附加文字;不填则不显示附加文字。
CharPlotDeclaration
export interface CharPlotDeclaration extends PlotDeclarationBase, CharOptions {
readonly kind: 'char';
}字符标记声明。
CharPlotDeclaration.kind
CharPlotDeclaration.kind: "char"绘图类型:字符标记。
CharPlotDeclaration.char
CharPlotDeclaration.char?: string | undefined要绘制的单个 Unicode 字符;不填则显示 ★,填空字符串则只显示附加文字。
ArrowPlotDeclaration
export interface ArrowPlotDeclaration extends PlotDeclarationBase, ArrowOptions {
readonly kind: 'arrow';
}数值箭头声明。
ArrowPlotDeclaration.kind
ArrowPlotDeclaration.kind: "arrow"绘图类型:数值箭头,正负决定方向,绝对值决定长度。
ArrowPlotDeclaration.colorUp
ArrowPlotDeclaration.colorUp?: Color | (string & {}) | undefined正值向上箭头的颜色,支持 CSS 颜色值;常用色可用 Color 枚举,默认使用 color。
ArrowPlotDeclaration.colorDown
ArrowPlotDeclaration.colorDown?: Color | (string & {}) | undefined负值向下箭头的颜色,支持 CSS 颜色值;常用色可用 Color 枚举,默认使用 color。
CandlePlotDeclaration
export interface CandlePlotDeclaration extends CandlePlotOptions {
readonly name: string;
readonly kind: 'candle';
}CandlePlotDeclaration.name
CandlePlotDeclaration.name: stringCandlePlotDeclaration.kind
CandlePlotDeclaration.kind: "candle"BarPlotDeclaration
export interface BarPlotDeclaration extends BarPlotOptions {
readonly name: string;
readonly kind: 'bar';
}BarPlotDeclaration.name
BarPlotDeclaration.name: stringBarPlotDeclaration.kind
BarPlotDeclaration.kind: "bar"PlotDeclarationBase
export interface PlotDeclarationBase extends PlotStyleBase {
readonly name: string;
}声明式 Plot 的公共信息。
ShapeSize
export type ShapeSize = 'auto' | 'tiny' | 'small' | 'normal' | 'large' | 'huge';@summary 尺寸档位
图形尺寸档位;size 不填则使用 Auto,各档位的尺寸如下。
| 档位 | 折线宽度(px) | 散点直径(px) | 形状 / 字符外框边长(px) | 箭头最大高度(px) | Histogram 柱宽(px) |
|---|---|---|---|---|---|
| ShapeSize.Auto | 1 | 3 | 12 | 50 | 1 |
| ShapeSize.Tiny | 1 | 6 | 6 | 20 | 1 |
| ShapeSize.Small | 1 | 10 | 10 | 30 | 1 |
| ShapeSize.Normal | 2 | 14 | 14 | 40 | 2 |
| ShapeSize.Large | 3 | 20 | 20 | 60 | 3 |
| ShapeSize.Huge | 4 | 28 | 28 | 90 | 4 |
px 为逻辑像素;箭头实际高度随数值幅度变化,最短为最大高度的 10%。 Columns 不接受 size,柱宽随 K 线间距自动调整。
ShapeOptions
export interface ShapeOptions extends MarkerOptions {
readonly style?: ShapeStyle;
}固定形状标记的专属样式。
ShapeOptions.textColor
ShapeOptions.textColor?: Color | (string & {}) | undefined标记附加文字的颜色,支持 CSS 颜色值;常用色可用 Color 枚举,默认与图形颜色一致。
CharOptions
export interface CharOptions extends MarkerOptions {
readonly char?: string;
}字符标记;空字符可只显示附加文字。
ArrowOptions
export interface ArrowOptions {
readonly colorUp?: Color | (string & {});
readonly colorDown?: Color | (string & {});
}数值箭头的方向颜色;箭头长度由 Plot 公共的 size 决定。
PlotStyleBase
export interface PlotStyleBase {
readonly label?: string;
readonly color?: Color | (string & {});
readonly format?: Format;
readonly textColor?: Color | (string & {});
readonly offset?: number;
readonly visible?: boolean;
readonly size?: ShapeSize;
}声明式 Plot 的公共样式。
MarkerOptions
export interface MarkerOptions {
readonly location?: ShapeLocation;
readonly text?: string;
readonly textColor?: Color | (string & {});
}Shape 与 Char 的共享样式;相对位置过滤零值,absolute 把 value 当价格。
ShapeStyle
export type ShapeStyle = 'xcross' | 'cross' | 'circle' | 'square' | 'diamond' | 'triangleup' | 'triangledown' | 'arrowup' | 'arrowdown' | 'labelup' | 'labeldown' | 'flag';@summary 标记形状
固定形状标记可选的外形;缺省使用 XCross。
ShapeLocation
export type ShapeLocation = 'abovebar' | 'belowbar' | 'top' | 'bottom' | 'absolute';@summary 标记位置
标记相对 K 线的位置;缺省在 K 线上方,Absolute 表示按价格定位。