# Set up exchange and symbol exchange = ccxt.binance() symbol = 'EUR/USD'
# Set up MA parameters short_term_ma_period = 50 long_term_ma_period = 200
# Define the bot's logic def ma_crossover_bot(data): # Calculate short-term and long-term MA short_term_ma = data['close'].rolling(window=short_term_ma_period).mean() long_term_ma = data['close'].rolling(window=long_term_ma_period).mean()
# Check for buy signal if short_term_ma.iloc[-1] > long_term_ma.iloc[-1] and short_term_ma.iloc[-2] < long_term_ma.iloc[-2]: return 'Buy'
# Check for sell signal elif short_term_ma.iloc[-1] < long_term_ma.iloc[-1] and short_term_ma.iloc[-2] > long_term_ma.iloc[-2]: return 'Sell'
# No signal, do nothing else: return 'Do Nothing'
# Set up the bot to run on each new candle def run_bot(): data = exchange.fetch_ohlcv(symbol, timeframe='1m') df = pd.DataFrame(data, columns=['time', 'open', 'high', 'low', 'close', 'volume']) signal = ma_crossover_bot(df)
if signal == 'Buy': exchange.place_order(symbol, 'buy', 0.1) elif signal == 'Sell': exchange.place_order(symbol, 'sell', 0.1)
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.