Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
730 views
in Technique[技术] by (71.8m points)

ta lib - stdev() differences between talib and pine script versions

I'm trying to port a strategy from tradingview (pinescript) to a framework I built in nodejs. My strategy uses breakouts on the Bollinger bands. in my pine script I've implemented the BBs with standard deviation ( basically copying the build-in indicator formula) as follows:

length = input(200, "BB Len", minval=1)
mult = input(1.5, "BB STD", minval=0.001, maxval=50, type=input.float)


basis = sma(src, length)
dev = mult * stdev(src, length)

upper1 = basis + dev
lower1 = basis - dev

Based on this a problem arose because of two reasons:

First reason.

As I can see in the explain of the STDDEV function in talib, there are three parameters instead of the two you get in the pine script version:

  1. inReal: the data serie
  2. optInNbDev: Deviations, with a default value of 1
  3. optInTimePeriod: Time Period, with a default value of 5 ( pine script does not have this )

Second reason.

As I noticed in the pine script reference in tradingview, it says that the stdev function is "a biased estimation of standard deviation.". I couldn't find any specific on this topic in the talib's doc, but I am assuming that they are applying the non-biased formula, based on some comments I found googleing here and there.

Based on this, do you think there would be a way to precisely replicate the tradingview behaviour using ta-lib?

question from:https://stackoverflow.com/questions/65901574/stdev-differences-between-talib-and-pine-script-versions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The advantage of ta-lib as opensource is that you can look at sources and see what exactly it does. The stdev function sources are here and it refers to TA_VAR() function, which sources are here.

According to my understanding TA-Lib's stddev is a rolling biased stddev of period optInTimePeriod that is multiplied by optInNbDev. So this function results in an array of stdevs made for each input array value considering subarray with length of optInTimePeriod.

There is no pine's stddev sources to compare, but it looks like you shall use length as optInTimePeriod and mult as optInNbDev (or leave it 1 and multiply values later). And expect the same results.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...