!=
不等于。适用于任何类型的表达式。
expr1 != expr2
返回值
布尔值,或一系列布尔值。
%
模数(整数余数)。 适用于数值表达式。
expr1 % expr2
返回值
整数或浮点值,或一系列值
*
乘法。适用于数值表达式。
expr1 * expr2
返回值
整数或浮点值,或一系列值
+
添加或一元正号。适用于数值表达式或字符串。
expr1 + expr2
+ expr1
返回值
字符串的返回expr1和expr2的合并 数字返回整数或浮点值,或一系列值: 数字'+'返回expr1加expr2。 一元“+”返回expr。
备注
您可以使用带数字的算术运算符以及变量数列。 在使用数列的情况下,操作符应用于元素。
-
减法或一元负号。 适用于数值表达式。
expr1 - expr2
- expr1
返回值
返回整数或浮点值,或一系列值
/
除法。适用于数值表达式。
expr1 / expr2
返回值
整数或浮点值,或一系列值
**
指数运算符。适用于数值表达式。
expr1 ** expr2
返回值
整数或浮点值,或一系列值
%=
模数(整数余数)。 适用于数值表达式。
expr1 %= expr2
等价于
expr1 = expr1 % expr2
备注
在使用前 expr1 必须已经定义
*=
乘法。 适用于数值表达式。
expr1 *= expr2
等价于
expr1 = expr1 * expr2
备注
在使用前 expr1 必须已经定义
+=
加法。 适用于数值表达式。
expr1 += expr2
等价于
expr1 = expr1 + expr2
备注
在使用前 expr1 必须已经定义
-=
减法。 适用于数值表达式。
expr1 -= expr2
等价于
expr1 = expr1 - expr2
备注
在使用前 expr1 必须已经定义
/=
除法。 适用于数值表达式。
expr1 /= expr2
等价于
expr1 = expr1 / expr2
备注
在使用前 expr1 必须已经定义
<
小于。适用于数值表达式。
expr1 < expr2
返回值
整数或浮点值,或一系列值
>
大于。适用于数值表达式。
expr1 > expr2
返回值
整数或浮点值,或一系列值
<=
小于等于。适用于数值表达式。
expr1 <= expr2
返回值
整数或浮点值,或一系列值
>=
大于等于。适用于数值表达式。
expr1 >= expr2
返回值
整数或浮点值,或一系列值
==
等于。适用于数值表达式。
expr1 == expr2
返回值
整数或浮点值,或一系列值
?:
三元条件运算符。
expr1 ? expr2 : expr3
不推荐写法
result = close > open ? highest(close,10) : lowest(close,10)
推荐写法
hi= highest(close,10)
lo = lowest(close,10)
result = close > open ? hi : lo
study(title="Demo")
myInput = input(2,type="int")

result = myInput == 2 ? highest(close,10) : lowest(close,10)
返回值
如果expr1被评估为true,则expr2,否则为expr3。
[]
元组成员引用。
expr1[expr2]
def fun(i,j):
    return i,j

(a,b) = fun(1,2)
r = fun(1,2)
(c, d) = r
e  = r[0]
f = r[1]
返回值
整数或浮点值,或一系列值
and
逻辑与。适用于布尔表达式。
expr1 and expr2
返回值
布尔值,或一系列值
or
逻辑或。适用于布尔表达式。
expr1 or expr2
返回值
布尔值,或一系列值
not
逻辑非。适用于布尔表达式。
expr1 or expr2
返回值
布尔值,或一系列值
for
For语句允许重复执行一些指令。当循环完成且没有被break 取消,则执行else 下的语句块
sum = 0
for i in range(0,10,2):
    sum += i
else:
     sum = 20
if
If语句定义了在满足表达式条件时必须执行的语句块。
sum = 0
if close >open:
    sum+=1
elif close == open:
    sum += 2
else :
    sum+= 3
当在分支内引用 ema ,sma 等 函数时 推荐结构
sum = 0
ema1 = ema(close,2)
ema2 = ema(close,9)
ema3 = ema(close,19)
if close >open:
    sum+=ema1
