如何将松树脚本转换为python

时间:2021-02-25 06:51:19

标签: python pine-script

Pine 脚本示例如下:

length = input(20, title="BB Length")
mult = input(2.0,title="BB MultFactor")
lengthKC=input(20, title="KC Length")
multKC = input(1.5, title="KC MultFactor")

useTrueRange = input(true, title="Use TrueRange (KC)", type=bool)

// Calculate BB
source = close
basis = sma(source, length)
dev = multKC * stdev(source, length)
upperBB = basis + dev
lowerBB = basis - dev

// Calculate KC
ma = sma(source, lengthKC)
range = useTrueRange ? tr : (high - low)
rangema = sma(range, lengthKC)
upperKC = ma + rangema * multKC
lowerKC = ma - rangema * multKC

sqzOn  = (lowerBB > lowerKC) and (upperBB < upperKC)
sqzOff = (lowerBB < lowerKC) and (upperBB > upperKC)
noSqz  = (sqzOn == false) and (sqzOff == false)

val = linreg(source  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), 
            lengthKC,0)

bcolor = iff( val > 0, 
            iff( val > nz(val[1]), lime, green),
            iff( val < nz(val[1]), red, maroon))
scolor = noSqz ? blue : sqzOn ? black : gray 
plot(val, color=bcolor, style=histogram, linewidth=4)
plot(0, color=scolor, style=cross, linewidth=2)

我的 Python 代码如下:

#val = linreg(source  -  avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)
high =talib.MAX(np.array(data['high']),20)
low = talib.MIN(np.array(data['low']),20)
hl_avg = np.mean(high,low)
sma20 = talib.SMA(np.array(data['close']), timeperiod=20)
e_avg = np.mean(hl_avg,sma20)
val =  talib.LINEARREG_ANGLE(np.array(data['close'] - e_avg,20,0))

一个问题是func avg如何转换为python ...avg(highest(high, lengthKC)

感谢您的任何提示:)

0 个答案:

没有答案