In [1]:
# ----------------------------------------------------
# 0. Bibliotheken importieren
import ccxt
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime, timedelta, timezone
In [2]:
# ----------------------------------------------------
# 1. Binance initialisieren
exchange = ccxt.binance()
In [3]:
# ----------------------------------------------------
# 2. Dynamisches 'since' (3 Jahre zurück)
days_back = 3 * 365
since_ms = int((datetime.now(timezone.utc) - timedelta(days=days_back)).timestamp() * 1000)
In [4]:
# ----------------------------------------------------
# 3. Daten abrufen & aufbereiten
def fetch_ohlcv_since(symbol='ETH/USDT', timeframe='1d', since=since_ms):
    all_rows, since_ptr = [], since
    while True:
        rows = exchange.fetch_ohlcv(symbol, timeframe, since=since_ptr, limit=1000)
        if not rows:
            break
        all_rows += rows
        since_ptr = rows[-1][0] + 1
        if len(rows) < 1000:
            break

    df = pd.DataFrame(all_rows, columns=['timestamp','open','high','low','close','volume_eth'])
    df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms', utc=True)

    # Volumenberechnung
    df['volume_usd'] = df['volume_eth'] * df['close']
    df['volume_usd_mio'] = df['volume_usd'] / 1e6
    df['volume_usd_fmt'] = df['volume_usd_mio'].apply(lambda x: f"{x:,.2f} Mio $")
    df['volume_eth_fmt'] = df['volume_eth'].apply(lambda x: f"{x:,.2f} ETH")

    return df
In [5]:
# ----------------------------------------------------
# 4. Daten laden
df = fetch_ohlcv_since()
In [9]:
# ----------------------------------------------------
# 5. RSI & MA50 berechnen
delta = df['close'].diff()
gain = delta.where(delta > 0, 0)
loss = -delta.where(delta < 0, 0)
avg_gain = gain.rolling(window=14).mean()
avg_loss = loss.rolling(window=14).mean()
rs = avg_gain / avg_loss
df['RSI'] = 100 - (100 / (1 + rs))

df['MA50'] = df['close'].rolling(window=50).mean()
In [7]:
# ----------------------------------------------------
# 6. BUY / SELL Signale definieren (angepasste Logik)
df['signal'] = 'HOLD'
df.loc[(df['RSI'] < 45) & (df['close'] > df['MA50']), 'signal'] = 'BUY'
df.loc[(df['RSI'] > 55) & (df['close'] < df['MA50']), 'signal'] = 'SELL'

# Übersicht
print(df['signal'].value_counts())
signal
HOLD    979
BUY      60
SELL     56
Name: count, dtype: int64
In [12]:
import ta# RSI und MA berechnen
df['RSI'] = ta.momentum.RSIIndicator(close=df['close']).rsi()
df['MA50'] = df['close'].rolling(window=50).mean()
df['MA200'] = df['close'].rolling(window=200).mean()
df.tail()
Out[12]:
timestamp open high low close volume_eth volume_usd volume_usd_mio volume_usd_fmt volume_eth_fmt RSI MA50 signal MA200
1090 2025-06-10 00:00:00+00:00 2680.13 2827.00 2655.61 2816.40 1.138405e+06 3.206205e+09 3206.205187 3,206.21 Mio $ 1,138,405.48 ETH 67.169034 2312.3156 HOLD 2657.78485
1091 2025-06-11 00:00:00+00:00 2816.41 2879.22 2743.75 2771.61 8.502109e+05 2.356453e+09 2356.453122 2,356.45 Mio $ 850,210.93 ETH 63.942553 2332.6226 HOLD 2654.67335
1092 2025-06-12 00:00:00+00:00 2771.60 2784.83 2616.24 2642.65 6.995934e+05 1.848780e+09 1848.780434 1,848.78 Mio $ 699,593.38 ETH 55.653396 2349.5742 HOLD 2651.08060
1093 2025-06-13 00:00:00+00:00 2642.66 2645.45 2436.98 2579.19 1.202176e+06 3.100641e+09 3100.641084 3,100.64 Mio $ 1,202,176.30 ETH 52.075840 2365.7650 HOLD 2646.90410
1094 2025-06-14 00:00:00+00:00 2579.19 2579.43 2518.51 2536.09 1.405074e+05 3.563393e+08 356.339332 356.34 Mio $ 140,507.37 ETH 49.737331 2380.7948 HOLD 2642.96090
In [13]:
# Kurs und gleitende Durchschnitte
plt.figure(figsize=(14,6))
plt.plot(df['timestamp'], df['close'], label='Close')
plt.plot(df['timestamp'], df['MA50'], label='MA50')
plt.plot(df['timestamp'], df['MA200'], label='MA200')
plt.title('ETH/USDT Preis & MA – Tageschart')
plt.xlabel('Datum')
plt.ylabel('Preis (USDT)')
plt.legend()
plt.grid(True)
plt.show()
No description has been provided for this image
In [14]:
# RSI Plot
plt.figure(figsize=(14,4))
plt.plot(df['timestamp'], df['RSI'], label='RSI')
plt.axhline(30, color='green', linestyle='--', label='Überverkauft')
plt.axhline(70, color='red', linestyle='--', label='Überkauft')
plt.title('RSI – ETH/USDT')
plt.legend()
plt.grid(True)
plt.show()
No description has been provided for this image
In [8]:
# ----------------------------------------------------
# 7. Chart mit Signalen
plt.figure(figsize=(14,6))
plt.plot(df['timestamp'], df['close'], label='Close Price')
plt.plot(df['timestamp'], df['MA50'], label='MA50')

buy_signals = df[df['signal'] == 'BUY']
sell_signals = df[df['signal'] == 'SELL']

plt.scatter(buy_signals['timestamp'], buy_signals['close'], label='BUY', marker='^', color='green')
plt.scatter(sell_signals['timestamp'], sell_signals['close'], label='SELL', marker='v', color='red')

plt.title("Swing Trading Signale (angepasst)")
plt.xlabel("Datum")
plt.ylabel("Preis")
plt.legend()
plt.grid(True)
plt.show()
No description has been provided for this image
In [15]:
File > Download as > HTML (.html)
  Cell In[15], line 1
    File > Download as > HTML (.html)
                    ^
SyntaxError: invalid syntax
In [ ]: