alexgrover

Minimum Variance SMA

Return the value of a simple moving average with a period within the range min to max such that the variance of the same period is the smallest available.

Since the smallest variance is often the one with the smallest period, a penalty setting is introduced, and allows the indicator to return moving averages values with higher periods more often, with higher penalty values returning moving averages values with higher periods.

Because variances with smaller periods are more reactive than ones with higher periods, it is common for the indicator to return the value of an SMA of a higher period during more volatile market, this can be seen on the image below:


here variances from period 10 to 15 are plotted, a blueish color represents a higher period, note how they are the smallest ones when fluctuations are more volatile.


Indicator with min = 50, max = 200 and penalty = 0.5


In blue the indicator with penalty = 0, in red with penalty = 1, with both min = 50 and max = 200.

On The Script

The script minimize Var(i)/p with i ∈ (min,max) and p = i^penalty, this is done by computing the variance for each period i and keeping the smallest one currently in the loop, if we get a variance value smaller than the previously one found we calculate the value of an SMA with period i, as such the script deal with brute force optimization.

For our use case it is not possible to use the built-in sma and variance functions within a loop, as such we use cumulative forms for both functions.

Check out the indicators we are making at luxalgo: www.tradingview.com/u/LuxAlgo/
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?