elif close == open:
    sum += ema2
else :
    sum+= ema3
当在分支内引用 ema ,sma 等 函数时不推荐结构
sum = 0
if close >open:
    sum+=ema(close,2)
elif close == open:
    sum += ema(close,9)
else :
    sum+= ema(close,19)
def
def 定义函数
def my_fun(i,j=open):
    return i,j

(x,y) = my_fun(close)
result = my_fun(close,open)
(a,b) = result
m = result[0]
n = result[1]
print(a)
print(m)
open
当前开盘价
类型
float
high
当前最高价
类型
float
low
当前最低价
类型
float
close
当前收盘价
类型
float
time
当前时间
类型
float
volume
当前成交量
类型
float
plot
在图表上绘制一系列数据
plot(series, title, color, linewidth, style) → plot
plot(high+low, title="Title", color="#00ffaa", linewidth=2, style="area",histbase=0,offset=-10)

# You may fill the background between any two plots with a fill() function:
p1 = plot(open)
p2 = plot(close)
返回值
可用于fill的绘图对象。
参数
series (series)要绘制成箭头的数据系列。 必要参数。
title (const string)绘图标题。
color (color)绘图的颜色。您可以使用如'color = "red"'或'color ="#ff001a"'的常量以及如 'color = close >= open ? "green" : "red"'的复杂表达式。 可选参数。
linewidth (input integer)绘制线的宽度,使用从1到4的值。默认值为1。不适用于每种样式。
style (input integer) 绘图类型。 可能的值包括:"line" "histogram","cross","area" 默认值为 "line"。
histbase (input float)在使用"area"样式渲染绘图时,价格值将被视为起始基点。 默认值为0.0。
offset (integer)在k线特定数量上向左或向右移动绘图。 默认值为0。
fill
在图表上绘制一系列数据
fill(plot1, plot2, color, title) → void
# You may fill the background between any two plots with a fill() function:
p1 = plot(open)
p2 = plot(close)
fill(p1, p2, color=color("green",50))
返回值
可用于fill的绘图对象。
参数
plot1 (plot)首个绘图对象。 必要参数。
plot2 (plot)第二个绘图对象. 必要参数。
color (color)绘图的颜色。您可以使用如'color = red'或'color =#ff001a'的常量以及如 'color = close >= open ? green : red'的复杂表达式。 可选参数。
title (const string)已创建填充对象的标题。 可选参数。
timestamp
时间戳功能返回UNIX时间的指定日期和时间。
timestamp(year, month, day, hour, minute, second) → integer
plot(time>timestamp(2020, 7, 19, 09, 30, 15)?2:1)
例子
show = timestamp(2016, 01, 19, 09, 30) > time 
返回值
Unix时间。
参数
year (integer)
month (integer)
day (integer)
hour (integer) 小时
minute (integer) 分钟
second (integer) (可选参数)Second。默认值为0
change
当前值与以前的值的差异,x - x[y].
change(source, length) → series[float]
返回值
系列差异
参数
source (series)
length (integer) 从当前k线偏移到上一个k线。
rma
RSI中使用的移动平均线。 它是指数加权移动平均线,alpha加权值 = 1 /长度。
rma(source, length) → series[float]
plot(rma(close, 15))


def my_rma(src, length):
    alpha = length
    sum = 0.0
    sum = na(prev(sum,1)) ? sma(src, length) : (src + (alpha - 1) * nz(prev(sum,1))) / alpha
    return sum
plot(my_rma(close, 15))
返回值
x的指数移动平均值= 1 / y。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
lowest
过去k线的给定数目的最低值。
lowest(source, length) → series[float]
plot(lowest(close, 15))
返回值
最低值。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
highest
过去k线的给定数目的最高值。
highest(source, length) → series[float]
plot(highest(close, 15))
返回值
最高值。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
mom
过去x价和x价的动量。这只是x - x [y]的区别。
mom(source, length) → series[float]
plot(mom(close, 15))
返回值
过去x价和x价的动量。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
cci
CCI(商品路径指数)以商品的典型价格与其简单移动平均线之间的差额除以典型价格的平均绝对偏差计算。 该指数以0.015的逆因数缩放,以提供更多可读数字
cci(source, length) → series[float]
plot(cci(close, 15))
返回值
过去y线的x商品路径指标
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
dev
系列与sma之间的差量数
dev(source, length) → series[float]
plot(dev(close, 10))


