Bitcoin / TetherUS PERPETUAL CONTRACT

# Define your trading pair and timeframe symbol = 'BTC/USDT' tim

import ccxt
import pandas as pd
import time

# Initialize the Binance exchange API
exchange = ccxt.binance({
'apiKey': BTCUSDT.P 'HrTNX3qb64fYm1k9acw45Qy1bUBPDGHVhH43fESGg3UkysUAc1Yo7wwcLyXAEQT7',
'secret': 'M5vjVCyNaNoblpgMut2hcQwj9dbqfxSmGCL4jR78C5PaSiXrKyQi9MtOIHn3C4Y6',
})

# Define your trading pair and timeframe
symbol = 'BTC/USDT'
timeframe = '1h'

# Bollinger Bands parameters
period = 20 # Lookback period
std_dev = 2 # Standard deviation multiplier

while True:
# Fetch historical OHLCV data
ohlcv = exchange.fetch_ohlcv(symbol, timeframe, limit=period + 1)

# Create a pandas DataFrame
df = pd.DataFrame(ohlcv, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])

# Calculate Bollinger Bands
df['sma'] = df['close'].rolling(window=period).mean()
df['std'] = df['close'].rolling(window=period).std()
df['upper_band'] = df['sma'] + (df['std'] * std_dev)
df['lower_band'] = df['sma'] - (df['std'] * std_dev)

# Get the latest data
latest_data = df.iloc[-1]

# Check for buy/sell signals
if latest_data['close'] < latest_data['lower_band']:
# Place a buy order here
print('Bullish Buy Signal - Place Buy Order')

elif latest_data['close'] > latest_data['upper_band']:
# Place a sell order here
print('Bearish Sell Signal - Place Sell Order')

# Add a sleep to avoid overloading the exchange
time.sleep(60) # Sleep for 1 minute (adjust as needed)

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.