NESESITO QUE ME HAGAN UN BOT CON ESTA INFORMACION EN PYTON

MQL5 Uzmanlar Python

Şartname


NESESITO QUE ME HAGAN UN BOT CON ESTA INFORMACION EN PYTON 









mport ccxt

import pandas as pd
import numpy as np
import ta

# Configuración de la API
exchange = ccxt.binance()  # Cambia a tu exchange preferido
symbol = 'BTC/USDT'  # Activo a operar
timeframe = '1h'  # Marco temporal
risk_percentage = 0.02  # Riesgo por operación
stop_loss_percentage = 0.02  # 2% stop loss
take_profit_percentage = 0.04  # 4% take profit

# Función para obtener datos históricos
def get_historical_data(symbol, timeframe):
    bars = exchange.fetch_ohlcv(symbol, timeframe)
    df = pd.DataFrame(bars, columns=['timestamp', 'open', 'high', 'low', 'close', 'volume'])
    df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')
    return df

# Función para calcular indicadores
def calculate_indicators(df):
    df['RSI'] = ta.momentum.RSIIndicator(df['close']).rsi()
    df['MACD'] = ta.trend.MACD(df['close']).macd()
    df['Signal'] = ta.trend.MACD(df['close']).macd_signal()
    df['OBV'] = ta.volume.OnBalanceVolumeIndicator(df['close'], df['volume']).on_balance_volume()
    df['Stochastic'] = ta.momentum.StochasticOscillator(df['high'], df['low'], df['close']).stoch()
    return df

# Estrategia de Trading
def strategy(df):
    last_row = df.iloc[-1]
    
    # Condiciones de compra
    if (last_row['RSI'] < 30) and (last_row['MACD'] > last_row['Signal']):
        return 'buy'
    
    # Condiciones de venta
    elif (last_row['RSI'] > 70) and (last_row['MACD'] < last_row['Signal']):
        return 'sell'
    
    return 'hold'

# Función de gestión de riesgo
def calculate_position_size(balance, risk_percentage):
    return balance * risk_percentage

# Función para ejecutar ordenes con stop loss y take profit
def execute_order(signal, position_size):
    market_price = exchange.fetch_ticker(symbol)['last']
    
    if signal == 'buy':
        # Ejecutar orden de compra
        order = exchange.create_market_order(symbol, 'buy', position_size)
        # Calcular niveles de stop loss y take profit
        stop_loss_price = market_price * (1 - stop_loss_percentage)
        take_profit_price = market_price * (1 + take_profit_percentage)
        
        # Establecer stop loss
        exchange.create_order(symbol, 'stop_market', 'sell', position_size, stop_loss_price)
        # Establecer take profit
        exchange.create_limit_order(symbol, 'sell', position_size, take_profit_price)

    elif signal == 'sell':
        # Ejecutar orden de venta
        order = exchange.create_market_order(symbol, 'sell', position_size)
        # Calcular niveles de stop loss y take profit
        stop_loss_price = market_price * (1 + stop_loss_percentage)
        take_profit_price = market_price * (1 - take_profit_percentage)
        
        # Establecer stop loss
        exchange.create_order(symbol, 'stop_market', 'buy', position_size, stop_loss_price)
        # Establecer take profit
        exchange.create_limit_order(symbol, 'buy', position_size, take_profit_price)

# Loop principal del bot
def run_bot():
    balance = exchange.fetch_balance()['total']['USDT']  # Ajusta según tu activo
    df = get_historical_data(symbol, timeframe)
    df = calculate_indicators(df)
    
    signal = strategy(df)
    
    if signal in ['buy', 'sell']:
        position_size = calculate_position_size(balance, risk_percentage)
        execute_order(signal, position_size)

# Ejecutar el bot
if _name_ == "_main_":
    run_bot()

Yanıtlandı

1
Geliştirici 1
Derecelendirme
(184)
Projeler
317
24%
Arabuluculuk
24
33% / 13%
Süresi dolmuş
23
7%
Çalışıyor
Yayınlandı: 3 kod
2
Geliştirici 2
Derecelendirme
(1)
Projeler
1
0%
Arabuluculuk
1
0% / 0%
Süresi dolmuş
0
Serbest
Benzer siparişler
Hello, I am looking for an experienced MQL5 and Web Developer to create a complete automated copy-trading infrastructure for MetaTrader 5 with a subscription/licensing system. The project consists of three main components: 1. MT5 Slave EA (Copiador): An Expert Advisor for MT5 that receives trading signals from a master account (via a web server, WebSockets, or a database like Firebase/MySQL) and replicates them

Proje bilgisi

Bütçe
30+ USD