def my_dev(source, length):
    mean = sma(source, length)
    sum = 0.0
    for i in range(0, length - 1):
        val = prev(source,i)
        sum = sum + abs(val - mean)
    dev = sum/length
    return dev
plot(my_dev(close, 10))
返回值
过去y线的x偏移。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
lowestbars
过去k线的给定数目的最低值偏移。
lowestbars(source, length) → series[float]
plot(lowestbars(close, 15))
返回值
偏移到最低k线。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
highestbars
过去k线的给定数目的最高值偏移。
highestbars(source, length) → series[float]
plot(highestbars(close, 15))
返回值
偏移到最高k线。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
rising
测试x系列是否因长y线下升。
rising(source, length) → series[float]
返回值
如果当前x大于过去y线的任何前一个x,则返回true,否则返回false。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
falling
测试x系列是否因长y线下跌。
falling(source, length) → series[float]
返回值
如果当前x小于过去y线的任何前一个x,则返回true,否则返回false。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
variance
差异是一系列平均偏差(sma)的预期,并且非正式地衡量 一组数字从其平均分布的程度。
variance(source, length) → series[float]
plot(variance(close, 15))

# but less efficient
def my_variance(x, len):
    sm = sma(x, len)
    return sma(x*x,len) - sm*sm

plot(my_variance(close, 15))
返回值
过去y线的x方差。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
vwma
vwma函数返回过去y线的x成交量加权移动均线。 它与以下相同: sma(x * volume, y) / sma(volume, y)
vwma(source, length) → series[float]
plot(vwma(close, 15))

# but less efficient
def my_vwma(x, y):
    return sma(x * volume, y) / sma(volume, y)
plot(my_vwma(close, 15))
返回值
过去y线的x成交量加权移动均线。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
sma
sma函数返回移动平均值,即x的最后y值,除以y。
sma(source, length) → series[float]
plot(sma(close, 15))

#less efficient
def my_sma(x, y):
    sum = 0.0
    for i in range(0, y - 1):
        sum = sum + prev(x,i) / y
    return sum
plot(my_sma(close, 15))
返回值
过去y线的x简单移动平均线。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
ema
sma函数返回指数加权移动平均线。 在ema加权因子呈指数下降。 它通过公式计算:EMA = alpha * x + (1 - alpha) * EMA[1], 其中 alpha = 2 / (y + 1)
ema(source, length) → series[float]
plot(ema(close, 15))

# less efficient
def my_ema(src, length):
    alpha = 2 / (length + 1)
    sum = 0.0
    sum = na(prev(sum,1)) ? sma(src, length) : alpha * src + (1 - alpha) * nz(prev(sum,1))
    return sum
plot(my_ema(close,15))
返回值
x的指数移动平均值与alpha = 2 / (y + 1)。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
wma
wma函数将得回y线的x的加权移动均线。 在wma,加权因子在算术进程中减少。
wma(source, length) → series[float]
plot(wma(close, 15))

# less efficient
def my_wma(x, y):
    norm = 0.0
    sum = 0.0
    for i in range(0, y - 1):
        weight = (y - i) * y
        norm = norm + weight
        sum = sum + prev(x,i) * weight
    return sum / norm
plot(my_wma(close, 15))
返回值
过去y线的x加权移动均线。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
rsi
相对强度指数。它是根据rma的向上和向下变化x来计算的。
rsi(source, length) → series[float]
plot(rsi(close, 7))
# less efficient
def my_rsi(x, y):
    u = max(x - prev(x,1), 0) # upward change
    d = max(prev(x,1) - x, 0) # downward change
    rs = rma(u, y) / rma(d, y)
    res = 100 - 100 / (1 + rs)
    return res

