xmd79

mtf dips/tops finder btc

Mar 28th, 2023
1,706
0
Never
12
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.73 KB | Cryptocurrency | 0 0
  1. import numpy as np
  2. from binance.client import Client
  3. from binance.enums import *
  4. import pandas as pd
  5.  
  6. # Load API key and secret from credentials.txt
  7. with open('credentials.txt', 'r') as f:
  8.     lines = f.readlines()
  9.     api_key = lines[0].strip()
  10.     api_secret = lines[1].strip()
  11.  
  12. # Connect to Binance Futures API
  13. client = Client(api_key, api_secret, testnet=False)
  14.  
  15. # Retrieve price data for USDTM on all timeframes
  16. symbols = ['BTCUSDT']
  17. timeframes = ['1d', '4h', '1h', '15m', '5m']
  18. prices = {}
  19. for symbol in symbols:
  20.     for timeframe in timeframes:
  21.         klines = client.futures_klines(symbol=symbol, interval=timeframe, limit=1000)
  22.         df = pd.DataFrame(klines, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume', 'close_time', 'quote_asset_volume', 'trades', 'taker_buy_base_asset_volume', 'taker_buy_quote_asset_volume', 'ignore'])
  23.         df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
  24.         df.set_index('timestamp', inplace=True)
  25.         prices[(symbol, timeframe)] = df
  26.  
  27. # Perform polynomial fit analysis for all timeframes
  28. for symbol in symbols:
  29.     for timeframe in timeframes:
  30.         df = prices[(symbol, timeframe)]
  31.         x = df['close'].astype(float).values
  32.         y = np.arange(len(x)).astype(float)
  33.         best_fit_line1 = np.poly1d(np.polyfit(y, x, 1))(y)
  34.         best_fit_line2 = np.poly1d(np.polyfit(y, x, 1))(y) * 1.01
  35.         best_fit_line3 = np.poly1d(np.polyfit(y, x, 1))(y) * 0.99
  36.         # Determine if the close price is below the lowest line
  37.         if df['close'].astype(float)[-1] < min(best_fit_line1[-1], best_fit_line2[-1], best_fit_line3[-1]):
  38.             print(f"{symbol} {timeframe}: DIP")
  39.         else:
  40.             print(f"{symbol} {timeframe}: TOP")
  41.  
Advertisement
Comments
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment