{"id":469805,"date":"2025-08-06T15:02:02","date_gmt":"2025-08-06T15:02:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=469805"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=469805","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u043d\u0430 Python \u0434\u043b\u044f \u0442\u043e\u0440\u0433\u043e\u0432\u043b\u0438 \u043f\u043e \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430\u043c \u043d\u0430 Bybit<\/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<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u042f Python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u0443\u043a\u043b\u043e\u043d\u043e\u043c \u0432 \u0430\u043b\u0433\u043e\u0442\u0440\u0435\u0439\u0434\u0438\u043d\u0433. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u043f\u043e\u0434 Bybit, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u0440\u0433\u0443\u0435\u0442 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043d\u0430 <strong>Bollinger Bands<\/strong>. \u041f\u043e\u043a\u0430\u0436\u0443 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 API, \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0434\u0435\u043b\u043e\u043a. \u041f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u0442\u0435\u043c, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u0440\u0436\u0430\u043c\u0438 \u0438 \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0436\u0438\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0440\u0443\u043a\u0430\u043c\u0438.<\/p>\n<hr\/>\n<h3>\ud83d\udccc \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Bollinger Bands?<\/h3>\n<p>\u041f\u043e\u043b\u043e\u0441\u044b \u0411\u043e\u043b\u043b\u0438\u043d\u0434\u0436\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0438. \u041f\u043e \u0441\u0443\u0442\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u0421\u0435\u0440\u0435\u0434\u0438\u043d\u0430 (middle)<\/strong>: \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0430\u044f \u0441\u0440\u0435\u0434\u043d\u044f\u044f (\u043e\u0431\u044b\u0447\u043d\u043e 20 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432).<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0435\u0440\u0445\u043d\u044f\u044f \u043f\u043e\u043b\u043e\u0441\u0430 (upper)<\/strong>: SMA + 2 * std.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0438\u0436\u043d\u044f\u044f \u043f\u043e\u043b\u043e\u0441\u0430 (lower)<\/strong>: SMA &#8212; 2 * std.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0434\u0435\u044f: \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u044c \u043f\u0440\u0438 \u043a\u0430\u0441\u0430\u043d\u0438\u0438 \u043d\u0438\u0436\u043d\u0435\u0439 \u043f\u043e\u043b\u043e\u0441\u044b \u0438 \u043f\u0440\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043a\u0430\u0441\u0430\u043d\u0438\u0438 \u0432\u0435\u0440\u0445\u043d\u0435\u0439. \u0422\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0441\u0434\u0435\u043b\u043e\u043a, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 BB \u0434\u0430\u0441\u0442 \u043f\u043b\u043e\u0445\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<hr\/>\n<h3>\ud83d\udd0d \u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b <\/h3>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043f \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u0449\u0438\u0435:<\/p>\n<h4>1. RSI (Relative Strength Index)<\/h4>\n<ul>\n<li>\n<p>\u041c\u043e\u043c\u0435\u043d\u0442\u0443\u043c-\u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c\/\u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>RSI &lt; 30 \u2014 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c (\u043b\u043e\u043d\u0433), RSI &gt; 70 \u2014 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c (\u0448\u043e\u0440\u0442)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043f\u0430\u0440\u0435 \u0441 Bollinger Bands<\/p>\n<\/li>\n<\/ul>\n<h4>2. EMA (Exponential Moving Average)<\/h4>\n<ul>\n<li>\n<p>\u0411\u044b\u0441\u0442\u0440\u0430\u044f \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0444\u0438\u043b\u044c\u0442\u0440 \u0442\u0440\u0435\u043d\u0434\u0430: \u0446\u0435\u043d\u0430 \u0432\u044b\u0448\u0435 EMA \u2192 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043b\u043e\u043d\u0433<\/p>\n<\/li>\n<\/ul>\n<h4>3. ATR (Average True Range)<\/h4>\n<ul>\n<li>\n<p>\u0418\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043f-\u043b\u043e\u0441\u0441\u0430 \u0438\u043b\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0438\u0437\u043a\u043e\u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<h4>4. CSI \/ CSC (Cluster Strength Index \/ Cluster Signal Confirmation)<\/h4>\n<ul>\n<li>\n<p>\u0418\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u0435\u0447\u0435\u0439 \u0438 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u0445 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<h3>\ud83d\udee0\ufe0f \u0427\u0442\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h3>\n<ul>\n<li>\n<p><code>requests<\/code> \u2014 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c.<\/p>\n<\/li>\n<li>\n<p><code>pybit<\/code> \u2014 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 API Bybit.<\/p>\n<\/li>\n<li>\n<p><code>pandas<\/code>, <code>numpy<\/code> \u2014 \u0440\u0430\u0441\u0447\u0451\u0442\u044b \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><code>datetime<\/code>, <code>time<\/code> \u2014 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<\/li>\n<li>\n<p><code>threading<\/code> \u2014 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p><code>telebot<\/code> (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) \u2014 \u0434\u043b\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0432 Telegram.<\/p>\n<\/li>\n<\/ul>\n<h3>\ud83d\udcc1 \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<pre><code class=\"python\">bollinger_bot\/ \u251c\u2500\u2500 main.py              # \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u251c\u2500\u2500 back.py              # \u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u251c\u2500\u2500 config.cfg           # \u043a\u043e\u043d\u0444\u0438\u0433 \u0444\u0430\u0439\u043b \u0441 \u043d\u0430\u0439\u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0434. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u043e\u043a\u0430 \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0412\u043e\u0442 \u043b\u0443\u0447\u0448\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043d\u0430\u0448\u0435\u043b \u0437\u0430 \u0432\u0440\u0435\u043c\u044f \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np import time import datetime from collections import deque from scipy.stats import zscore from binance.client import Client as BinanceClient from pybit.unified_trading import HTTP import telebot # === \u041d\u0410\u0421\u0422\u0420\u041e\u0419\u041a\u0418 ===  symbol = \"ETHUSDT\" interval = \"5m\"  bb_period = 40 bb_std = 1  STOP_LOSS_PCT = 0.004  client = BinanceClient()  config = {     'min_cluster': 3,     'bull_quant': 0.75,     'bear_quant': 0.25,     'rsi': 60 }<\/code><\/pre>\n<h3>\ud83d\udcc8 \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c <code>pybit<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u0432\u0435\u0447\u0438:<\/p>\n<pre><code class=\"python\">def fetch_klines_paged(symbol=symbol, interval=interval, total_bars=100000, client=None):     if client is None:         client = Client()      limit = 1000     data = []     end_time = int(time.time() * 1000)      while len(data) &lt; total_bars:         bars_to_fetch = min(limit, total_bars - len(data))         try:             klines = client.futures_klines(symbol=symbol, interval=interval, limit=bars_to_fetch, endTime=end_time)         except Exception as e:             print(\"\u041e\u0448\u0438\u0431\u043a\u0430 Binance API:\", e)             break          if not klines:             break          data = klines + data         end_time = klines[0][0] - 1         time.sleep(0.2)      df = pd.DataFrame(data, columns=[         'timestamp', 'open', 'high', 'low', 'close', 'volume',         'close_time', 'quote_asset_volume', 'number_of_trades',         'taker_buy_base', 'taker_buy_quote', 'ignore'     ])     df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')     df[['open','high','low','close','volume']] = df[['open','high','low','close','volume']].astype(float)     df = df.drop_duplicates('timestamp').sort_values('timestamp').reset_index(drop=True)     return df<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 bybit \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u0435\u0447\u0435\u0439 \u0438\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u043b\u0438\u043c\u0438\u0442 \u0432 1500 \u0441\u0432\u0435\u0447\u0435\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0443\u044e \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0434\u043b\u044f \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0430. <\/p>\n<p>\u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0434\u043b\u044f \u0441\u0432\u0435\u0447\u0435\u0439 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f df. \u041f\u043e\u0437\u0436\u0435 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043f. \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0440\u0435\u0437\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0435 \u0434\u043e 50000 \u0441\u0432\u0435\u0447\u0435\u0439, \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0423 \u0441\u0432\u0435\u0447\u0435\u0439 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<ol>\n<li>\n<p>timestamp &#8212; \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>open &#8212; \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>high &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>low &#8212; \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>close &#8212; \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>volume &#8212; \u043e\u0431\u044c\u0451\u043c, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043e\u043d \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d<\/p>\n<\/li>\n<\/ol>\n<h2>\u0420\u0430\u0441\u0447\u0451\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<p>\u0432\u0441\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0443 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435. \u0414\u043b\u044f \u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u0443\u0445\u043e\u043c \u043a\u043e\u0434\u0435. \u0418\u0437 \u0432\u0430\u0436\u043d\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <\/p>\n<ol>\n<li>\n<p>period = 450 \u0432 \u0440\u0430\u0441\u0447\u0451\u0442\u0435 RSI. \u042d\u0442\u043e\u0442 \u043f\u0435\u0440\u0438\u043e\u0434 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043d\u0430 ATR. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0438\u0435 \u0446\u0438\u0444\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043f\u043e \u0432\u0441\u0435\u0439 \u0434\u043b\u0438\u043d\u0435 \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0430 (\u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 100000 \u0441\u0432\u0435\u0447\u0435\u0439 \u043f\u043e 5\u043c). \u041d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0431\u043e\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u044b\u043b \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0442\u0435\u0441\u0442\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0442\u043e\u0436\u0435 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u0435\u0447\u0438, \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u0436\u0435 50000-100000 \u0448\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0412 ATR.rolling() \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 14. \u042d\u0442\u043e \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u0435, 14 &#8212; \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u0443\u0442 \u043e\u043d\u043e \u043c\u043d\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442. <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">def compute_rsi(df, period=450):     delta = df['close'].diff()     gain = delta.clip(lower=0)     loss = -delta.clip(upper=0)     avg_gain = gain.rolling(period, min_periods=1).mean()     avg_loss = loss.rolling(period, min_periods=1).mean()     rs = avg_gain \/ avg_loss     df['RSI'] = 100 - (100 \/ (1 + rs))     df['RSI'] = df['RSI'].fillna(method='bfill')     return df  def compute_csc(df, min_cluster, bull_quant, bear_quant):     bull_thr = df['CSI'].quantile(bull_quant)     bear_thr = df['CSI'].quantile(bear_quant)      df['sentiment'] = np.where(df['CSI'] &gt;= bull_thr, 'bull',                         np.where(df['CSI'] &lt;= bear_thr, 'bear', 'neutral'))     df['cluster_id'] = pd.Series(dtype='object')     curr_type, curr_start, length = None, None, 0      for i, s in df['sentiment'].items():         if s == curr_type and s in ['bull', 'bear']:             length += 1         else:             if curr_type in ['bull', 'bear'] and length &gt;= min_cluster:                 df.loc[curr_start:i-1, 'cluster_id'] = f\"{curr_type}_{curr_start}\"             if s in ['bull', 'bear']:                 curr_type, curr_start, length = s, i, 1             else:                 curr_type, length = None, 0      if curr_type in ['bull', 'bear'] and length &gt;= min_cluster:         df.loc[curr_start:df.index[-1], 'cluster_id'] = f\"{curr_type}_{curr_start}\"      return df  def compute_bollinger(df):     df['ma'] = df['close'].rolling(bb_period).mean()     df['std'] = df['close'].rolling(bb_period).std()     df['upper'] = df['ma'] + bb_std * df['std']     df['lower'] = df['ma'] - bb_std * df['std']     return df  def get_csi(df):     body = (df['close'] - df['open']).abs()     rng = (df['high'] - df['low']).replace(0, np.nan)     body_ratio = body \/ rng     direction = np.where(df['close'] &gt; df['open'], 1, -1)     vol_score = df['volume'] \/ df['volume'].rolling(50).max()     range_z = zscore(df['high'] - df['low']).clip(-3, 3)      tr = pd.DataFrame({         'hl': df['high'] - df['low'],         'hc': (df['high'] - df['close'].shift(1)).abs(),         'lc': (df['low'] - df['close'].shift(1)).abs()     }).max(axis=1)      atr = tr.rolling(14).mean().bfill()     df['CSI'] = direction * (0.5 * body_ratio + 0.3 * vol_score + 0.2 * range_z) \/ atr     return df<\/code><\/pre>\n<h2>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u0432\u0445\u043e\u0434\u0430<\/h2>\n<p>\u0423\u0436\u0435 \u0440\u0430\u043d\u0435\u0435 \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u043a\u043e\u043d\u0444\u0438\u0433 \u0434\u043b\u044f \u0431\u043e\u0442\u0430. \u041a\u043e\u043d\u0444\u0438\u0433 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432\u0445\u043e\u0434\u0430. \u041c\u043e\u0439 \u0431\u043e\u0442 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0434\u0432\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b &#8212; \u0438 \u0432 \u043b\u043e\u043d\u0433, \u0438 \u0432 \u0448\u043e\u0440\u0442. \u0412\u0430\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043b\u043e\u043d\u0433 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 10-15% \u0447\u0430\u0449\u0435, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e \u0441 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438 \u0440\u044b\u043d\u043a\u0430 (\u0433\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u0430\u0434\u0430\u0442\u044c \u0442\u044f\u0436\u0435\u043b\u0435\u0435, \u0447\u0435\u043c \u0440\u0430\u0441\u0442\u0438). <\/p>\n<pre><code class=\"python\">def check_signal_row(row, prev_row):     if np.isnan(row['lower']) or np.isnan(prev_row['CSI']) or np.isnan(row['CSI']):         return None     cluster = row['cluster_id']     if not isinstance(cluster, str):         return None      long_cond = (         row['close'] &lt; row['lower'] and         row['CSI'] &gt; 0 and row['CSI'] &gt; prev_row['CSI'] and         cluster.startswith('bull') and row['RSI'] &lt; config['rsi']     )     short_cond = (         row['close'] &gt; row['upper'] and         row['CSI'] &lt; 0 and row['CSI'] &lt; prev_row['CSI'] and         cluster.startswith('bear') and row['RSI'] &gt; (100 - config['rsi'])     )      if long_cond:         return 'buy'     elif short_cond:         return 'sell'     return None<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u0434. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441 \u0441\u0434\u0435\u043b\u043a\u0430\u043c\u0438, \u0433\u0434\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441\u0438\u0433\u043d\u0430\u043b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0441\u0432\u0435\u0447\u0430\u043c\u0438 \u0432 csv \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     df = fetch_klines_paged(symbol, interval, 100000, client)     df = compute_rsi(df)     df = compute_bollinger(df)     df = get_csi(df)     df = compute_csc(df, config['min_cluster'], config['bull_quant'], config['bear_quant'])      signals = [None]     for i in range(1, len(df)):         signals.append(check_signal_row(df.iloc[i], df.iloc[i - 1]))     df['signal'] = signals           in_position = False     entry_price = None     entry_index = None     position_type = None      completed_trades = []      for i in range(1, len(df)):         row = df.iloc[i]         signal = row['signal']          # === \u0412\u0445\u043e\u0434 \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u044e ===         if not in_position and signal in ['buy', 'sell']:             in_position = True             entry_index = i             entry_price = row['close']             position_type = 'long' if signal == 'buy' else 'short'             stop_price = (                 entry_price * (1 - STOP_LOSS_PCT) if position_type == 'long'                 else entry_price * (1 + STOP_LOSS_PCT)             )          # === \u0412\u044b\u0445\u043e\u0434 \u0438\u0437 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 ===         elif in_position:             exit_index = entry_index + 15             exit_row = df.iloc[i]             low, high = exit_row['low'], exit_row['high']             hit_stop = (                 low &lt;= stop_price if position_type == 'long'                 else high &gt;= stop_price             )              if hit_stop or i &gt;= exit_index:                 exit_price = stop_price if hit_stop else exit_row['close']                 pnl = (                     (exit_price - entry_price) \/ entry_price * 100                     if position_type == 'long'                     else (entry_price - exit_price) \/ entry_price * 100                 )                 completed_trades.append({                     'entry_time': df.iloc[entry_index]['timestamp'],                     'exit_time': df.iloc[i]['timestamp'],                     'position_type': position_type,                     'entry_price': entry_price,                     'exit_price': exit_price,                     'pnl_%': pnl,                     'reason': 'stop_loss' if hit_stop else 'time_exit'                 })                 in_position = False      # === \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0441\u0434\u0435\u043b\u043a\u0438 ===     trades_df = pd.DataFrame(completed_trades)     trades_df.to_csv('trades_complete.csv', sep=';', index=False)      print(\"\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0441\u0434\u0435\u043b\u043a\u0438:\")     print(trades_df.tail(10))      total_pnl = trades_df['pnl_%'].sum()     print(f\"\\n\u041e\u0431\u0449\u0438\u0439 PnL \u043f\u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438: {total_pnl:.2f}%\") <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 \u043a\u043e\u043d\u0446\u0435 \u0432\u044b\u0432\u043e\u0434 \u043e\u0431\u0449\u0435\u0433\u043e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043f\u043e \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438. <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0430. \u0411\u0435\u043a\u0442\u0435\u0441\u0442 &#8212; \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0433\u043e \u0432\u0430\u043c\u0438 \u0431\u043e\u0442\u0430. \u0411\u0435\u043a\u0442\u0435\u0441\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438, \u043c\u043d\u043e\u0433\u0438\u0435 \u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0442 \u0431\u0435\u043a\u0442\u0435\u0441\u0442 \u0441 \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0439 \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435. \u041d\u043e \u044d\u0442\u043e \u0443\u0441\u043b\u043e\u0436\u043d\u0435\u043d\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u0438, \u043f\u043e-\u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e \u044d\u0442\u043e \u043d\u0435 \u0441\u0442\u043e\u0438\u0442 \u0442\u043e\u0433\u043e.<\/p>\n<h2>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430<\/h2>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f. \u0420\u0430\u0441\u0447\u0451\u0442 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439. \u042f \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c\u043c \u0431\u043e\u0442\u0430, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0435\u0434\u0438\u0442\u044c.<\/p>\n<p>\u041e\u0447\u0435\u043d\u044c \u0432\u0430\u0436\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 &#8212; \u043d\u0443\u0436\u043d\u043e \u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u0438 \u0441\u0432\u0435\u0447\u0435\u0439. \u041e\u0434\u043d\u0430 \u0434\u043b\u044f \u0441\u0432\u0435\u0447\u0435\u0439 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u0432\u0442\u043e\u0440\u0430\u044f \u0434\u043b\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043d\u0443\u0436\u043d\u043e \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430 csc).<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u043d\u0444\u0438\u0433:<\/p>\n<pre><code class=\"python\"># === \u041d\u0410\u0421\u0422\u0420\u041e\u0419\u041a\u0418 === symbol = \"ETHUSDT\" interval = \"5m\" bb_period = 40 bb_std = 1 STOP_LOSS_PCT = 0.004 TRADE_QTY_ETH = 1 EXIT_AFTER_BARS = 3 #15 \u043c\u0438\u043d\u0443\u0442 TELEGRAM_CHAT_ID = config.tg_id #\u0441\u0432\u043e\u0439 chat_id  # === API === bot = telebot.TeleBot(\"7871321841:AAGp9cbyLRCdO0VMfqK0v-x2eGCfIqebmVU\") #tg bot BYBIT_API_KEY = config.apikey BYBIT_API_SECRET = config.bybit_secret  bybit = HTTP(api_key=BYBIT_API_KEY, api_secret=BYBIT_API_SECRET) #bybit init  # === \u041a\u041b\u0410\u0421\u0422\u0415\u0420\u041d\u042b\u0419 \u041a\u041e\u041d\u0424\u0418\u0413 === config = {     'min_cluster': 3,     'bull_quant': 0.75,     'bear_quant': 0.25,     'rsi': 60,     'total_bars': 60000 }  entry_history = deque(maxlen=100) open_positions = [] client = BinanceClient()<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u043a\u0443 \u0441\u0432\u0435\u0447\u0435\u0439:<\/p>\n<pre><code class=\"python\">def fetch_klines_paged(symbol=symbol, interval=interval,  total_bars=60000, client = None):     if client is None:         client = BinanceClient()      limit = 1000     data = []     end_time = None  # \u0441\u0430\u043c\u044b\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0431\u0430\u0440 (\u043d\u043e\u0432\u0435\u0439\u0448\u0430\u044f \u0442\u043e\u0447\u043a\u0430)      while len(data) &lt; total_bars:         bars_to_fetch = min(limit, total_bars - len(data))          try:             klines = client.futures_klines(                 symbol=symbol,                 interval=interval,                 limit=bars_to_fetch,                 endTime=end_time             )         except Exception as e:             print(\"\u041e\u0448\u0438\u0431\u043a\u0430 Binance API:\", e)             break          if not klines:             break          data = klines + data  # prepend! \u2014 \u0441\u0442\u0430\u0440\u044b\u0435 \u0441\u0432\u0435\u0447\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0430\u0447\u0430\u043b\u043e         end_time = klines[0][0] - 1  # \u0441\u0434\u0432\u0438\u0433 \u043d\u0430\u0437\u0430\u0434 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438         time.sleep(0.2)      df = pd.DataFrame(data, columns=[         'timestamp', 'open', 'high', 'low', 'close', 'volume',         'close_time', 'quote_asset_volume', 'number_of_trades',         'taker_buy_base', 'taker_buy_quote', 'ignore'     ])     df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')     df[['open','high','low','close','volume']] = df[['open','high','low','close','volume']].astype(float)     df = df.drop_duplicates('timestamp')     df = df.sort_values('timestamp').reset_index(drop=True)     return df  def get_last_closed_candle():     df = fetch_klines_paged(total_bars=50000)     last_candle = df.iloc[-2]  # \u043f\u0440\u0435\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u2014 \u043e\u043d\u0430 \u0437\u0430\u043a\u0440\u044b\u0442\u0430     now = datetime.datetime.now(datetime.timezone.utc)     if (now - last_candle['timestamp'].to_pydatetime()).total_seconds() &gt;= 300:         return last_candle.to_frame().T     else:         print(\"\u23f3 \u0421\u0432\u0435\u0447\u0430 \u0435\u0449\u0451 \u043d\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0430. \u041f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u043c.\")         return None  <\/code><\/pre>\n<p>\u0414\u043b\u044f \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u0438\u044f \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0435\u0434\u0438\u043d\u043e\u0439. \u041d\u043e \u0432 \u0438\u0434\u0435\u0430\u043b\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 100-200 \u0441\u0432\u0435\u0447\u0435\u0439 \u0438 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043d\u0435\u0439. \u042d\u0442\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438\u0448\u044c \u043d\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0437\u0430\u0442\u0440\u0430\u0442\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043b def get_last_closed_candle(), \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0441\u0432\u0435\u0447\u0443 \u0438 \u0441\u0438\u0433\u043d\u0430\u043b \u043d\u0430 \u043d\u0435\u0439. \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c \u043f\u043e\u0442\u043e\u043a\u0438, \u043b\u0438\u0431\u043e \u0435\u0449\u0451 \u0445\u0443\u0436\u0435 &#8212; time.sleep(), \u043e\u0434\u043d\u0430\u043a\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043c\u0435\u043d\u044f \u043d\u0435 \u0443\u0441\u0442\u0440\u043e\u0438\u043b \u043d\u0430 \u0434\u0438\u0441\u0442\u0430\u043d\u0446\u0438\u0438. \u041f\u043e \u043e\u043f\u044b\u0442\u0443 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0445\u0443\u0436\u0435.<\/p>\n<p>\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u0432\u0430\u0436\u043d\u044b\u0439 \u043d\u044c\u044e\u0430\u043d\u0441, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043a\u0430\u0437\u0430\u043b \u0440\u0430\u043d\u0435\u0435. \u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c sub = df[], \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u0440\u0430\u0441\u0447\u0451\u0442\u0435 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432 (\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043e\u0442\u0440\u0435\u0437\u043a\u0435 \u0441\u0432\u0435\u0447\u0435\u0439) \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u043e \u0440\u0430\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0441 \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u043e\u043c. \u0412 \u0434\u0440\u0443\u0433\u0438\u0445 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430\u0445 \u044d\u0442\u043e \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u043d\u0438\u0445 \u0438 \u0442\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f &lt;1000 \u0441\u0432\u0435\u0447\u0435\u0439 (\u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0432 rsi, 450).<\/p>\n<pre><code class=\"python\">def compute_csc(df):     sub = df.tail(min(50000, len(df)))     bull_thr = sub['CSI'].quantile(config['bull_quant'])     bear_thr = sub['CSI'].quantile(config['bear_quant'])     df['sentiment'] = np.where(df['CSI'] &gt;= bull_thr, 'bull', np.where(df['CSI'] &lt;= bear_thr, 'bear', 'neutral'))     df['cluster_id'] = pd.Series(dtype='object')     curr_type, curr_start, length = None, None, 0     for i, s in df['sentiment'].items():         if s == curr_type and s in ['bull','bear']:             length += 1         else:             if curr_type in ['bull','bear'] and length &gt;= config['min_cluster']:                 df.loc[curr_start:i-1, 'cluster_id'] = f\"{curr_type}_{curr_start}\"             if s in ['bull','bear']:                 curr_type, curr_start, length = s, i, 1             else:                 curr_type, length = None, 0     if curr_type in ['bull','bear'] and length &gt;= config['min_cluster']:         df.loc[curr_start:df.index[-1], 'cluster_id'] = f\"{curr_type}_{curr_start}\"     return df<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u0445\u043e\u0434\u0430 \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u044e. \u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u044d\u0442\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pybit. \u0422\u0430\u043a\u0436\u0435 \u0441\u0434\u0435\u043b\u0430\u043b \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u0431\u043e\u0442 \u0442\u043e\u0447\u043d\u043e \u043d\u0435 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0437\u0438\u0446\u0438\u0439 \u0432 \u043e\u0434\u043d\u043e\u0439 5\u043c \u0441\u0432\u0435\u0447\u0435.<\/p>\n<pre><code class=\"python\">def place_order(symbol, side, qty_eth, stop_price):     try:         bybit.place_order(             category=\"linear\",             symbol=symbol,             side=\"Buy\" if side == \"long\" else \"Sell\",             order_type=\"Market\",             qty=qty_eth,             time_in_force=\"GoodTillCancel\",             stopLoss=round(stop_price, 2)         )         bot.send_message(TELEGRAM_CHAT_ID, f\"\u2705 \u041e\u0442\u043a\u0440\u044b\u0442\u0430 {side.upper()} \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u043d\u0430 {qty_eth} ETH\")     except Exception as e:         print(\"\u041e\u0448\u0438\u0431\u043a\u0430 \u043e\u0440\u0434\u0435\u0440\u0430:\", e)  def close_position(symbol, position_type, qty_eth):     try:         bybit.place_order(             category=\"linear\",             symbol=symbol,             side=\"Sell\" if position_type == \"long\" else \"Buy\",             order_type=\"Market\",             qty=qty_eth,             time_in_force=\"GoodTillCancel\"         )         bot.send_message(TELEGRAM_CHAT_ID, f\"\ud83d\udd3b \u0417\u0430\u043a\u0440\u044b\u0442\u0430 {position_type.upper()} \u043f\u043e\u0437\u0438\u0446\u0438\u044f ({qty_eth} ETH)\")     except Exception as e:         bot.send_message(TELEGRAM_CHAT_ID, f\"\u2757 \u041e\u0448\u0438\u0431\u043a\u0430 \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u043f\u043e\u0437\u0438\u0446\u0438\u0438: {e}\")  def can_enter_again(signal_type):     now = datetime.datetime.now(datetime.timezone.utc)     cooldown = 5 * 60     return not any((now - t).total_seconds() &lt; cooldown and s == signal_type for t, s in entry_history)<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0432\u044b\u0437\u043e\u0432\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<pre><code class=\"python\">bot.send_message(TELEGRAM_CHAT_ID, \"\ud83d\udcc8 \u0411\u043e\u0442 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\") df = fetch_klines_paged() last_checked_minute = None  while True:     try:         now = datetime.datetime.now(datetime.timezone.utc)         if now.minute % 5 == 0 and now.second &lt; 10:             if last_checked_minute == now.minute:                 time.sleep(1)                 continue             last_checked_minute = now.minute              new_df = get_last_closed_candle()             if new_df is None:                 continue              df = pd.concat([df, new_df.tail(1)]).drop_duplicates('timestamp').reset_index(drop=True)             if len(df) &gt; config['total_bars']:                 df = df.tail(config['total_bars'])              df = compute_bollinger(df)             df = get_csi(df)             df = compute_csc(df)             df = compute_rsi(df)             df['signal'] = [None] + [check_signal_row(df.iloc[i], df.iloc[i - 1]) for i in range(1, len(df))]              latest = df.iloc[-2]             signal = latest['signal']              if signal in ['buy', 'sell'] and can_enter_again(signal):                 entry_price = latest['close']                 stop_price = entry_price * (1 - STOP_LOSS_PCT) if signal == 'buy' else entry_price * (1 + STOP_LOSS_PCT)                 position_type = 'long' if signal == 'buy' else 'short'                 entry_time = datetime.datetime.now(datetime.timezone.utc)                  place_order(symbol, position_type, TRADE_QTY_ETH, stop_price)                 entry_history.append((entry_time, signal))                 open_positions.append({                     'type': position_type,                     'entry_price': entry_price,                     'stop_price': stop_price,                     'entry_time': entry_time                 })             positions_to_remove = []             current_price = latest['close']             updated_positions = []             for pos in open_positions[:]:                 entry_time = pos['entry_time']                 elapsed = (datetime.utcnow() - entry_time).total_seconds()                 position_data = bybit.get_positions(category=\"linear\", symbol=symbol)[\"result\"][\"list\"]                 position_size = float(position_data[0]['size']) if position_data else 0                  # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043d\u0430 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u043e\u043f-\u043b\u043e\u0441\u0441\u0430                 hit_stop = (                     (pos['type'] == 'long' and current_price &lt;= pos['stop_price']) or                     (pos['type'] == 'short' and current_price &gt;= pos['stop_price'])                 )                  if hit_stop or elapsed &gt;= (EXIT_AFTER_BARS * 5):                     # \u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430: \u043f\u043e\u0437\u0438\u0446\u0438\u044f \u0435\u0449\u0451 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435                     if position_size &gt; 0:                         exit_price = pos['stop_price'] if hit_stop else current_price                         pnl = (                             (exit_price - pos['entry_price']) \/ pos['entry_price'] * 100                             if pos['type'] == 'long'                             else (pos['entry_price'] - exit_price) \/ pos['entry_price'] * 100                         )                         reason = \"\u0441\u0442\u043e\u043f-\u043b\u043e\u0441\u0441\" if hit_stop else \"\u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438\"                         close_position(symbol, pos['type'], TRADE_QTY_ETH)                         bot.send_message(                             TELEGRAM_CHAT_ID,                             f\"\u274c \u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u0438: {pos['type'].upper()} \u043f\u043e {exit_price:.2f} ({reason})\\nPnL: {pnl:.2f}%\"                         )                     else:                         # \u041f\u043e\u0437\u0438\u0446\u0438\u044f \u0443\u0436\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0430 \u0432\u0440\u0443\u0447\u043d\u0443\u044e\/\u0441\u0442\u043e\u043f\u043e\u043c \u0432\u043d\u0435 \u043a\u043e\u0434\u0430                         bot.send_message(                             TELEGRAM_CHAT_ID,                             f\"\u2139\ufe0f \u041f\u043e\u0437\u0438\u0446\u0438\u044f {pos['type'].upper()} \u0443\u0436\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0430 \u043d\u0430 \u0431\u0438\u0440\u0436\u0435. \u0423\u0434\u0430\u043b\u044f\u044e \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430.\"                         )                      positions_to_remove.append(pos)              # \u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0445\/\u0437\u0430\u043a\u0440\u044b\u0442\u044b\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u0439             for p in positions_to_remove:                 if p in open_positions:                     open_positions.remove(p)      except Exception as e:         bot.send_message(TELEGRAM_CHAT_ID, f\"\u2757 \u041e\u0448\u0438\u0431\u043a\u0430: {e}\")      time.sleep(3) <\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e \u0438\u0442\u043e\u0433\u0443 \u0438\u043c\u0435\u0435\u043c \u0434\u0432\u0430 \u0444\u0430\u0439\u043b\u0430. Main.py \u0438 back.py. <\/p>\n<p>Main.py \u0444\u0430\u0439\u043b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0431\u043e\u0442\u0430. \u041f\u0435\u0440\u0435\u0434 \u044d\u0442\u0438\u043c \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u044b \u0438 \u0438\u0437\u0443\u0447\u0438\u0432 \u0432\u044b\u0432\u043e\u0434 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0438 .csv \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0432\u0438\u043d\u0440\u0435\u0439\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u043e\u0439 \u0431\u043e\u0442 \u0442\u043e\u0440\u0433\u0443\u0435\u0442 \u043f\u043e \u0444\u044c\u044e\u0447\u0430\u043c \u0438 \u043f\u0440\u043e\u0446\u0435\u043d\u0442 \u0447\u0438\u0441\u0442\u043e\u0439 \u043f\u0440\u0438\u0431\u044b\u043b\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b 173.86% \u0437\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0433\u043e\u0434 (100\u043a \u0441\u0432\u0435\u0447\u0435\u0439). \u0422\u043e \u0435\u0441\u0442\u044c \u044d\u0442\u043e 1738% \u043f\u0440\u0438\u0431\u044b\u043b\u0438 \u043d\u0430 \u043c\u0430\u0440\u0436\u0443. \u041d\u043e, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u0442\u043e\u0438\u0442 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0438 \u043a\u043e\u043c\u0438\u0441\u0441\u0438\u043e\u043d\u043d\u044b\u0435 + \u043f\u0440\u043e\u0441\u043a\u0430\u043b\u044c\u0437\u044b\u0432\u0430\u043d\u0438\u044f. \u041a\u043e\u043c\u0438\u0441\u0441\u0438\u044f \u0431\u0430\u0439\u0431\u0438\u0442 &#8212; 0,1% \u043d\u0430 \u043c\u0430\u0440\u0436\u0443 (0,01% \u043d\u0430 \u043f\u043e\u0437\u0438\u0446\u0438\u044e). \u0422\u0430\u043a\u0436\u0435 \u0437\u0430\u043a\u043b\u044b\u0432\u0430\u043b \u043f\u0440\u043e\u0441\u043a\u0430\u043b\u044c\u0437\u044b\u0432\u0430\u043d\u0438\u0435 \u043e\u043a\u043e\u043b\u043e 0,02%. \u0422\u0430\u043a \u0447\u0442\u043e \u043f\u0440\u0438\u0431\u044b\u043b\u044c \u0431\u043e\u0442\u0430 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043c\u0435\u043d\u044c\u0448\u0435. \u041e\u0434\u043d\u0430\u043a\u043e \u0435\u0441\u043b\u0438 \u0441\u0447\u0438\u0442\u0430\u0442\u044c % \u043d\u0430 \u043c\u0430\u0440\u0436\u0443, \u0442\u043e \u0432\u043b\u043e\u0436\u0438\u0432 1000$ \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u043e\u0435 (\u043d\u0430 unified trading \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u0435) \u043f\u043b\u0435\u0447\u043e 10\u0445, \u043c\u043e\u0436\u043d\u043e \u0437\u0430 \u0433\u043e\u0434 \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u0440\u0435\u0443\u043c\u043d\u043e\u0436\u0438\u0442\u044c \u044d\u0442\u0443 \u0441\u0443\u043c\u043c\u0443.<\/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\/934602\/\"> https:\/\/habr.com\/ru\/articles\/934602\/<\/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<p>\u041f\u0440\u0438\u0432\u0435\u0442, \u0425\u0430\u0431\u0440!<\/p>\n<p>\u042f Python-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u0443\u043a\u043b\u043e\u043d\u043e\u043c \u0432 \u0430\u043b\u0433\u043e\u0442\u0440\u0435\u0439\u0434\u0438\u043d\u0433. \u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0442\u043e\u0440\u0433\u043e\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u043f\u043e\u0434 Bybit, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u0440\u0433\u0443\u0435\u0442 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043d\u0430 <strong>Bollinger Bands<\/strong>. \u041f\u043e\u043a\u0430\u0436\u0443 \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 API, \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0438 \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0434\u0435\u043b\u043e\u043a. \u041f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u0442\u0435\u043c, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u0438\u0440\u0436\u0430\u043c\u0438 \u0438 \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0442\u0440\u043e\u0433\u0430\u0442\u044c \u0436\u0438\u0432\u043e\u0433\u043e \u0431\u043e\u0442\u0430 \u0440\u0443\u043a\u0430\u043c\u0438.<\/p>\n<hr\/>\n<h3>\ud83d\udccc \u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Bollinger Bands?<\/h3>\n<p>\u041f\u043e\u043b\u043e\u0441\u044b \u0411\u043e\u043b\u043b\u0438\u043d\u0434\u0436\u0435\u0440\u0430 \u2014 \u044d\u0442\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0435\u0439 \u0441\u0440\u0435\u0434\u043d\u0435\u0439 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c \u043e\u0442\u043a\u043b\u043e\u043d\u0435\u043d\u0438\u0438. \u041f\u043e \u0441\u0443\u0442\u0438:<\/p>\n<ul>\n<li>\n<p><strong>\u0421\u0435\u0440\u0435\u0434\u0438\u043d\u0430 (middle)<\/strong>: \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0441\u043a\u043e\u043b\u044c\u0437\u044f\u0449\u0430\u044f \u0441\u0440\u0435\u0434\u043d\u044f\u044f (\u043e\u0431\u044b\u0447\u043d\u043e 20 \u043f\u0435\u0440\u0438\u043e\u0434\u043e\u0432).<\/p>\n<\/li>\n<li>\n<p><strong>\u0412\u0435\u0440\u0445\u043d\u044f\u044f \u043f\u043e\u043b\u043e\u0441\u0430 (upper)<\/strong>: SMA + 2 * std.<\/p>\n<\/li>\n<li>\n<p><strong>\u041d\u0438\u0436\u043d\u044f\u044f \u043f\u043e\u043b\u043e\u0441\u0430 (lower)<\/strong>: SMA &#8212; 2 * std.<\/p>\n<\/li>\n<\/ul>\n<p>\u0418\u0434\u0435\u044f: \u043f\u043e\u043a\u0443\u043f\u0430\u0442\u044c \u043f\u0440\u0438 \u043a\u0430\u0441\u0430\u043d\u0438\u0438 \u043d\u0438\u0436\u043d\u0435\u0439 \u043f\u043e\u043b\u043e\u0441\u044b \u0438 \u043f\u0440\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438 \u043a\u0430\u0441\u0430\u043d\u0438\u0438 \u0432\u0435\u0440\u0445\u043d\u0435\u0439. \u0422\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0441\u0434\u0435\u043b\u043e\u043a, \u0442\u0430\u043a \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430 \u0442\u043e\u043b\u044c\u043a\u043e \u0441 BB \u0434\u0430\u0441\u0442 \u043f\u043b\u043e\u0445\u043e\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<hr\/>\n<h3>\ud83d\udd0d \u0414\u0440\u0443\u0433\u0438\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b <\/h3>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0436\u0435 \u0434\u043e\u043f \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b. \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u0449\u0438\u0435:<\/p>\n<h4>1. RSI (Relative Strength Index)<\/h4>\n<ul>\n<li>\n<p>\u041c\u043e\u043c\u0435\u043d\u0442\u0443\u043c-\u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440, \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c\/\u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c.<\/p>\n<\/li>\n<li>\n<p>RSI &lt; 30 \u2014 \u043f\u0435\u0440\u0435\u043f\u0440\u043e\u0434\u0430\u043d\u043d\u043e\u0441\u0442\u044c (\u043b\u043e\u043d\u0433), RSI &gt; 70 \u2014 \u043f\u0435\u0440\u0435\u043a\u0443\u043f\u043b\u0435\u043d\u043d\u043e\u0441\u0442\u044c (\u0448\u043e\u0440\u0442)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0442\u043b\u0438\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043f\u0430\u0440\u0435 \u0441 Bollinger Bands<\/p>\n<\/li>\n<\/ul>\n<h4>2. EMA (Exponential Moving Average)<\/h4>\n<ul>\n<li>\n<p>\u0411\u044b\u0441\u0442\u0440\u0430\u044f \u0440\u0435\u0430\u043a\u0446\u0438\u044f \u043d\u0430 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0444\u0438\u043b\u044c\u0442\u0440 \u0442\u0440\u0435\u043d\u0434\u0430: \u0446\u0435\u043d\u0430 \u0432\u044b\u0448\u0435 EMA \u2192 \u043f\u0440\u0438\u043e\u0440\u0438\u0442\u0435\u0442 \u043b\u043e\u043d\u0433<\/p>\n<\/li>\n<\/ul>\n<h4>3. ATR (Average True Range)<\/h4>\n<ul>\n<li>\n<p>\u0418\u0437\u043c\u0435\u0440\u044f\u0435\u0442 \u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u044c<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043f-\u043b\u043e\u0441\u0441\u0430 \u0438\u043b\u0438 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u0438\u0437\u043a\u043e\u0432\u043e\u043b\u0430\u0442\u0438\u043b\u044c\u043d\u044b\u0445 \u0443\u0447\u0430\u0441\u0442\u043a\u043e\u0432<\/p>\n<\/li>\n<\/ul>\n<h4>4. CSI \/ CSC (Cluster Strength Index \/ Cluster Signal Confirmation)<\/h4>\n<ul>\n<li>\n<p>\u0418\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u0435\u0447\u0435\u0439 \u0438 \u043f\u043b\u043e\u0442\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0435\u043d\u0438\u044f \u043d\u0430\u043c\u0435\u0440\u0435\u043d\u0438\u044f \u0446\u0435\u043d\u044b \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u0432 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u0432 \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u0438\u0445 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u044f\u0445 \u0441 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<h3>\ud83d\udee0\ufe0f \u0427\u0442\u043e \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c<\/h3>\n<ul>\n<li>\n<p><code>requests<\/code> \u2014 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c.<\/p>\n<\/li>\n<li>\n<p><code>pybit<\/code> \u2014 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 API Bybit.<\/p>\n<\/li>\n<li>\n<p><code>pandas<\/code>, <code>numpy<\/code> \u2014 \u0440\u0430\u0441\u0447\u0451\u0442\u044b \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u0430.<\/p>\n<\/li>\n<li>\n<p><code>datetime<\/code>, <code>time<\/code> \u2014 \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<\/li>\n<li>\n<p><code>threading<\/code> \u2014 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438.<\/p>\n<\/li>\n<li>\n<p><code>telebot<\/code> (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e) \u2014 \u0434\u043b\u044f \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u0432 Telegram.<\/p>\n<\/li>\n<\/ul>\n<h3>\ud83d\udcc1 \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430<\/h3>\n<pre><code class=\"python\">bollinger_bot\/ \u251c\u2500\u2500 main.py              # \u041e\u0441\u043d\u043e\u0432\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 \u251c\u2500\u2500 back.py              # \u0422\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0430\u0442\u0435\u0433\u0438\u0438 \u043d\u0430 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u251c\u2500\u2500 config.cfg           # \u043a\u043e\u043d\u0444\u0438\u0433 \u0444\u0430\u0439\u043b \u0441 \u043d\u0430\u0439\u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 (\u043e\u043f\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e)<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u043a\u043e\u0434. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b \u043f\u043e\u043a\u0430 \u0432\u044b\u0431\u0435\u0440\u0435\u043c \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442. \u0412\u043e\u0442 \u043b\u0443\u0447\u0448\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0433, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f \u043d\u0430\u0448\u0435\u043b \u0437\u0430 \u0432\u0440\u0435\u043c\u044f \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"python\">import pandas as pd import numpy as np import time import datetime from collections import deque from scipy.stats import zscore from binance.client import Client as BinanceClient from pybit.unified_trading import HTTP import telebot # === \u041d\u0410\u0421\u0422\u0420\u041e\u0419\u041a\u0418 ===  symbol = \"ETHUSDT\" interval = \"5m\"  bb_period = 40 bb_std = 1  STOP_LOSS_PCT = 0.004  client = BinanceClient()  config = {     'min_cluster': 3,     'bull_quant': 0.75,     'bear_quant': 0.25,     'rsi': 60 }<\/code><\/pre>\n<h3>\ud83d\udcc8 \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c <code>pybit<\/code> \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0441\u0432\u0435\u0447\u0438:<\/p>\n<pre><code class=\"python\">def fetch_klines_paged(symbol=symbol, interval=interval, total_bars=100000, client=None):     if client is None:         client = Client()      limit = 1000     data = []     end_time = int(time.time() * 1000)      while len(data) &lt; total_bars:         bars_to_fetch = min(limit, total_bars - len(data))         try:             klines = client.futures_klines(symbol=symbol, interval=interval, limit=bars_to_fetch, endTime=end_time)         except Exception as e:             print(\"\u041e\u0448\u0438\u0431\u043a\u0430 Binance API:\", e)             break          if not klines:             break          data = klines + data         end_time = klines[0][0] - 1         time.sleep(0.2)      df = pd.DataFrame(data, columns=[         'timestamp', 'open', 'high', 'low', 'close', 'volume',         'close_time', 'quote_asset_volume', 'number_of_trades',         'taker_buy_base', 'taker_buy_quote', 'ignore'     ])     df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')     df[['open','high','low','close','volume']] = df[['open','high','low','close','volume']].astype(float)     df = df.drop_duplicates('timestamp').sort_values('timestamp').reset_index(drop=True)     return df<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 bybit \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0441\u0432\u0435\u0447\u0435\u0439 \u0438\u0437 \u0438\u0441\u0442\u043e\u0440\u0438\u0438. \u041e\u0434\u043d\u0430\u043a\u043e \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0435\u0441\u0442\u044c \u043b\u0438\u043c\u0438\u0442 \u0432 1500 \u0441\u0432\u0435\u0447\u0435\u0439. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u043d\u0435\u0434\u0440\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0443\u044e \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u0434\u043b\u044f \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0430. <\/p>\n<p>\u0425\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435\u043c \u0434\u043b\u044f \u0441\u0432\u0435\u0447\u0435\u0439 \u0443 \u043d\u0430\u0441 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f df. \u041f\u043e\u0437\u0436\u0435 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043f. \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0440\u0435\u0437\u0430\u0442\u044c \u0438\u0437 \u043d\u0435\u0435 \u0434\u043e 50000 \u0441\u0432\u0435\u0447\u0435\u0439, \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u043e\u0432. \u0423 \u0441\u0432\u0435\u0447\u0435\u0439 \u0435\u0441\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b:<\/p>\n<ol>\n<li>\n<p>timestamp &#8212; \u0432\u0440\u0435\u043c\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>open &#8212; \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>high &#8212; \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>low &#8212; \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>close &#8212; \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0441\u0432\u0435\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>volume &#8212; \u043e\u0431\u044c\u0451\u043c, \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043e\u043d \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d<\/p>\n<\/li>\n<\/ol>\n<h2>\u0420\u0430\u0441\u0447\u0451\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432<\/h2>\n<p>\u0432\u0441\u0435 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0443 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0435. \u0414\u043b\u044f \u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e, \u043f\u043e\u043a\u0430 \u0447\u0442\u043e \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u0441\u0443\u0445\u043e\u043c \u043a\u043e\u0434\u0435. \u0418\u0437 \u0432\u0430\u0436\u043d\u044b\u0445 \u0434\u0435\u0442\u0430\u043b\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <\/p>\n<ol>\n<li>\n<p>period = 450 \u0432 \u0440\u0430\u0441\u0447\u0451\u0442\u0435 RSI. \u042d\u0442\u043e\u0442 \u043f\u0435\u0440\u0438\u043e\u0434 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043d\u0430\u0438\u043b\u0443\u0447\u0448\u0438\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043d\u0430 ATR. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e \u0446\u0435\u043b\u0435\u0441\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u043d\u044c\u0448\u0438\u0435 \u0446\u0438\u0444\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043f\u043e \u0432\u0441\u0435\u0439 \u0434\u043b\u0438\u043d\u0435 \u0431\u0435\u043a\u0442\u0435\u0441\u0442\u0430 (\u0432 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 100000 \u0441\u0432\u0435\u0447\u0435\u0439 \u043f\u043e 5\u043c). \u041d\u043e \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u043c \u0431\u043e\u0442\u0435, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0431\u044b\u043b \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d \u0442\u0435\u0441\u0442\u0443, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0442\u043e\u0436\u0435 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u0432\u0435\u0447\u0438, \u0436\u0435\u043b\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e\u0436\u0435 50000-100000 \u0448\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0412 ATR.rolling() \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 14. \u042d\u0442\u043e \u0441\u0433\u043b\u0430\u0436\u0438\u0432\u0430\u043d\u0438\u0435, 14 &#8212; \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u0443\u0442 \u043e\u043d\u043e \u043c\u043d\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442. <\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"python\">def compute_rsi(df, period=450):     delta = df['close'].diff()     gain = delta.clip(lower=0)     loss = -delta.clip(upper=0)     avg_gain = gain.rolling(period, min_periods=1).mean()     avg_loss = loss.rolling(period, min_periods=1).mean()     rs = avg_gain \/ avg_loss     df['RSI'] = 100 - (100 \/ (1 + rs))     df['RSI'] = df['RSI'].fillna(method='bfill')     return df  def compute_csc(df, min_cluster, bull_quant, bear_quant):     bull_thr = df['CSI'].quantile(bull_quant)     bear_thr = df['CSI'].quantile(bear_quant)      df['sentiment'] = np.where(df['CSI'] &gt;= bull_thr, 'bull',                         np.where(df['CSI'] &lt;= bear_thr, 'bear', 'neutral'))     df['cluster_id'] = pd.Series(dtype='object')     curr_type, curr_start, length = None, None, 0      for i, s in df['sentiment'].items():         if s == curr_type and s in ['bull', 'bear']:             length += 1         else:             if curr_type in ['bull', 'bear'] and length &gt;= min_cluster:                 df.loc[curr_start:i-1, 'cluster_id'] = f\"{curr_type}_{curr_start}\"             if s in ['bull', 'bear']:                 curr_type, curr_start, length = s, i, 1             else:                 curr_type, length = None, 0      if curr_type in ['bull', 'bear'] and length &gt;= min_cluster:         df.loc[curr_start:df.index[-1], 'cluster_id'] = f\"{curr_type}_{curr_start}\"      return df  def compute_bollinger(df):     df['ma'] = df['close'].rolling(bb_period).mean()     df['std'] = df['close'].rolling(bb_period).std()     df['upper'] = df['ma'] + bb_std * df['std']     df['lower'] = df['ma'] - bb_std * df['std']     return df  def get_csi(df):     body = (df['close'] - df['open']).abs()     rng = (df['high'] - df['low']).replace(0, np.nan)     body_ratio = body \/ rng     direction = np.where(df['close'] &gt; df['open'], 1, -1)     vol_score = df['volume'] \/ df['volume'].rolling(50).max()     range_z = zscore(df['high'] - df['low']).clip(-3, 3)      tr = pd.DataFrame({         'hl': df['high'] - df['low'],         'hc': (df['high'] - df['close'].shift(1)).abs(),         'lc': (df['low'] - df['close'].shift(1)).abs()     }).max(axis=1)      atr = tr.rolling(14).mean().bfill()     df['CSI'] = direction * (0.5 * body_ratio + 0.3 * vol_score + 0.2 * range_z) \/ atr     return df<\/code><\/pre>\n<h2>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0443\u0441\u043b\u043e\u0432\u0438\u0435\u043c \u0432\u0445\u043e\u0434\u0430<\/h2>\n<p>\u0423\u0436\u0435 \u0440\u0430\u043d\u0435\u0435 \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u043a\u043e\u043d\u0444\u0438\u0433 \u0434\u043b\u044f \u0431\u043e\u0442\u0430. \u041a\u043e\u043d\u0444\u0438\u0433 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0440\u0430\u0441\u0447\u0451\u0442\u0430 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0432\u0445\u043e\u0434\u0430. \u041c\u043e\u0439 \u0431\u043e\u0442 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432 \u0434\u0432\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b &#8212; \u0438 \u0432 \u043b\u043e\u043d\u0433, \u0438 \u0432 \u0448\u043e\u0440\u0442. \u0412\u0430\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043b\u043e\u043d\u0433 \u043e\u0442\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 10-15% \u0447\u0430\u0449\u0435, \u0447\u0442\u043e \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e \u0441 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0438 \u0440\u044b\u043d\u043a\u0430 (\u0433\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043f\u0430\u0434\u0430\u0442\u044c \u0442\u044f\u0436\u0435\u043b\u0435\u0435, \u0447\u0435\u043c \u0440\u0430\u0441\u0442\u0438). <\/p>\n<pre><code class=\"python\">def check_signal_row(row, prev_row):     if np.isnan(row['lower']) or np.isnan(prev_row['CSI']) or np.isnan(row['CSI']):         return None     cluster = row['cluster_id']     if not isinstance(cluster, str):         return None      long_cond = (         row['close'] &lt; row['lower'] and         row['CSI'] &gt; 0 and row['CSI'] &gt; prev_row['CSI'] and         cluster.startswith('bull') and row['RSI'] &lt; config['rsi']     )     short_cond = (         row['close'] &gt; row['upper'] and         row['CSI'] &lt; 0 and row['CSI'] &lt; prev_row['CSI'] and         cluster.startswith('bear') and row['RSI'] &gt; (100 - config['rsi'])     )      if long_cond:         return 'buy'     elif short_cond:         return 'sell'     return None<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u043c\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u0430, \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u0434. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0441 \u0441\u0434\u0435\u043b\u043a\u0430\u043c\u0438, \u0433\u0434\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0441\u0438\u0433\u043d\u0430\u043b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0441\u0432\u0435\u0447\u0430\u043c\u0438 \u0432 csv \u0444\u0430\u0439\u043b:<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     df = fetch_klines_paged(symbol, interval, 100000, client)     df = compute_rsi(df)     df = compute_bollinger(df)     df = get_csi(df)     df = compute_csc(df, config['min_cluster'], config['bull_quant'], config['bear_quant'])      signals = [None]     for i in range(1, len(df)):         signals.append(check_signal_row(df.iloc[i], df.iloc[i - 1]))     df['signal'] = signals           in_position = False     entry_price = None     entry_index = None     position_type = None      completed_trades = []      for i in range(1, len(df)):         row = df.iloc[i]         signal = row['signal']          # === \u0412\u0445\u043e\u0434 \u0432 \u043f\u043e\u0437\u0438\u0446\u0438\u044e ===         if not in_position and signal in ['buy', 'sell']:             in_position = True             entry_index = i             entry_price = row['close']             position_type = 'long' if signal == 'buy' else 'short'             stop_price = (                 entry_price * (1 - STOP_LOSS_PCT) if position_type == 'long'                 else entry_price <\/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-469805","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469805","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=469805"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469805\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=469805"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=469805"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=469805"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}