0% found this document useful (0 votes)
6 views2 pages

Python Trading - Script - Py

This document contains a Python script that connects to the Binance API to fetch 1-minute OHLCV data for the BTC/USDT trading pair. It calculates a Renko chart based on a specified traditional brick size and generates buy or sell signals depending on the price movements relative to a drawn line, which is only visible for a set duration if the trading volume exceeds a threshold. The script runs in a continuous loop, fetching data every minute and printing buy or sell signals accordingly.

Uploaded by

mobilekhan6969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Python Trading - Script - Py

This document contains a Python script that connects to the Binance API to fetch 1-minute OHLCV data for the BTC/USDT trading pair. It calculates a Renko chart based on a specified traditional brick size and generates buy or sell signals depending on the price movements relative to a drawn line, which is only visible for a set duration if the trading volume exceeds a threshold. The script runs in a continuous loop, fetching data every minute and printing buy or sell signals accordingly.

Uploaded by

mobilekhan6969
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import ccxt

import pandas as pd
import time

# Binance API keys


api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'

# Binance connection
exchange = ccxt.binance({
'apiKey': api_key,
'secret': api_secret,
})

# Trading parameters
symbol = 'BTC/USDT'
timeframe = '1m'
trad_size = 40 # Traditional Renko size
volume_threshold = 500 # Minimum volume for drawing line (in BTC)
line_duration_days = 2 # Duration for which the line should be valid

# Function to get Renko chart


def get_renko_chart(data, trad_size):
data['close_shift'] = data['close'].shift(1)
data['price_diff'] = abs(data['close'] - data['close_shift'])
data['bricks'] = data['price_diff'] // trad_size
data.drop(['close_shift', 'price_diff'], axis=1, inplace=True)
return data

# Function to check if the volume is above the threshold


def is_high_volume(data, volume_threshold):
return data['volume'].iloc[-1] >= volume_threshold

# Function to generate buy or sell signals based on Renko chart


def generate_signals(data):
data['buy_signal'] = data['close'] > data['line']
data['sell_signal'] = data['close'] < data['line']
return data

# Main loop
while True:
# Fetch 1-minute data
ohlcv = exchange.fetch_ohlcv(symbol, timeframe)
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close',
'volume'])
df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
df.set_index('timestamp', inplace=True)

# Check for high volume


if is_high_volume(df, volume_threshold):
# Draw line
line_price = df['close'].iloc[-1]
line_start_time = time.time()

# Check if the line should be visible


if time.time() - line_start_time < line_duration_days * 24 * 60 * 60:
df['line'] = line_price
else:
df['line'] = None
# Generate Renko chart
renko_df = get_renko_chart(df, trad_size)

# Generate signals
signals_df = generate_signals(renko_df)

# Print signals (replace with actual trading logic)


if signals_df['buy_signal'].iloc[-1]:
print("Buy Signal!")
elif signals_df['sell_signal'].iloc[-1]:
print("Sell Signal!")

# Sleep for a minute (adjust as needed)


time.sleep(60)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy