求威廉指标的js轮子

Author: 八维, Created: 2021-10-23 08:02:58, Updated:

如题,社区策略文库都找不到类似威廉指标的js处理轮子。


More

ChaoZhang function arrayMax(array) { return Math.max.apply( Math, array.filter(function (n) { return !isNaN(n); }) ); } function arrayMin(array) { return Math.min.apply( Math, array.filter(function (n) { return !isNaN(n); }) ); } function WILLR(highs, lows, closes, lookback) { var willr = [], highest_high, lowest_low, curr_close, i; // computing only if highs and lows arrays are of equal length if (highs.length == lows.length && highs.length >= lookback) { /* * Willams %R exists only for the values which have atleast "lookback" values * so we iterate till ((length )-lookback)to calculate Willams %R */ var limit = highs.length - lookback; for (i = limit; i >= 0; i--) { highest_high = arrayMax(highs.slice(i, i + lookback)); lowest_low = arrayMin(lows.slice(i, i + lookback)); curr_close = closes[i]; willr[i] = ((highest_high - curr_close) / (highest_high - lowest_low)) * -100; } } return willr; } function main() { var highs = [127.01, 127.62, 126.59, 127.35, 128.17, 128.43, 127.37, 126.42, 126.9, 126.85, 125.65, 125.72, 127.16, 127.72, 127.69, 128.22].reverse(), lows = [125.36, 126.16, 124.93, 126.09, 126.82, 126.48, 126.03, 124.83, 126.39, 125.72, 124.56, 124.57, 125.07, 126.86, 126.63, 126.8].reverse(), close = [127.29, 127.18, 128.01].reverse(); var willr = WILLR(highs, lows, close, 14); Log(willr); }

ChaoZhang function main(){ var records = exchange.GetRecords(); Log(talib.WILLR(records, 7)); }

八维 感激,谢谢大大。