0
关注
172
关注者

优宽 PINE Script 文档

创建于: 2022-05-10 10:18:57, 更新于: 2025-01-23 10:27:09
comments   0
hits   4638

y

当前权益(strategy.initial_capital + strategy.netprofit + strategy.openprofit)。

类型 series float

另见


### strategy.position_size

目前市场头寸的方向和规模。 如果值> 0,则市场头寸较长。 如果值<0,则市场头寸较短。 绝对值是交易中的合同/股/手/单位数(头寸大小)。

**类型**
series float

**另见**
```strategy.position_avg_price```

### strategy.position_avg_price

当前市场定位平均入场价。 如果市场地位平滑,则“NaN”就会退回。

**说明**
优宽 PINE Script中的均价均为包含手续费的价格。例如:下单价格为8000,卖出方向,数量1手(个、张),成交后均价不是8000,低于8000(成本中包含了手续费)。

**类型**
series float

**另见**
```strategy.position_size```

### strategy.long

多头方向。

**类型**
strategy_direction

**另见**
```strategy.entry``` ```strategy.exit```

### strategy.short

空头方向。

**类型**
strategy_direction

**另见**
```strategy.entry``` ```strategy.exit```

### strategy.closedtrades

在整个交易间隔内被关闭的交易数量。

**类型**
series int

**另见**
```strategy.position_size``` ```strategy.opentrades```

### strategy.opentrades

未关闭或者继续持有的交易数量。如果没有,则显示0。

**类型**
series int

**另见**
```strategy.position_size```

### strategy.netprofit

所有已完成交易的总货币价值。

**类型**
series float

**另见**
```strategy.openprofit``` ```strategy.position_size``` ```strategy.grossprofit```

### strategy.grossprofit

所有已完成赢利交易的总货币价值。

**类型**
series float

**另见**
```strategy.netprofit```

### strategy.openprofit

当前未结仓位的未实现损益。

**类型**
series float

**另见**
```strategy.netprofit``` ```strategy.position_size```

### strategy.direction.long

只能做多的策略

**类型**
const string

**另见**
```strategy.risk.allow_entry_in```

### strategy.direction.short

只能做空的策略

**类型**
const string

**另见**
```strategy.risk.allow_entry_in```

### strategy.direction.all

允许既可以做多又可以做空的策略

**类型**
const string

**另见**
```strategy.risk.allow_entry_in```

## dayofweek

### dayofweek

交换时区的当前k线时间的星期。

**类型**
series int

**备注**
请注意,此变量根据K线的打开时间返回天。对于隔夜交易时段(例如EURUSD,其周一交易时段从周日17:00开始),该值可以比交易日的天低1。
您可以使用dayofweek.sunday,dayofweek.monday,dayofweek.tuesday,dayofweek.wednesday,dayofweek.thursday,dayofweek.friday和dayofweek.saturday变量用于比较。

**另见**
```time``` ```dayofmonth```

### dayofweek.sunday

是dayofweek函数的返回值和dayofweek变量的值的命名常量。

**类型**
const int

**另见**
```dayofweek.monday``` ```dayofweek.tuesday``` ```dayofweek.wednesday``` ```dayofweek.thursday``` ```dayofweek.friday``` ```dayofweek.saturday```

### dayofweek.monday

是dayofweek函数的返回值和dayofweek变量的值的命名常量。

**类型**
const int

**另见**
```dayofweek.sunday``` ```dayofweek.tuesday``` ```dayofweek.wednesday``` ```dayofweek.thursday``` ```dayofweek.friday``` ```dayofweek.saturday```

### dayofweek.tuesday

是dayofweek函数的返回值和dayofweek变量的值的命名常量。

**类型**
const int

**另见**
```dayofweek.sunday``` ```dayofweek.monday``` ```dayofweek.wednesday``` ```dayofweek.thursday``` ```dayofweek.friday``` ```dayofweek.saturday```

### dayofweek.wednesday

是dayofweek函数的返回值和dayofweek变量的值的命名常量。

**类型**
const int

**另见**
```dayofweek.sunday``` ```dayofweek.monday``` ```dayofweek.tuesday``` ```dayofweek.thursday``` ```dayofweek.friday``` ```dayofweek.saturday```

### dayofweek.thursday

是dayofweek函数的返回值和dayofweek变量的值的命名常量。

**类型**
const int