plot(my_rsi(close, 7))
返回值
相对强弱指标(RSI)
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
stdev
标准差
stdev(source, length) → series[float]
plot(stdev(close, 5))


def isZero(val, eps):
    return abs(val) <= eps

def SUM(fst, snd):
    EPS = 0.0000000001
    res = fst + snd
    result = 0
    if isZero(res, EPS):
        result = 0
    else:
        if not isZero(res, 0.00001):
            result = res
        else:
            result = 15
    return result
def my_stdev(src, length):
    avg = sma(src, length)
    sumOfSquareDeviations = 0.0
    for i in range(0, length - 1):
        sum = SUM(prev(src,i), -avg)
        sumOfSquareDeviations = sumOfSquareDeviations + sum * sum

    stdev = sqrt(sumOfSquareDeviations / length)
    return stdev
plot(my_stdev(close, 5))
返回值
标准差
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
sum
sum函数返回x的最后y值的滑动综合。
sum(source, length) → series[float]
plot(sum(close,10))
返回值
过去y线的x总和。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
hma
hma函数返回船体移动平均线HMA。
hma(source, length) → series[float]
src = input(defval=close, type="source", title="Source")
length = input(defval=9, type="int", title="Length")
hmaBuildIn = hma(src, length)
plot(hmaBuildIn, title="Hull MA", color="#674EA7")
返回值
返回 '​​length' 柱的 'source' 的移动平均线Hull Moving Average。
参数
source (series)待执行的系列值。
length (integer) K线数量(长度).
na
如为NaN,则测试价值。
na(x) → boolean
返回值
如果x非有效数字,则为true(x为NaN),否则为false。
nz
以系列中的零(或指定数)替换NaN值。
nz(x, y)
返回值
两个参数版本:如果是有效(非NaN)数字,则返回x,否则y
一个参数版本:如果为有效(非NaN)号码,则返回x,否则为0
参数
x (series) 待执行的系列值。
y (float)将代替x系列中所有NaN值插入的值。
color
功能颜色将指定透明度应用于给定的颜色。
color(color, transp) → color
plot(close-open,color=color("red",60))
返回值
有特定透明度的颜色。
参数
color (color)
transp (integer) 可用的值是从0(不透明)到100(不可见)
fixnan
对于给定的系列,将NaN值替换为先前的非NaN值。
fixnan(x) → series
返回值
无na间隙的系列。
参数
x (series)
abs
若 x>=0,x 的绝对值为 x,否则为 -x。
abs(x) → float
返回值
x的绝对值
acos
acos函数返回数字的反余弦(以弧度表示),如cos(acos(y)) = y 在 y 范围内 [-1, 1]。
acos(x) → float
返回值
反余弦值。如果y超出范围[-1,1],返回角度在[0,Pi]或na的范围内。
asin
若asin函数返回数字的反正弦(以弧度表示),正弦(asin(y)) = y 在 y 范围内[-1, 1]。
asin(x) → float
返回值
反正弦值。如果y超出范围[-1,1],返回角度在[-Pi / 2,Pi / 2]或na的范围内。
atan
atan函数返回数字的反正切(以弧度表示),tan(atan(y)) = 任何 y 中的 y。
atan(x) → float
返回值
反正切值; 返回角度在[-Pi / 2,Pi / 2]的范围内。
cos
cos函数返回角度的三角余弦。
cos(x) → float
返回值
角的三角余弦。
cum
x的累积(总数)总和。 换句话说,这是x的所有元素总和。
cum(x) → float
plot(cum(close))
返回值
系列总和。
exp
x的exp函数是e ^ x,其中x是参数,e是欧拉数。
exp(x) → float
result = exp(100)
print(result)   # result = 22026.465794806718
返回值
一个代表e ^ x的数字
sqrt
任何x> = 0的平方根是唯一的y> = 0,如y ^ 2 = x
sqrt(x) → float
result = sqrt(100)
print(result)   # result = 10
返回值
x的平方根
floor
x 舍去小数
floor(x) → float
result = ceil(100.2)
print(result)   # result = 100
返回值
x 舍去小数 的整数
ceil
向上取整函数返回大于或等于参数的最小(最接近负无穷)整数
ceil(x) → float
result = ceil(100.2)
print(result)   # result = 101
返回值
小于或等于给定数字的最小整数
round
round函数返回舍入到最近整数的参数值,并将其舍入。
round(x) → float
result = round(100.2)
print(result)   # result = 100
返回值
舍入到最近整数的参数的值
log
任何x> 0自然对数都是唯一的“y”,例如e ^ y = x
log(x) → float
result = log(100)
print(result)   #4.605170185988092
返回值
x的自然对数。
max
返回多个值中最大的一个
max(x1, x2) -> float
result = max(close,open)
plot(result)
返回值
多个给定值中最大的。
min
返回多个值中最小的一个
min(x1, x2) -> float
result = min(close,open)
plot(result)
返回值
多个给定值中最小的。
avg
计算所有系列的平均值(对应元素)。
avg(x1, x2, a, b) -> float
result = avg(close,open)
plot(result)
返回值
平均
sign
如果x为零,则x的符号(正负号函数)为0,如果x大于零,则为1.0,如果x小于零,则为-1.0。
sign(x) -> float
返回值
参数的标志
barssince
条件为true时,barssince函数计算k线数量。
barssince(condition) → series[integer]
# get number of bars since last green bar
barssince(close >= open)
返回值
如状况为true的k线数目。
dmi
dmi函数返回动向指数DMI。
dmi(diLength, adxSmoothing) → (series[float], series[float], series[float])
返回值
三个DMI系列的元组:上升指标(+ DI),下降指标(-DI)和平均趋向指数(ADX)。
参数
diLength (integer)DI Period。
adxSmoothing (integer)ADX平滑周期
pivothigh
此函数返回枢轴高点的价格。 如果没有枢轴高点,则返回“NaN”。
pivothigh(source, leftbars, rightbars) → series[float]
leftBars = input(2,type="int")
rightBars=input(2,type="int")
ph = pivothigh(high,leftBars, rightBars)
plot(ph, style="cross", linewidth=3, color= "red", offset=-rightBars)
返回值
此点的价格或者 'NaN'.
参数
source (series)数据系列计算值
leftbars (series)左力量。
rightbars (series)右长度。
pivotlow
此函数返回枢轴低点的价格。 如果没有枢轴低点,则返回“NaN”。
pivotlow(source, leftbars, rightbars) → series[float]
leftBars = input(2,type="int")
rightBars=input(2,type="int")
ph = pivotlow(high,leftBars, rightBars)
plot(ph, style="cross", linewidth=3, color= "red", offset=-rightBars)
返回值
此点的价格或者 'NaN'.
参数
source (series)数据系列计算值
leftbars (series)左力量。
rightbars (series)右长度。
macd
MACD(平滑异同平均线)。 它应该揭示股票价格趋势的实力、方向、动量和持续时间的变化。。
macd(source, fastlen, slowlen, siglen) → (series[float], series[float], series[float])
(macdLine, signalLine, histLine) = macd(close, 12, 26, 9)
plot(macdLine, color="blue")
plot(signalLine, color="orange")
plot(histLine, color=histLine>0?"green":"red", style="histogram")
返回值
三个MACD系列的元组:MACD线,信号线和直方图线。
参数
source (series)待执行的系列值。
lfastlen (integer)快线参数
slowlen (integer) 慢长度参数
siglen (integer)信号长度参数
stoch
随机指标。计算方程:100 * (close - lowest(low, length)) / (highest(high, length) - lowest(low, length))
stoch(source, high, low, length) → series[float]
plot(stoch(close, high, low, 10))
返回值
随机
参数
source (series)源系列
lfastlen (integer)高系列
slowlen (integer) 低系列
siglen (integer)长度(K线数量)
valuewhen
当最近出现的第n个条件为true时,则源序列值。
valuewhen(condition, source, occurrence) → series[float]
slow = sma(close, 7)
fast = sma(close, 14)
# get value of close on second cross occurrence
valuewhen(cross(slow, fast), close, 1)
返回值
情况为true时的源值
linreg
线性回归曲线。最符合用户指定时间区间内价格的曲线。 使用最小二乘法计算。该函数结果使用以下公式计算:linreg = intercept + slope *(length - 1 - offset),其中length是y参数,offset是z参数,intercept和slope是用源系列最小二乘法计算的值 (x参数)。
linreg(source, length, offset) → series[float]
plot(linreg(open , 10, 10))
返回值
线性回归曲线
参数
source (series)源系列
length (integer)长度.
offset (integer) 偏移
sar
抛物线转向(抛物线停止和反向)是J. Welles Wilder, Jr.设计的方法,以找出交易市场价格方向的潜在逆转。
sar(start, inc, max) → series[float]
plot(sar(0.2, 0.2, .2), style="cross", linewidth=3)
返回值
抛物线转向指标。
参数
start (float)开始。
inc (float)增加
max (float) 最大
atr
函数ATR(真实波动幅度均值)返回真实范围的RMA。真实波动幅度是max(high - low, abs(high - close[1]), abs(low - close[1]))
atr(length) → series[float]
plot(atr(14))

