import ccxt
import time
# initialize exchange API
exchange = ccxt.binance({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET_KEY'
})
# define trading parameters
symbol = 'BTC/USDT'
timeframe = '1m'
stop_loss = 0.02
take_profit = 0.04
quantity = 0.1
# define technical indicators
sma_short = exchange.fetch_ohlcv(symbol, timeframe)[-10:]
sma_long = exchange.fetch_ohlcv(symbol, timeframe)[-30:]
# define trading strategy
if sma_short[-1][4] > sma_long[-1][4]:
# if short-term SMA is above long-term SMA, buy
order = exchange.create_market_buy_order(symbol, quantity)
time.sleep(5)
# set stop-loss and take-profit orders
exchange.create_limit_sell_order(symbol, quantity, order['price']*(1+take_profit))
exchange.create_limit_sell_order(symbol, quantity, order['price']*(1-stop_loss))
elif sma_short[-1][4] < sma_long[-1][4]:
# if short-term SMA is below long-term SMA, sell
order = exchange.create_market_sell_order(symbol, quantity)
time.sleep(5)
# set stop-loss and take-profit orders
exchange.create_limit_buy_order(symbol, quantity, order['price']*(1-take_profit))
exchange.create_limit_buy_order(symbol, quantity, order['price']*(1+stop_loss))
# check for open orders and cancel if necessary
orders = exchange.fetch_open_orders(symbol)
for order in orders:
exchange.cancel_order(order['id'])
import time
# initialize exchange API
exchange = ccxt.binance({
'apiKey': 'YOUR_API_KEY',
'secret': 'YOUR_SECRET_KEY'
})
# define trading parameters
symbol = 'BTC/USDT'
timeframe = '1m'
stop_loss = 0.02
take_profit = 0.04
quantity = 0.1
# define technical indicators
sma_short = exchange.fetch_ohlcv(symbol, timeframe)[-10:]
sma_long = exchange.fetch_ohlcv(symbol, timeframe)[-30:]
# define trading strategy
if sma_short[-1][4] > sma_long[-1][4]:
# if short-term SMA is above long-term SMA, buy
order = exchange.create_market_buy_order(symbol, quantity)
time.sleep(5)
# set stop-loss and take-profit orders
exchange.create_limit_sell_order(symbol, quantity, order['price']*(1+take_profit))
exchange.create_limit_sell_order(symbol, quantity, order['price']*(1-stop_loss))
elif sma_short[-1][4] < sma_long[-1][4]:
# if short-term SMA is below long-term SMA, sell
order = exchange.create_market_sell_order(symbol, quantity)
time.sleep(5)
# set stop-loss and take-profit orders
exchange.create_limit_buy_order(symbol, quantity, order['price']*(1-take_profit))
exchange.create_limit_buy_order(symbol, quantity, order['price']*(1+stop_loss))
# check for open orders and cancel if necessary
orders = exchange.fetch_open_orders(symbol)
for order in orders:
exchange.cancel_order(order['id'])
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
