├── README.md └── signals.py /README.md: -------------------------------------------------------------------------------- 1 | # advansed-crypto-signal-bot 2 | ![изображение](https://github.com/user-attachments/assets/fe8b1609-523a-4e52-b0ad-75d814cb799d) 3 | This code detects divergence between price and RSI. The last three values of price and RSI are considered. If price and the indicator change in different directions, this may signal divergence: 4 | 5 | Bullish Divergence: Price is falling, while RSI is rising. 6 | 7 | Bearish Divergence: Price is rising, while RSI is falling. The strength of the divergence is also determined based on the difference between the RSI values over the last two periods: weak (less than 5), moderate (5 to 10) 8 | and strong (greater than 10). 9 | 10 | Thus, this script helps automate cryptocurrency market monitoring, track potential trading signals based on price and RSI changes, and identify possible divergences. 11 | 12 | Define the list of coins you want to track in the COINS variable. 13 | 14 | Set the desired time frame, RSI period, and overbought/oversold levels. 15 | 16 | Run the script, and it will print trading signals based on divergence and RSI levels for the selected coins. 17 | 18 | Notes: 19 | RSI (Relative Strength Index): The script checks whether the RSI value is in the overbought (> 70) or oversold (< 30) zone and prints that information. 20 | 21 | Divergence: It looks for a discrepancy between price movement and RSI to identify possible bullish or bearish trends. 22 | 23 | ATR: The script uses a simple method based on standard deviation to approximate the Average True Range (ATR) and determine volatility. 24 | 25 | Compiled version with 4h timeframe(default): https://github.com/lucaswrao/crypto-signal-bot/releases/download/crypto/signals.zip 26 | 27 | 28 | -------------------------------------------------------------------------------- /signals.py: -------------------------------------------------------------------------------- 1 | import ccxt 2 | import time 3 | 4 | # Initialize Binance API (No API Key needed for public data) 5 | exchange = ccxt.binance() 6 | 7 | # List of cryptocurrency pairs 8 | COINS = ["BTC/USDT", "ETH/USDT", "SOL/USDT", "ADA/USDT", "XRP/USDT", "BNB/USDT", "DOGE/USDT", "SHIB/USDT", "TRX/USDT", "TRUMP/USDT"] 9 | 10 | # RSI Parameters 11 | TIMEFRAME = "3m" # Binance supports 8-hour timeframe 12 | RSI_PERIOD = 14 # RSI calculation period 13 | OVERBOUGHT = 70 14 | OVERSOLD = 30 15 | 16 | 17 | def fetch_ohlcv(symbol): 18 | """Fetch OHLCV data from Binance.""" 19 | try: 20 | return exchange.fetch_ohlcv(symbol, timeframe=TIMEFRAME, limit=RSI_PERIOD + 5) 21 | except Exception as e: 22 | print(f"Error fetching OHLCV for {symbol}: {e}") 23 | return None 24 | 25 | 26 | def calculate_rsi(prices): 27 | """Calculate RSI based on closing prices.""" 28 | if len(prices) < RSI_PERIOD + 1: 29 | return None # Not enough data 30 | 31 | gains, losses = [], [] 32 | for i in range(1, RSI_PERIOD + 1): 33 | change = prices[i] - prices[i - 1] 34 | gains.append(max(change, 0)) 35 | losses.append(abs(min(change, 0))) 36 | 37 | avg_gain = sum(gains) / RSI_PERIOD 38 | avg_loss = sum(losses) / RSI_PERIOD 39 | 40 | if avg_loss == 0: 41 | return 100 # Avoid division by zero, assume max RSI 42 | 43 | rs = avg_gain / avg_loss 44 | rsi = 100 - (100 / (1 + rs)) 45 | 46 | return round(rsi, 2) 47 | 48 | 49 | def fetch_rsi(symbol): 50 | """Fetch RSI indicator for a given cryptocurrency pair from Binance.""" 51 | ohlcv = fetch_ohlcv(symbol) 52 | if not ohlcv: 53 | return None 54 | 55 | prices = [candle[4] for candle in ohlcv] # Closing prices 56 | return calculate_rsi(prices) 57 | 58 | 59 | def fetch_price(symbol): 60 | """Fetch the latest price for a given cryptocurrency pair.""" 61 | try: 62 | ticker = exchange.fetch_ticker(symbol) 63 | return ticker['last'] 64 | except Exception as e: 65 | print(f"Error fetching price for {symbol}: {e}") 66 | return None 67 | 68 | 69 | def detect_divergence(symbol): 70 | """Определяет дивергенцию и ее силу""" 71 | ohlcv = fetch_ohlcv(symbol) 72 | if not ohlcv: 73 | return None 74 | 75 | prices = [candle[4] for candle in ohlcv] # Закрытые цены 76 | rsi_values = [calculate_rsi(prices[i:i + RSI_PERIOD + 1]) for i in range(len(prices) - RSI_PERIOD)] 77 | rsi_values = [rsi for rsi in rsi_values if rsi is not None] 78 | 79 | if len(rsi_values) < 3: 80 | return None 81 | 82 | recent_prices = prices[-3:] 83 | recent_rsi = rsi_values[-3:] 84 | 85 | price_change = abs(recent_prices[2] - recent_prices[0]) 86 | rsi_change = abs(recent_rsi[2] - recent_rsi[0]) 87 | 88 | # Классификация по разнице RSI 89 | if rsi_change >= 10: 90 | strength = "Strong 💪" 91 | elif rsi_change >= 5: 92 | strength = "Moderate ⚖" 93 | else: 94 | strength = "Weak ❌" 95 | 96 | # Бычья дивергенция 97 | if recent_prices[0] > recent_prices[2] and recent_rsi[0] < recent_rsi[2]: 98 | return f"Bullish Divergence 🟢 ({strength})" 99 | 100 | # Медвежья дивергенция 101 | if recent_prices[0] < recent_prices[2] and recent_rsi[0] > recent_rsi[2]: 102 | return f"Bearish Divergence 🔴 ({strength})" 103 | 104 | return "No Divergence" 105 | 106 | 107 | 108 | def check_rsi_signals(): 109 | """Fetch RSI and price, then print buy/sell signals and divergence.""" 110 | print("\n=== RSI SIGNAL BOT (BINANCE) ===\n") 111 | 112 | for symbol in COINS: 113 | rsi = fetch_rsi(symbol) 114 | price = fetch_price(symbol) 115 | divergence = detect_divergence(symbol) 116 | 117 | if rsi is None or price is None: 118 | print(f"{symbol}: Unable to retrieve RSI or price data\n") 119 | continue 120 | 121 | signal = "NEUTRAL" 122 | if rsi < OVERSOLD: 123 | signal = "BUY 📈 (Oversold)" 124 | elif rsi > OVERBOUGHT: 125 | signal = "SELL 📉 (Overbought)" 126 | 127 | print(f"{symbol} - Price: ${price:.2f} | RSI: {rsi} | Signal: {signal} | {divergence}\n") 128 | 129 | 130 | while True: 131 | check_rsi_signals() 132 | time.sleep(20) 133 | --------------------------------------------------------------------------------