def my_atr(length):
    trueRange = na(prev(high,1))? high-low : max(max(high - low, abs(high - prev(close,1))), abs(low - prev(close,1)))
    return rma(trueRange, length)

plot(my_atr(14))
返回值
真实波动幅度均值(ATR)
参数
length (integer)长度(K线数量)
alma
Arnaud Legoux移动平均线。 它使用高斯分布作为移动平均值的权重。
alma(series, length, offset, sigma) → series[float]
plot(alma(close, 9, 0.85, 6))

# same on alma, but much less efficient
def my_alma(series, windowsize, offset, sigma):
    m = floor(offset * (windowsize - 1))
    s = windowsize / sigma
    norm = 0.0
    sum = 0.0
    for i in range(0,windowsize - 1):
        weight = exp(-1 * ((i - m)** 2) / (2 * (s**2)))
        norm = norm + weight
        sum = sum + prev(series,windowsize - i - 1) * weight
    return sum / norm
plot(my_alma(close, 9, 0.85, 6))
返回值
Arnaud Legoux移动平均线
参数
series (series)待执行的系列值。
length (integer)K线数量(长度).
offset (float)控制平滑度(更接近1)和响应性(更接近0)之间的权衡。
sigma (float) 改变ALMA的平滑度。Sigma越大,ALMA越平滑。
dayofweek
dayofweek(time) → series
plot(dayofweek(time))
返回值
提供UNIX时间的每周日期(交换时区)。
参数
time (series) 以毫秒为单位的unix时间。
dayofmonth
dayofmonth(time) → series
plot(dayofmonth(time))
返回值
提供UNIX时间的每周日期(交换时区)。
参数
time (series) 以毫秒为单位的unix时间。
cross
cross(x, y) → series[bool]
ema1 = ema(close,20)
ema2 = ema(close, 10)

plot(cross(ema1,ema2)?-1:1, color="red",style="histogram")
返回值
如果两个系列相互交叉,则为1,否则为0。
参数
x (series)
y (series)
crossunder
如果`x`的值小于`y`,则`x`系列被定义为跨越`y`系列以下,以及`x`的值大于紧接当前k线上的`y`的值。
crossunder(x, y) → series[bool]
ema1 = ema(close,20)
ema2 = ema(close, 10)

plot(crossunder(ema1,ema2)?-1:1, color="red",style="histogram")
返回值
如果“x”向下越过“y”,则为true,否则为false。
参数
x (series) 数据系列`x`。
y (series) 数据系列`y`。
crossover
如果`x`的值大于`y`,则`x`系列被定义为跨越`y`系列,以及`x`的值小于紧接当前k线上的`y`的值。
crossover(x, y) → series[bool]
ema1 = ema(close,20)
ema2 = ema(close, 10)

plot(crossover(ema1,ema2)?-1:1, color="red",style="histogram")
返回值
如果“x”越过“y”则为true,否则为false
参数
x (series) 数据系列`x`。
y (series) 数据系列`y`。