**另见**
```dayofweek.sunday``` ```dayofweek.monday``` ```dayofweek.tuesday``` ```dayofweek.wednesday``` ```dayofweek.friday``` ```dayofweek.saturday```

### dayofweek.friday

是dayofweek函数的返回值和dayofweek变量的值的命名常量。

**类型**
const int

**另见**
```dayofweek.sunday``` ```dayofweek.monday``` ```dayofweek.tuesday``` ```dayofweek.wednesday``` ```dayofweek.thursday``` ```dayofweek.saturday```

### dayofweek.saturday

是dayofweek函数的返回值和dayofweek变量的值的命名常量。

**类型**
const int

**另见**
```dayofweek.sunday``` ```dayofweek.monday``` ```dayofweek.tuesday``` ```dayofweek.wednesday``` ```dayofweek.thursday``` ```dayofweek.friday```

## hline

### hline.style_dashed

是Hline函数的点划线样式的命名常量。

**类型**
hline_style

**另见**
```hline.style_solid``` ```hline.style_dotted```

### hline.style_dotted

hline.style_dotted

是Hline函数的点虚线样式的命名常量。

**类型**
hline_style

**另见**
```hline.style_solid``` ```hline.style_dashed```

### hline.style_solid

是Hline函数的实心线型的命名常量。

**类型**
hline_style

**另见**
```hline.style_dotted``` ```hline.style_dashed```

## barmerge

### barmerge.gaps_on

给所请求的数据合并策略。 数据与可能的差距(na值)合并。

**类型**
barmerge_gaps

**另见**
```request.security``` ```barmerge.gaps_off```

### barmerge.gaps_off

合并所请求数据的策略。 数据不间断地合并,所有的差距都以先前最近的现有值填满。

**类型**
barmerge_gaps

**另见**
```request.security``` ```barmerge.gaps_on```

### barmerge.lookahead_on

合并所请求数据位置的策略。 请求的条形图与当前的条形图按照k线开盘时间合并。 这种合并策略可能导致从“未来”获取数据计算历史的不良影响。 这在回溯测试策略中不被接受,但在指标中可使用。

**类型**
barmerge_lookahead

**另见**
```request.security``` ```barmerge.lookahead_off```

### barmerge.lookahead_off

合并所请求数据位置的策略。 所请求的条形图与当前的条形图按照k线收盘时间合并。 这种合并策略禁止从“未来”获取数据计算历史的影响。

**类型**
barmerge_lookahead

**另见**
```request.security``` ```barmerge.lookahead_on```

## others

### hl2

是(最高价 + 最低价)/2的快捷键

**类型**
series float

**另见**
```open``` ```high``` ```low``` ```close``` ```volume``` ```time``` ```hlc3``` ```hlcc4``` ```ohlc4```

### hlc3

是(最高价+最低价+收盘价)/3的快捷键

**类型**
series float

**另见**
```open``` ```high``` ```low``` ```close``` ```volume``` ```time``` ```hl2``` ```hlcc4``` ```ohlc4```

### hlcc4

是(高+低+收+收)/4的快捷键

**类型**
series float

**另见**
```open``` ```high``` ```low``` ```close``` ```volume``` ```time``` ```hl2``` ```hlc3``` ```ohlc4```

### ohlc4

是(开盘价 + 最高价 + 最低价 + 收盘价)/4的快捷键

**类型**
series float

**另见**
```open``` ```high``` ```low``` ```close``` ```volume``` ```time``` ```hl2``` ```hlc3``` ```hlcc4```

### na

Double.NaN值 (非数字)。

**类型**
simple na

**例子**
```pine
// na
plot(bar_index < 10 ? na : close)    // CORRECT
plot(close == na ? close[1] : close)    // INCORRECT!
plot(na(close) ? close[1] : close)    // CORRECT

备注 仅用于返回值。 别试图与它比较! 如果您要检查某些值是否为NaN,请使用内置函数na。

另见


### bar_index

目前的价格棒指数。 编号从零开始,第一个条的索引为0。

**类型**
series int

**例子**
```pine
// bar_index
plot(bar_index)
plot(bar_index > 5000 ? close : 0)

备注 请注意, bar_index 已替换版本4中的 n 变量。 请注意,K线索引从第一根历史K线起算为0。 请注意,使用此变量/函数可能会导致指标重新绘制。

另见


### last_bar_index

最后一根图表K线的索引。K线索引以第一根K线为零开始。

**类型**
series int

**例子**

