xmd79

mtf dips/tops finder template

Mar 14th, 2023
827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.05 KB | Cryptocurrency | 0 0
  1. from binance.client import Client
  2. import numpy as np
  3. import matplotlib.pyplot as plt
  4.  
  5.  
  6. class Trader:
  7.     def __init__(self, file):
  8.         self.connect(file)
  9.  
  10.     def connect(self, file):
  11.         lines = [line.rstrip('\n') for line in open(file)]
  12.         self.key = lines[0]
  13.         self.secret = lines[1]
  14.         self.client = Client(self.key, self.secret)
  15.  
  16.        
  17. class TechnicalAnalyzer:
  18.     def __init__(self, client):
  19.         self.client = client
  20.  
  21.     def get_historical_data(self, symbol, interval):
  22.         klines = self.client.get_historical_klines(symbol, interval, '1 year ago')
  23.         close_prices = [float(entry[4]) for entry in klines]
  24.         return close_prices
  25.  
  26.     def fit_line(self, data):
  27.         y = np.array(data)
  28.         x = np.arange(len(y))
  29.         z = np.polyfit(x, y, 1)
  30.         p = np.poly1d(z)
  31.         return p(x)
  32.    
  33.     def identify_dip(self, symbol):
  34.         close_prices = self.get_historical_data(symbol, '1d')
  35.         fit_line = self.fit_line(close_prices)
  36.  
  37.         if close_prices[-1] < fit_line[-1] and fit_line[0] <= fit_line[-1]:
  38.             print(f'{symbol}: Dip found on daily timeframe')
  39.             return True
  40.        
  41.         return False
  42.    
  43.     def identify_top(self, symbol):
  44.         close_prices = self.get_historical_data(symbol, '1d')
  45.         fit_line = self.fit_line(close_prices)
  46.  
  47.         if close_prices[-1] > fit_line[-1] and fit_line[0] >= fit_line[-1]:
  48.             print(f'{symbol}: Top found on daily timeframe')
  49.             return True
  50.        
  51.         return False
  52.  
  53.  
  54. filename = 'credentials.txt'
  55. trader = Trader(filename)
  56. analyzer = TechnicalAnalyzer(trader.client)
  57.  
  58. trading_pairs = ['BTCBUSD', 'BNBBUSD', 'DOGEBUSD', 'AVAXBUSD', 'ADABUSD', 'SOLBUSD']
  59.  
  60. for pair in trading_pairs:
  61.     if analyzer.identify_dip(pair):
  62.         if analyzer.identify_dip(pair):
  63.             print(f'{pair}: Dip confirmed on 4h timeframe')
  64.            
  65.     elif analyzer.identify_top(pair):
  66.         if analyzer.identify_top(pair):
  67.             print(f'{pair}: Top confirmed on 4h timeframe')
  68.  
Advertisement
Add Comment
Please, Sign In to add comment