{"id":379693,"date":"2024-06-25T03:29:18","date_gmt":"2024-06-25T03:29:18","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=379693"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=379693","title":{"rendered":"<span>\u041a\u0440\u0430\u0442\u043a\u043e \u043f\u0440\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b RSI \u0438 Stochastic<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w780q1\/getpro\/habr\/upload_files\/c96\/310\/637\/c96310637e7a811f1a517267e4197341.jpg\" width=\"1280\" height=\"720\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c96\/310\/637\/c96310637e7a811f1a517267e4197341.jpg\" data-blurred=\"true\"\/><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em> <\/p>\n<p><strong>\u041e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b<\/strong> \u2014 \u044d\u0442\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043b\u0435\u0431\u043b\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430, \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0442 0 \u0434\u043e 100, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u044b\u043d\u043a\u0430. <\/p>\n<p>\u041e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0443\u0442. <\/p>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 \u0441 \u0435\u0433\u043e \u0446\u0435\u043d\u043e\u0432\u044b\u043c\u0438 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 \u0437\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0446\u0435\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u0432\u0435\u0440\u0445\u043d\u0435\u043c\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0435\u0440\u0438\u043e\u0434, \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c. \u0418 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0435\u0441\u043b\u0438 \u0446\u0435\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443, \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u041e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0440\u044b\u043d\u043e\u0447\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0440\u0435\u043d\u0434\u043e\u0432\u044b\u0435 \u0438 \u0431\u043e\u043a\u043e\u0432\u044b\u0435 \u0440\u044b\u043d\u043a\u0438. \u0412 \u0442\u0440\u0435\u043d\u0434\u043e\u0432\u044b\u0445 \u0440\u044b\u043d\u043a\u0430\u0445 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430, \u0430 \u0432 \u0431\u043e\u043a\u043e\u0432\u044b\u0445 \u2014 \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0430.<\/p>\n<h2>Relative Strength Index (RSI)<\/h2>\n<p>RSI \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0414\u0436. \u0423\u044d\u043b\u043b\u0441\u043e\u043c \u0423\u0430\u0439\u043b\u0434\u0435\u0440\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0435\u0433\u043e \u043a\u043d\u0438\u0433\u0435 &#171;<em>New Concepts in Technical Trading Systems<\/em>&#187; \u0432 1978 \u0433\u043e\u0434\u0443. RSI \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u043e\u0432\u044b\u0445 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439 \u0430\u043a\u0442\u0438\u0432\u0430, \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u043d \u043a\u043e\u043b\u0435\u0431\u043b\u0435\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0442 0 \u0434\u043e 100 \u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0442\u0440\u0435\u0439\u0434\u0435\u0440\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0430\u043a\u0442\u0438\u0432\u043e\u0432.<\/p>\n<p>\u0420\u0430\u0441\u0447\u0435\u0442 RSI \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0434\u0432\u0430 \u0448\u0430\u0433\u0430:<\/p>\n<ol>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u043b\u044b (RS):<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\" [ RS = \\frac{\\text{\u0421\u0440\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0437\u0430 \u043f\u0435\u0440\u0438\u043e\u0434}}{\\text{\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u043f\u043e\u0442\u0435\u0440\u044f \u0437\u0430 \u043f\u0435\u0440\u0438\u043e\u0434}} ]\" alt=\" [ RS = \\frac{\\text{\u0421\u0440\u0435\u0434\u043d\u0438\u0439 \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u0437\u0430 \u043f\u0435\u0440\u0438\u043e\u0434}}{\\text{\u0421\u0440\u0435\u0434\u043d\u044f\u044f \u043f\u043e\u0442\u0435\u0440\u044f \u0437\u0430 \u043f\u0435\u0440\u0438\u043e\u0434}} ]\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/860\/2a8\/a02\/8602a8a0278357807c45804f6af39ae8.svg\" width=\"286\" height=\"54\"\/><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u0430\u043c\u043e\u0433\u043e RSI:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\" RSI = 100 - \\left( \\frac{100}{1 + RS} \\right) \" alt=\" RSI = 100 - \\left( \\frac{100}{1 + RS} \\right) \" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4c5\/598\/955\/4c55989550ed54503101ca363c967504.svg\" width=\"211\" height=\"49\"\/><\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 RSI \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 14 \u0434\u043d\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0430\u043a\u0442\u0438\u0432 \u0437\u0430\u043a\u0440\u044b\u043b\u0441\u044f \u0432\u044b\u0448\u0435 \u0437\u0430 7 \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 14 \u0434\u043d\u0435\u0439 \u0441 \u0441\u0440\u0435\u0434\u043d\u0438\u043c \u043f\u0440\u0438\u0440\u043e\u0441\u0442\u043e\u043c 1%, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 7 \u0434\u043d\u0435\u0439 \u0437\u0430\u043a\u0440\u044b\u043b\u0438\u0441\u044c \u043d\u0438\u0436\u0435 \u0441\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u043f\u043e\u0442\u0435\u0440\u0435\u0439 0.8%, \u0442\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 RS \u0431\u0443\u0434\u0435\u0442 1.25 (1% \/ 0.8%). \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f RSI.<\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f RSI \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p><strong>\u0412\u044b\u0448\u0435 70<\/strong> \u2014 \u0430\u043a\u0442\u0438\u0432 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u044f \u0432\u043d\u0438\u0437.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0438\u0436\u0435 30<\/strong> \u2014 \u0430\u043a\u0442\u0438\u0432 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u043e\u0441\u0442 \u0446\u0435\u043d\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>RSI \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0442\u0440\u0435\u0439\u0434\u0435\u0440\u0430\u043c \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u044b\u0435 \u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0440\u044b\u043d\u043a\u0430, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0430\u0445 \u0442\u0440\u0435\u043d\u0434\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 RSI \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 70, \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u0438. \u041d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0435\u0441\u043b\u0438 RSI \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0438\u0436\u0435 30, \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u043e\u0441\u0442\u0443 \u0446\u0435\u043d\u044b.<\/p>\n<p><strong>\u0414\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u0438 RSI<\/strong> \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442, \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u043d\u0434 \u0446\u0435\u043d \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0442\u0440\u0435\u043d\u0434 \u0441\u0430\u043c\u043e\u0433\u043e RSI \u0440\u0430\u0441\u0445\u043e\u0434\u044f\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0441\u043b\u0430\u0431\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442.<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u044b\u0447\u044c\u044f \u0434\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u044f<\/strong> \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0430 RSI \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c. \u042d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043e\u0441\u043b\u0430\u0431\u043b\u0435\u043d\u0438\u0435 \u043d\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0432\u0432\u0435\u0440\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0434\u0432\u0435\u0436\u044c\u044f \u0434\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u044f<\/strong> \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u0430 RSI \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u0438\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c. \u042d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e \u0441\u043b\u0430\u0431\u043e\u0441\u0442\u0438 \u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u043c \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0435 \u0432\u043d\u0438\u0437.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 RSI<\/h4>\n<p><strong>Python<\/strong><\/p>\n<pre><code class=\"python\">import pandas as pd  def calculate_rsi(data, period=14):     delta = data['Close'].diff()     gain = (delta.where(delta > 0, 0)).fillna(0)     loss = (-delta.where(delta &lt; 0, 0)).fillna(0)      avg_gain = gain.rolling(window=period).mean()     avg_loss = loss.rolling(window=period).mean()      rs = avg_gain \/ avg_loss     rsi = 100 - (100 \/ (1 + rs))     return rsi  # Example usage data = pd.DataFrame({     'Close': [45.15, 46.23, 45.56, 46.33, 45.86, 46.71, 47.24, 46.69, 47.28, 47.88, 48.07, 47.86, 47.33, 47.59] })  data['RSI'] = calculate_rsi(data) print(data) <\/code><\/pre>\n<p><strong>JavaScript<\/strong><\/p>\n<pre><code class=\"javascript\">function calculateRSI(closes, period = 14) {     let gains = [];     let losses = [];      for (let i = 1; i &lt; closes.length; i++) {         let change = closes[i] - closes[i - 1];         gains.push(change > 0 ? change : 0);         losses.push(change &lt; 0 ? -change : 0);     }      let avgGain = gains.slice(0, period).reduce((a, b) => a + b, 0) \/ period;     let avgLoss = losses.slice(0, period).reduce((a, b) => a + b, 0) \/ period;     let rs = avgGain \/ avgLoss;     let rsi = [100 - (100 \/ (1 + rs))];      for (let i = period; i &lt; gains.length; i++) {         avgGain = (avgGain * (period - 1) + gains[i]) \/ period;         avgLoss = (avgLoss * (period - 1) + losses[i]) \/ period;         rs = avgGain \/ avgLoss;         rsi.push(100 - (100 \/ (1 + rs)));     }      return rsi; }  \/\/ example let closes = [45.15, 46.23, 45.56, 46.33, 45.86, 46.71, 47.24, 46.69, 47.28, 47.88, 48.07, 47.86, 47.33, 47.59]; console.log(calculateRSI(closes));<\/code><\/pre>\n<p>R<\/p>\n<pre><code class=\"r\">calculate_rsi &lt;- function(prices, n = 14) {     deltas &lt;- diff(prices)     seed &lt;- deltas[1:n]     up &lt;- seed[seed >= 0]     down &lt;- -seed[seed &lt; 0]     up[is.na(up)] &lt;- 0     down[is.na(down)] &lt;- 0      avg_gain &lt;- sum(up) \/ n     avg_loss &lt;- sum(down) \/ n     rs &lt;- avg_gain \/ avg_loss     rsi &lt;- 100 - (100 \/ (1 + rs))      rsi_values &lt;- c(rep(NA, n), rsi)          for (i in (n+1):length(deltas)) {         delta &lt;- deltas[i]         gain &lt;- ifelse(delta > 0, delta, 0)         loss &lt;- ifelse(delta &lt; 0, -delta, 0)          avg_gain &lt;- (avg_gain * (n - 1) + gain) \/ n         avg_loss &lt;- (avg_loss * (n - 1) + loss) \/ n         rs &lt;- avg_gain \/ avg_loss         rsi &lt;- 100 - (100 \/ (1 + rs))          rsi_values &lt;- c(rsi_values, rsi)     }      return(rsi_values) }  # example prices &lt;- c(45.15, 46.23, 45.56, 46.33, 45.86, 46.71, 47.24, 46.69, 47.28, 47.88, 48.07, 47.86, 47.33, 47.59) rsi &lt;- calculate_rsi(prices) print(rsi)<\/code><\/pre>\n<h2>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440  <\/h2>\n<p>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0414\u0436\u043e\u0440\u0434\u0436\u0435\u043c \u041b\u0435\u0439\u043d\u043e\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 1950-\u0445 \u0433\u043e\u0434\u043e\u0432. \u042d\u0442\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043a \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443 \u0446\u0435\u043d \u0437\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u0442\u0440\u0435\u043d\u0434\u0435 \u0446\u0435\u043d\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0435 \u043a \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430, \u0430 \u0432 \u043d\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u0442\u0440\u0435\u043d\u0434\u0435 \u2014 \u0431\u043b\u0438\u0436\u0435 \u043a \u043d\u0438\u0436\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435. <\/p>\n<p>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432: \u043b\u0438\u043d\u0438\u0438 %K \u0438 \u043b\u0438\u043d\u0438\u0438 %D.<\/p>\n<ol>\n<li>\n<p><strong>%K \u043b\u0438\u043d\u0438\u044f<\/strong> \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"K=(HN\u200b\u2212LN\u200b)(C\u2212LN\u200b)\u200b\u00d710\" alt=\"K=(HN\u200b\u2212LN\u200b)(C\u2212LN\u200b)\u200b\u00d710\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/075\/171\/0be\/0751710be3608ec8105ddd0c838a9f3f.svg\" width=\"268\" height=\"22\"\/><br \/> \u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"C\" alt=\"C\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/083\/ee2\/2a3\/083ee22a3a6b76c59b9c94ad2301f259.svg\" width=\"15\" height=\"17\"\/> \u2014 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0446\u0435\u043d\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f,<\/p>\n<\/li>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"L_{N}\" alt=\"L_{N}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/83e\/374\/4fc\/83e3744fcadaccde080dccc5c2f5ae2e.svg\" width=\"27\" height=\"19\"\/> \u2014 \u0441\u0430\u043c\u0430\u044f \u043d\u0438\u0437\u043a\u0430\u044f \u0446\u0435\u043d\u0430 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 N \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432,<\/p>\n<\/li>\n<li>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"H_{N}\" alt=\"H_{N}\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/2da\/892\/469\/2da892469ea79e13d332d8021e03616d.svg\" width=\"30\" height=\"19\"\/> \u2014 \u0441\u0430\u043c\u0430\u044f \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0446\u0435\u043d\u0430 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 N \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>%D \u043b\u0438\u043d\u0438\u044f<\/strong> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043b\u0438\u043d\u0438\u0438 %K \u0437\u0430 \u0442\u0440\u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0430:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"formula inline\" source=\"D = \\text{SMA}_{3}(K)\" alt=\"D = \\text{SMA}_{3}(K)\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/47b\/577\/3ce\/47b5773ce5c35972ce6c4c65031a8ac4.svg\" width=\"125\" height=\"22\"\/><\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432 14 \u0434\u043d\u0435\u0439 \u0434\u043b\u044f %K \u0438 3 \u0434\u043d\u044f \u0434\u043b\u044f %D, \u043d\u043e \u044d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u043a\u043e\u043b\u0435\u0431\u043b\u044e\u0442\u0441\u044f \u043e\u0442 0 \u0434\u043e 100. \u0423\u0440\u043e\u0432\u043d\u0438 \u0432\u044b\u0448\u0435 80 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430, \u0430 \u0443\u0440\u043e\u0432\u043d\u0438 \u043d\u0438\u0436\u0435 20 \u2014 \u043d\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<ul>\n<li>\n<p><strong>\u041f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c<\/strong>: \u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 80, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0432\u043d\u0438\u0437. \u0422\u0440\u0435\u0439\u0434\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u044d\u0442\u043e \u043a\u0430\u043a \u0441\u0438\u0433\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u0436\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c<\/strong>:\u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0438\u0436\u0435 20, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0432\u0432\u0435\u0440\u0445. \u042d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u043e\u043a\u0443\u043f\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u0445\u043e\u0440\u043e\u0448 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0431\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0440\u044b\u043d\u043a\u0430, \u0433\u0434\u0435 \u043e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u044f. \u0412 \u0442\u0440\u0435\u043d\u0434\u043e\u0432\u044b\u0445 \u0440\u044b\u043d\u043a\u0430\u0445 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u043e\u043d\u0435 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f. \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432.<\/p>\n<p>\u0414\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u0438 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0441\u0441\u0447\u0435\u0442\u043e\u0432 \u0432 \u043a\u043e\u0434\u0435<\/h4>\n<p><strong>Python<\/strong><\/p>\n<pre><code class=\"python\">import pandas as pd  def calculate_stochastic_oscillator(data, k_period=14, d_period=3):     low_min = data['Low'].rolling(window=k_period).min()     high_max = data['High'].rolling(window=k_period).max()      data['%K'] = 100 * ((data['Close'] - low_min) \/ (high_max - low_min))     data['%D'] = data['%K'].rolling(window=d_period).mean()     return data  # example data = pd.DataFrame({     'High': [127.01, 128.48, 128.43, 128.72, 128.22, 128.43, 128.72, 128.21, 128.35, 128.75, 128.37, 128.57, 128.88, 128.78],     'Low': [125.36, 126.41, 126.74, 126.82, 126.32, 126.74, 126.82, 126.41, 126.35, 126.82, 126.41, 126.72, 126.92, 126.72],     'Close': [126.45, 127.98, 127.98, 128.43, 127.38, 127.68, 128.43, 127.88, 127.88, 128.28, 127.78, 128.15, 128.43, 128.23] })  data = calculate_stochastic_oscillator(data) print(data[['%K', '%D']])<\/code><\/pre>\n<p><strong>JavaScript<\/strong><\/p>\n<pre><code class=\"javascript\">function calculateStochasticOscillator(highs, lows, closes, kPeriod = 14, dPeriod = 3) {     let stochastics = [];     let percentK = [];     let percentD = [];      for (let i = 0; i &lt; closes.length; i++) {         if (i >= kPeriod - 1) {             let highMax = Math.max(...highs.slice(i - kPeriod + 1, i + 1));             let lowMin = Math.min(...lows.slice(i - kPeriod + 1, i + 1));             let k = ((closes[i] - lowMin) \/ (highMax - lowMin)) * 100;             percentK.push(k);              if (percentK.length >= dPeriod) {                 let d = percentK.slice(-dPeriod).reduce((a, b) => a + b) \/ dPeriod;                 percentD.push(d);             } else {                 percentD.push(null);             }         } else {             percentK.push(null);             percentD.push(null);         }          stochastics.push({             K: percentK[percentK.length - 1],             D: percentD[percentD.length - 1]         });     }      return stochastics; }  \/\/ example let highs = [127.01, 128.48, 128.43, 128.72, 128.22, 128.43, 128.72, 128.21, 128.35, 128.75, 128.37, 128.57, 128.88, 128.78]; let lows = [125.36, 126.41, 126.74, 126.82, 126.32, 126.74, 126.82, 126.41, 126.35, 126.82, 126.41, 126.72, 126.92, 126.72]; let closes = [126.45, 127.98, 127.98, 128.43, 127.38, 127.68, 128.43, 127.88, 127.88, 128.28, 127.78, 128.15, 128.43, 128.23];  console.log(calculateStochasticOscillator(highs, lows, closes));<\/code><\/pre>\n<p><strong>R<\/strong><\/p>\n<pre><code class=\"r\">calculate_stochastic &lt;- function(highs, lows, closes, k_period = 14, d_period = 3) {     K &lt;- rep(NA, length(closes))     D &lt;- rep(NA, length(closes))          for (i in seq(k_period, length(closes))) {         high_max &lt;- max(highs[(i - k_period + 1):i])         low_min &lt;- min(lows[(i - k_period + 1):i])         K[i] &lt;- ((closes[i] - low_min) \/ (high_max - low_min)) * 100     }          for (i in seq((k_period + d_period - 1), length(closes))) {         D[i] &lt;- mean(K[(i - d_period + 1):i], na.rm = TRUE)     }          return(data.frame(K = K, D = D)) }  # example highs &lt;- c(127.01, 128.48, 128.43, 128.72, 128.22, 128.43, 128.72, 128.21, 128.35, 128.75, 128.37, 128.57, 128.88, 128.78) lows &lt;- c(125.36, 126.41, 126.74, 126.82, 126.32, 126.74, 126.82, 126.41, 126.35, 126.82, 126.41, 126.72, 126.92, 126.72) closes &lt;- c(126.45, 127.98, 127.98, 128.43, 127.38, 127.68, 128.43, 127.88, 127.88, 128.28, 127.78, 128.15, 128.43, 128.23)  stochastic &lt;- calculate_stochastic(highs, lows, closes) print(stochastic)<\/code><\/pre>\n<hr\/>\n<p>\u041e\u0431\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u044b \u0432 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 RSI \u0438 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0442\u0440\u0435\u043d\u0434\u043e\u0432\u044b\u043c\u0438 \u043b\u0438\u043d\u0438\u044f\u043c\u0438, \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0438\u043c\u0438 \u0441\u0440\u0435\u0434\u043d\u0438\u043c\u0438 \u0438\u043b\u0438 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0438 \u0441\u043e\u043f\u0440\u043e\u0442\u0438\u0432\u043b\u0435\u043d\u0438\u044f \u0447\u0430\u0441\u0442\u043e \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u0442\u043e\u0440\u0433\u043e\u0432\u044b\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438.  <\/p>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u044d\u043a\u0441\u043f\u0435\u0440\u0442\u044b \u0438\u0437 OTUS \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u044e\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043e\u043d\u043b\u0430\u0439\u043d-\u043a\u0443\u0440\u0441\u043e\u0432. <a href=\"https:\/\/otus.pw\/Bh5R\/\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435<\/a>.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/823500\/\"> https:\/\/habr.com\/ru\/articles\/823500\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><\/figure>\n<p><em>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/em> <\/p>\n<p><strong>\u041e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b<\/strong> \u2014 \u044d\u0442\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043b\u0435\u0431\u043b\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430, \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0442 0 \u0434\u043e 100, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0440\u044b\u043d\u043a\u0430. <\/p>\n<p>\u041e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u044b \u043f\u0440\u0435\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u043d\u0434\u043e\u0432 \u0434\u043e \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u044d\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0438\u0437\u043e\u0439\u0434\u0443\u0442. <\/p>\n<p>\u041f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u043e\u0432 \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0438 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430 \u0441 \u0435\u0433\u043e \u0446\u0435\u043d\u043e\u0432\u044b\u043c\u0438 \u0443\u0440\u043e\u0432\u043d\u044f\u043c\u0438 \u0437\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0446\u0435\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u0432\u0435\u0440\u0445\u043d\u0435\u043c\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u043f\u0435\u0440\u0438\u043e\u0434, \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0432\u044b\u0441\u043e\u043a\u0438\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044f \u043d\u0430 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c. \u0418 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0435\u0441\u043b\u0438 \u0446\u0435\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0431\u043b\u0438\u0437\u043a\u043e \u043a \u043d\u0438\u0436\u043d\u0435\u043c\u0443 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443, \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<p>\u041e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0440\u044b\u043d\u043e\u0447\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0442\u0440\u0435\u043d\u0434\u043e\u0432\u044b\u0435 \u0438 \u0431\u043e\u043a\u043e\u0432\u044b\u0435 \u0440\u044b\u043d\u043a\u0438. \u0412 \u0442\u0440\u0435\u043d\u0434\u043e\u0432\u044b\u0445 \u0440\u044b\u043d\u043a\u0430\u0445 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u044b \u043f\u043e\u043c\u043e\u0433\u0430\u044e\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430, \u0430 \u0432 \u0431\u043e\u043a\u043e\u0432\u044b\u0445 \u2014 \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0430.<\/p>\n<h2>Relative Strength Index (RSI)<\/h2>\n<p>RSI \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0414\u0436. \u0423\u044d\u043b\u043b\u0441\u043e\u043c \u0423\u0430\u0439\u043b\u0434\u0435\u0440\u043e\u043c \u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u0432 \u0435\u0433\u043e \u043a\u043d\u0438\u0433\u0435 &#171;<em>New Concepts in Technical Trading Systems<\/em>&#187; \u0432 1978 \u0433\u043e\u0434\u0443. RSI \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0446\u0435\u043d\u043e\u0432\u044b\u0445 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0439 \u0430\u043a\u0442\u0438\u0432\u0430, \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u044f \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438. \u041e\u043d \u043a\u043e\u043b\u0435\u0431\u043b\u0435\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u043e\u0442 0 \u0434\u043e 100 \u0438 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0442\u0440\u0435\u0439\u0434\u0435\u0440\u0430\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u043f\u043e\u043a\u0443\u043f\u043a\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0430\u0436\u0438 \u0430\u043a\u0442\u0438\u0432\u043e\u0432.<\/p>\n<p>\u0420\u0430\u0441\u0447\u0435\u0442 RSI \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0434\u0432\u0430 \u0448\u0430\u0433\u0430:<\/p>\n<ol>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0435\u0442 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u043b\u044b (RS):<\/strong><\/p>\n<p><\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u0420\u0430\u0441\u0447\u0435\u0442 \u0441\u0430\u043c\u043e\u0433\u043e RSI:<\/strong><\/p>\n<p><\/p>\n<\/li>\n<\/ol>\n<p>\u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 RSI \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 14 \u0434\u043d\u0435\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0430\u043a\u0442\u0438\u0432 \u0437\u0430\u043a\u0440\u044b\u043b\u0441\u044f \u0432\u044b\u0448\u0435 \u0437\u0430 7 \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 14 \u0434\u043d\u0435\u0439 \u0441 \u0441\u0440\u0435\u0434\u043d\u0438\u043c \u043f\u0440\u0438\u0440\u043e\u0441\u0442\u043e\u043c 1%, \u0430 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 7 \u0434\u043d\u0435\u0439 \u0437\u0430\u043a\u0440\u044b\u043b\u0438\u0441\u044c \u043d\u0438\u0436\u0435 \u0441\u043e \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u043f\u043e\u0442\u0435\u0440\u0435\u0439 0.8%, \u0442\u043e \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 RS \u0431\u0443\u0434\u0435\u0442 1.25 (1% \/ 0.8%). \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0444\u043e\u0440\u043c\u0443\u043b\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f RSI.<\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f RSI \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0442\u0430\u043a:<\/p>\n<ul>\n<li>\n<p><strong>\u0412\u044b\u0448\u0435 70<\/strong> \u2014 \u0430\u043a\u0442\u0438\u0432 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u0431\u0443\u0434\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u044f \u0432\u043d\u0438\u0437.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0438\u0436\u0435 30<\/strong> \u2014 \u0430\u043a\u0442\u0438\u0432 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f \u0440\u043e\u0441\u0442 \u0446\u0435\u043d\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>RSI \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0442\u0440\u0435\u0439\u0434\u0435\u0440\u0430\u043c \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u044b\u0435 \u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0440\u044b\u043d\u043a\u0430, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0430\u0445 \u0442\u0440\u0435\u043d\u0434\u043e\u0432. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 RSI \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 70, \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0435\u0433\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0446\u0438\u0438. \u041d\u0430\u043e\u0431\u043e\u0440\u043e\u0442, \u0435\u0441\u043b\u0438 RSI \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0438\u0436\u0435 30, \u044d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0440\u043e\u0441\u0442\u0443 \u0446\u0435\u043d\u044b.<\/p>\n<p><strong>\u0414\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u0438 RSI<\/strong> \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u044f\u0442, \u043a\u043e\u0433\u0434\u0430 \u0442\u0440\u0435\u043d\u0434 \u0446\u0435\u043d \u0430\u043a\u0442\u0438\u0432\u0430 \u0438 \u0442\u0440\u0435\u043d\u0434 \u0441\u0430\u043c\u043e\u0433\u043e RSI \u0440\u0430\u0441\u0445\u043e\u0434\u044f\u0442\u0441\u044f, \u0447\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u043e\u0441\u043b\u0430\u0431\u043b\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442.<\/p>\n<ul>\n<li>\n<p><strong>\u0411\u044b\u0447\u044c\u044f \u0434\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u044f<\/strong> \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c, \u0430 RSI \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u0438\u0439 \u043c\u0438\u043d\u0438\u043c\u0443\u043c. \u042d\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u043e\u0441\u043b\u0430\u0431\u043b\u0435\u043d\u0438\u0435 \u043d\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0432\u0432\u0435\u0440\u0445.<\/p>\n<\/li>\n<li>\n<p><strong>\u041c\u0435\u0434\u0432\u0435\u0436\u044c\u044f \u0434\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u044f<\/strong> \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043d\u0430 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u0430 RSI \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u0438\u0439 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c. \u042d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e \u0441\u043b\u0430\u0431\u043e\u0441\u0442\u0438 \u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0442\u0440\u0435\u043d\u0434\u0430 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u043c \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442\u0435 \u0432\u043d\u0438\u0437.<\/p>\n<\/li>\n<\/ul>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0435\u0442\u0430 RSI<\/h4>\n<p><strong>Python<\/strong><\/p>\n<pre><code class=\"python\">import pandas as pd  def calculate_rsi(data, period=14):     delta = data['Close'].diff()     gain = (delta.where(delta > 0, 0)).fillna(0)     loss = (-delta.where(delta &lt; 0, 0)).fillna(0)      avg_gain = gain.rolling(window=period).mean()     avg_loss = loss.rolling(window=period).mean()      rs = avg_gain \/ avg_loss     rsi = 100 - (100 \/ (1 + rs))     return rsi  # Example usage data = pd.DataFrame({     'Close': [45.15, 46.23, 45.56, 46.33, 45.86, 46.71, 47.24, 46.69, 47.28, 47.88, 48.07, 47.86, 47.33, 47.59] })  data['RSI'] = calculate_rsi(data) print(data) <\/code><\/pre>\n<p><strong>JavaScript<\/strong><\/p>\n<pre><code class=\"javascript\">function calculateRSI(closes, period = 14) {     let gains = [];     let losses = [];      for (let i = 1; i &lt; closes.length; i++) {         let change = closes[i] - closes[i - 1];         gains.push(change > 0 ? change : 0);         losses.push(change &lt; 0 ? -change : 0);     }      let avgGain = gains.slice(0, period).reduce((a, b) => a + b, 0) \/ period;     let avgLoss = losses.slice(0, period).reduce((a, b) => a + b, 0) \/ period;     let rs = avgGain \/ avgLoss;     let rsi = [100 - (100 \/ (1 + rs))];      for (let i = period; i &lt; gains.length; i++) {         avgGain = (avgGain * (period - 1) + gains[i]) \/ period;         avgLoss = (avgLoss * (period - 1) + losses[i]) \/ period;         rs = avgGain \/ avgLoss;         rsi.push(100 - (100 \/ (1 + rs)));     }      return rsi; }  \/\/ example let closes = [45.15, 46.23, 45.56, 46.33, 45.86, 46.71, 47.24, 46.69, 47.28, 47.88, 48.07, 47.86, 47.33, 47.59]; console.log(calculateRSI(closes));<\/code><\/pre>\n<p>R<\/p>\n<pre><code class=\"r\">calculate_rsi &lt;- function(prices, n = 14) {     deltas &lt;- diff(prices)     seed &lt;- deltas[1:n]     up &lt;- seed[seed >= 0]     down &lt;- -seed[seed &lt; 0]     up[is.na(up)] &lt;- 0     down[is.na(down)] &lt;- 0      avg_gain &lt;- sum(up) \/ n     avg_loss &lt;- sum(down) \/ n     rs &lt;- avg_gain \/ avg_loss     rsi &lt;- 100 - (100 \/ (1 + rs))      rsi_values &lt;- c(rep(NA, n), rsi)          for (i in (n+1):length(deltas)) {         delta &lt;- deltas[i]         gain &lt;- ifelse(delta > 0, delta, 0)         loss &lt;- ifelse(delta &lt; 0, -delta, 0)          avg_gain &lt;- (avg_gain * (n - 1) + gain) \/ n         avg_loss &lt;- (avg_loss * (n - 1) + loss) \/ n         rs &lt;- avg_gain \/ avg_loss         rsi &lt;- 100 - (100 \/ (1 + rs))          rsi_values &lt;- c(rsi_values, rsi)     }      return(rsi_values) }  # example prices &lt;- c(45.15, 46.23, 45.56, 46.33, 45.86, 46.71, 47.24, 46.69, 47.28, 47.88, 48.07, 47.86, 47.33, 47.59) rsi &lt;- calculate_rsi(prices) print(rsi)<\/code><\/pre>\n<h2>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440  <\/h2>\n<p>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0414\u0436\u043e\u0440\u0434\u0436\u0435\u043c \u041b\u0435\u0439\u043d\u043e\u043c \u0432 \u043a\u043e\u043d\u0446\u0435 1950-\u0445 \u0433\u043e\u0434\u043e\u0432. \u042d\u0442\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0446\u0435\u043d\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043a \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0443 \u0446\u0435\u043d \u0437\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432 \u0432\u043e\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u0442\u0440\u0435\u043d\u0434\u0435 \u0446\u0435\u043d\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u043e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0431\u043b\u0438\u0436\u0435 \u043a \u0432\u0435\u0440\u0445\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0430, \u0430 \u0432 \u043d\u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u043c \u0442\u0440\u0435\u043d\u0434\u0435 \u2014 \u0431\u043b\u0438\u0436\u0435 \u043a \u043d\u0438\u0436\u043d\u0435\u0439 \u0433\u0440\u0430\u043d\u0438\u0446\u0435. <\/p>\n<p>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u0432: \u043b\u0438\u043d\u0438\u0438 %K \u0438 \u043b\u0438\u043d\u0438\u0438 %D.<\/p>\n<ol>\n<li>\n<p><strong>%K \u043b\u0438\u043d\u0438\u044f<\/strong> \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043f\u043e \u0444\u043e\u0440\u043c\u0443\u043b\u0435<\/p>\n<p> \u0433\u0434\u0435:<\/p>\n<ul>\n<li>\n<p> \u2014 \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0446\u0435\u043d\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f,<\/p>\n<\/li>\n<li>\n<p> \u2014 \u0441\u0430\u043c\u0430\u044f \u043d\u0438\u0437\u043a\u0430\u044f \u0446\u0435\u043d\u0430 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 N \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432,<\/p>\n<\/li>\n<li>\n<p> \u2014 \u0441\u0430\u043c\u0430\u044f \u0432\u044b\u0441\u043e\u043a\u0430\u044f \u0446\u0435\u043d\u0430 \u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 N \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>%D \u043b\u0438\u043d\u0438\u044f<\/strong> \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0435 \u0441\u0440\u0435\u0434\u043d\u0435\u0435 \u043b\u0438\u043d\u0438\u0438 %K \u0437\u0430 \u0442\u0440\u0438 \u043f\u0435\u0440\u0438\u043e\u0434\u0430:<\/p>\n<\/li>\n<\/ol>\n<p>\u041f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043f\u0435\u0440\u0438\u043e\u0434 \u0432 14 \u0434\u043d\u0435\u0439 \u0434\u043b\u044f %K \u0438 3 \u0434\u043d\u044f \u0434\u043b\u044f %D, \u043d\u043e \u044d\u0442\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0435\u043d\u0438\u0439.<\/p>\n<p>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u043a\u043e\u043b\u0435\u0431\u043b\u044e\u0442\u0441\u044f \u043e\u0442 0 \u0434\u043e 100. \u0423\u0440\u043e\u0432\u043d\u0438 \u0432\u044b\u0448\u0435 80 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c \u0430\u043a\u0442\u0438\u0432\u0430, \u0430 \u0443\u0440\u043e\u0432\u043d\u0438 \u043d\u0438\u0436\u0435 20 \u2014 \u043d\u0430 \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<ul>\n<li>\n<p><strong>\u041f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c<\/strong>: \u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0435\u0442 80, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0432\u043d\u0438\u0437. \u0422\u0440\u0435\u0439\u0434\u0435\u0440\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u044d\u0442\u043e \u043a\u0430\u043a \u0441\u0438\u0433\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u0430\u0436\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>\u041f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c<\/strong>:\u043a\u043e\u0433\u0434\u0430 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043f\u0430\u0434\u0430\u0435\u0442 \u043d\u0438\u0436\u0435 20, \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0439 \u0440\u0430\u0437\u0432\u043e\u0440\u043e\u0442 \u0432\u0432\u0435\u0440\u0445. \u042d\u0442\u043e \u0441\u0438\u0433\u043d\u0430\u043b \u0434\u043b\u044f \u043f\u043e\u043a\u0443\u043f\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u0445\u043e\u0440\u043e\u0448 \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u0431\u043e\u043a\u043e\u0432\u043e\u0433\u043e \u0440\u044b\u043d\u043a\u0430, \u0433\u0434\u0435 \u043e\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0432\u044b\u044f\u0432\u043b\u044f\u0442\u044c \u043a\u0440\u0430\u0442\u043a\u043e\u0441\u0440\u043e\u0447\u043d\u044b\u0435 \u043a\u043e\u043b\u0435\u0431\u0430\u043d\u0438\u044f. \u0412 \u0442\u0440\u0435\u043d\u0434\u043e\u0432\u044b\u0445 \u0440\u044b\u043d\u043a\u0430\u0445 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0437\u043e\u043d\u0435 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438\u043b\u0438 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0434\u043b\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0434\u043e\u043f. \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432.<\/p>\n<p>\u0414\u0438\u0432\u0435\u0440\u0433\u0435\u043d\u0446\u0438\u0438 \u0441\u0442\u043e\u0445\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u044e\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0441\u0446\u0438\u043b\u043b\u044f\u0442\u043e\u0440\u0430 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u0435\u0442 \u0441 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0446\u0435\u043d\u044b \u0430\u043a\u0442\u0438\u0432\u0430.<\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440\u044b \u0440\u0430\u0441\u0441\u0447\u0435\u0442\u043e\u0432 \u0432 \u043a\u043e\u0434\u0435<\/h4>\n<p><strong>Python<\/strong><\/p>\n<pre><code class=\"python\">import pandas as pd  def calculate_stochastic_oscillator(data, k_period=14, d_period=3):     low_min = data['Low'].rolling(window=k_period).min()     high_max = data['High'].rolling(window=k_period).max()      data['%K'] = 100 * ((data['Close'] - low_min) \/ (high_max - low_min))     data['%D'] = data['%K'].rolling(window=d_period).mean()     return data  # example data = pd.DataFrame({     'High': [127.01, 128.48, 128.43, 128.72, 128.22, 128.43, 128.72, 128.21, 128.35, 128.75, 128.37, 128.57, 128.88, 128.78],     'Low': [125.36, 126.41, 126.74, 126.82, 126.32, 126.74, 126.82, 126.41, 126.35, 126.82, 126.41, 126.72, 126.92, 126.72],     'Close': [126.45, 127.98, 127.98, 128.43, 127.38, 127.68, 128.43, 127.88, 127.88, 128.28, 127.78, 128.15, 128.43, 128.23] })  data = calculate_stochastic_oscillator(data) print(data[['%K', '%D']])<\/code><\/pre>\n<p><strong>JavaScript<\/strong><\/p>\n<pre><code class=\"javascript\">function calculateStochasticOscillator(highs, lows, closes, kPeriod = 14, dPeriod = 3) {     let stochastics = [];     let percentK = [];     let percentD = [];      for (let i = 0; i &lt; closes.length; i++) {         if (i >= kPeriod - 1) {             let highMax = Math.max(...highs.slice(i - kPeriod + 1, i + 1));             let lowMin = Math.min(...lows.slice(i - kPeriod + 1, i + 1));             let k = ((closes[i] - lowMin) \/ (highMax - lowMin)) * 100;             percentK.push(k);              if (percentK.length >= dPeriod) {                 let d = percentK.slice(-dPeriod).reduce((a, b) => a + b) \/ dPeriod;                 percentD.push(d);             } else {                 percentD.push(null);             }         } else {             percentK.push(null);             percentD.push(null);         }          stochastics.push({             K: percentK[percentK.length - 1],             D: percentD[percentD.length - 1]         });     }      return stochastics; }  \/\/ example let highs = [127.01, 128.48, 128.43, 128.72, 128.22, 128.43, 128.72, 128.21, 128.35, 128.75, 128.37, 128.57, 128.88, 128.78]; let lows = [125.36, 126.41, 126.74, 126.82, 126.32, 126.74, 126.82, 126.41, 126.35, 126.82, 126.41, 126.72, 126.92, 126.72]; let closes = [126.45, 127.98, 127.98, 128.43, 127.38, 127.68, 128.43, 127.88, 127.88, 128.28, 127.78, 128.15, 128.43, 128.23];  console.log(calculateStochasticOscillator(highs, lows, closes));<\/code><\/pre>\n<p><strong>R<\/strong><\/p>\n<pre><code class=\"r\">calculate_stochastic &lt;- function(highs, lows, closes, k_period = 14, d_period = 3) {     K &lt;- rep(NA, length(closes))     D &lt;- rep(NA, length(closes))          for (i in seq(k_period, length(closes))) {         high_max &lt;- max(highs[(i - k_period + 1):i])         low_min &lt;- min(lows[(i - k_period + 1):i])         K[i] &lt;- ((closes[i] - low_min) \/ (high_max - low_min)) * 100     }          for (i in seq((k_period + d_period - 1), length(closes))) {         D[i] &lt;- mean(K[(i - d_period + 1):i], na.rm = TRUE)     }          return(data.frame(K = K, D = D)) }  # example highs &lt;- c(127.01, 128.48, 128.43, 128.72, 128.22, 128.43, 128.72, 128.21, 128.35, 128.75, 128.37, 128.57, 128.88, 128.78) lows &lt;- c(125.36, 126.41, 126.74, 126.82, 126.32, 126.74, 126.82, 126.41, 126.35,<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-379693","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379693","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=379693"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/379693\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379693"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379693"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379693"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}