strategy(“Mark Last X Bars For Backtesting”, overlay = true, calc_on_every_tick = true) lastBarsFilterInput = input.int(100, “Bars Count:”) // Here, we store the ‘last_bar_index’ value that is known from the beginning of the script’s calculation. // The ‘last_bar_index’ will change when new real-time bars appear, so we declare ‘lastbar’ with the ‘var’ keyword. var lastbar = last_bar_index // Check if the current bar_index is ‘lastBarsFilterInput’ removed from the last bar on the chart, or the chart is traded in real-time. allowedToTrade = (lastbar - bar_index <= lastBarsFilterInput) or barstate.isrealtime bgcolor(allowedToTrade ? color.new(color.green, 80) : na) “`

返回值 收盘的最后历史K线索引,或开盘的实时K线索引。

备注 请注意,使用此变量可能会导致指标重绘。

另见 bar_index last_bar_time barstate.ishistory barstate.isrealtime

time

UNIX格式的当前k线时间。 这是自1970年1月1日00:00:00 UTC以来的毫秒数。

timenow

UNIX格式的当前时间。 这是自1970年1月1日00:00:00 UTC以来的毫秒数。

类型 series int

备注 请注意,使用此变量/函数可能会导致指标重新绘制。

另见 timestamp time dayofmonth dayofweek

类型 series int

备注 请注意,此变量将根据K线的打开时间返回时间戳。因此,对于隔夜交易时段(例如EURUSD,其周一时段从周日17:00开始),此变量可以返回交易日指定日期之前的时间。例如,在EURUSD上,“dayofmonth(time)”可以比交易日的日期低1,因为当前日期的K线实际上是前一天打开的。

另见 time dayofmonth dayofweek

year

交换时区的当前年k线。

类型 series int

备注 请注意,此变量根据K线的打开时间返回年份。对于隔夜交易时段(例如EURUSD,其周一交易时段从周日17:00开始),该值可以比交易日的年份低1。

另见 year time month weekofyear dayofmonth dayofweek hour minute second

month

交易所时区的当前月k线。

类型 series int

备注 请注意,此变量根据K线的打开时间返回月份。对于隔夜交易时段(例如EURUSD,其周一交易时段从周日17:00开始),该值可以比交易日的月份低1。

另见 month time year weekofyear dayofmonth dayofweek hour minute second

hour

交易所时区的当前小时k线。

类型 series int

另见 hour time year month weekofyear dayofmonth dayofweek minute second

minute

交易所时区的当前分钟k线。

类型 series int

另见 minute time year month weekofyear dayofmonth dayofweek hour second

second

交易所时区的当前秒k线。

类型 series int

另见 second time year month weekofyear dayofmonth dayofweek hour minute

open

当前开盘价。

类型 series float

备注 可使用方括号运算符 []来访问以前的值,例如。 open[1],open[2]。

另见 high low close volume time hl2 hlc3 hlcc4 ohlc4

high

当前最高价。

类型 series float

备注 可使用方括号运算符 []来访问以前的值,例如。 high[1],high[2]。

另见 open low close volume time hl2 hlc3 hlcc4 ohlc4

low

当前最低价。

类型 series float

备注 可使用方括号运算符 []来访问以前的值,例如。 low[1],low[2]。

另见 open high close volume time hl2 hlc3 hlcc4 ohlc4

close

当前K线关闭时的收盘价,或尚未完成的实时K线的最后交易价格。

类型 series float

备注 可使用方括号运算符 []来访问以前的值,例如。 close[1],close[2]。

另见 open high low volume time hl2 hlc3 hlcc4 ohlc4

volume

当前K线成交量。

类型 series float

备注 可使用方括号运算符 []来访问以前的值,例如。 volume[1],volume[2]。

另见 open high low close time hl2 hlc3 hlcc4 ohlc4

weekofyear

交换时区的当前k线时段的周数。

类型 series int

备注 请注意,此变量根据K线的打开时间返回周。对于隔夜交易时段(例如EURUSD,其周一交易时段从周日17:00开始),该值可以比交易日的周低1。

另见 weekofyear time year month dayofmonth dayofweek hour minute second

dayofmonth

交换时区的当前k线时间的日期。

类型 series int

备注 请注意,此变量根据K线的打开时间返回天。对于隔夜交易时段(例如EURUSD,其周一交易时段从周日17:00开始),该值可以比交易日的天低1。

另见 time dayofweek

更多内容