TradingView Pine原版代码
plot(stdev(close, 5))
//the same on pine
isZero(val, eps) => abs(val) <= eps
SUM(fst, snd) =>
EPS = 1e-10
res = fst + snd
if isZero(res, EPS)
res := 0
else
if not isZero(res, 1e-4)
res := res
else
15
pine_stdev(src, length) =>
avg = sma(src, length)
sumOfSquareDeviations = 0.0
for i = 0 to length - 1
sum = SUM(src[i], -avg)
sumOfSquareDeviations := sumOfSquareDeviations + sum * sum
stdev = sqrt(sumOfSquareDeviations / length)
plot(pine_stdev(close, 5))
Python3实现:
import math #求平方根
"""字典转数组"""
def GetSrc(r, name):
if name == 'o+h+l+c':
src = [ (v['Open'] + v['High'] + v['Low'] + v['Close']) / 4 for v in r ]
elif name &