Zyon

指定

import MetaTrader5 as mt5
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from backtrader import Cerebro

# Connect to MetaTrader 5
mt5.initialize()

# Function to fetch historical data from MT5
def get_historical_data(symbol, timeframe, num_bars):
    rates = mt5.copy_rates_from_pos(symbol, timeframe, 0, num_bars)
    df = pd.DataFrame(rates)
    df['time'] = pd.to_datetime(df['time'], unit='s')
    return df

# Fetch XAUUSD data
symbol = "XAUUSD"
data = get_historical_data(symbol, mt5.TIMEFRAME_M1, 10000)

# Prepare features for the AI model
X = np.array([data['open'], data['close'], data['high'], data['low']]).T
y = np.array([1 if data['close'][i] > data['open'][i] else 0 for i in range(len(data))])

# Split data for AI model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# Train a Random Forest model
model = RandomForestClassifier()
model.fit(X_train, y_train)

# Make predictions on test data
predictions = model.predict(X_test)

# Add Moving Average Strategy to DataFrame (EMA12 and EMA26)
data['EMA_12'] = data['close'].ewm(span=12, adjust=False).mean()
data['EMA_26'] = data['close'].ewm(span=26, adjust=False).mean()
data['Signal'] = np.where(data['EMA_12'] > data['EMA_26'], 1, -1)

# Risk management (stop loss, take profit)
def place_trade(symbol, order_type, volume, stop_loss, take_profit):
    ask_price = mt5.symbol_info_tick(symbol).ask
    bid_price = mt5.symbol_info_tick(symbol).bid
    if order_type == "buy":
        mt5.order_send(symbol=symbol, action=mt5.TRADE_ACTION_DEAL, order_type=mt5.ORDER_TYPE_BUY, volume=volume, price=ask_price, sl=stop_loss, tp=take_profit)
    elif order_type == "sell":
        mt5.order_send(symbol=symbol, action=mt5.TRADE_ACTION_DEAL, order_type=mt5.ORDER_TYPE_SELL, volume=volume, price=bid_price, sl=stop_loss, tp=take_profit)

# Example trade (modify parameters as needed)
place_trade(symbol, "buy", 0.1, 5, 10)

# Backtesting Setup with Backtrader
class MyStrategy(bt.Strategy):
    def __init__(self):
        self.ema12 = bt.indicators.ExponentialMovingAverage(self.data.close, period=12)
        self.ema26 = bt.indicators.ExponentialMovingAverage(self.data.close, period=26)

    def next(self):
        if self.ema12 > self.ema26:
            self.buy(size=1)
        elif self.ema12 < self.ema26:
            self.sell(size=1)

# Backtest function
def run_backtest(data):
    cerebro = Cerebro()
    cerebro.addstrategy(MyStrategy)
    # Add your data feed here
    cerebro.run()

# Convert MT5 data to Backtrader data feed format if needed
# run_backtest(data)

# Shutdown MT5 connection
mt5.shutdown()

反馈

1
开发者 1
等级
项目
0
0%
仲裁
0
逾期
0
空闲
2
开发者 2
等级
(2)
项目
5
0%
仲裁
3
0% / 100%
逾期
3
60%
空闲
3
开发者 3
等级
(11)
项目
26
27%
仲裁
3
0% / 0%
逾期
1
4%
已载入
相似订单
I'm planning on building/creating an mt4/5 trading indicator that use a break and retest strategy I will share a link for the idea strategy, Kindly message me to send you the link, I can't send it here
We are seeking an experienced developer to create a custom Expert Advisor (EA) for Forex trading, integrating Artificial Intelligence (AI). The EA should be capable of autonomously analyzing data, reading news feeds, and making intelligent trading decisions. Responsibilities: - Develop a Forex trading EA with AI integration. - The EA must fetch and analyze news from trusted sources to inform trading decisions. -
we will use this script( News365 – PHP Newspaper Script Magazine Blog with Video Newspaper by bdtask (codecanyon.net) ) or anything better to clone this website( European Central Bank (europa.eu) ) I want everything exactly the same as the above-mentioned website ---------------------------------------------------------------- I ---------------------------------------------------------------- I
I have some specific conditions that i want to check during FVG, OB, BB, MSS, BOS, etc. but lets tell them in private if you will choose to work with me
I am seeking a custom trading robot/EA for MetaTrader 5, based on a proprietary strategy utilizing various technical indicators. Indicators: Vigor XProfuter/Maxwell's Equation Indicator Heiken Ashi Candlesticks Please ensure the trading robot/EA is fully functional, reliable, and compatible with MetaTrader 5. Additionally, clear documentation and support for any adjustments or optimizations in the future would be
I need an indicator like the one of the two photos that print on current candle 0, or pre alert 60% win rate minimum for mt5 or 4 I would like too trail until Friday as this is when I get paid pls
I do have file made by someone but we are not working together so i like to know if you can help me to run this setup on my forexvps.net server and do changes as per my need
I want to turn the attached trade into a bot. It may be a little hard to udnerstand, in simple terms I want to trade at a turn around point following a fair value gap. I may want to add two switches: Buy / sell only Only trade within zone x-y these additions will allow me to check fundamentals for buy/or sell, and then only trade when im in support/resistance. You may know a better more profitable way of going about
Hello I have a piece of python code that connects telegram and pocket option, I need help running it and will update it before tomorrow speed is paramount.We can use anydesk for to connect my pocket option with telegram basically run the code, once that is done will give 2 updates on the code
I need to create an EA based on my own strategy that actually is a little bit different from most of the usual EA. This because it use an indicator but the power of the system is just because it can shows target price by designing trendline on the price chart in a unusual way. A friend of mine tried to create it on MT4 platform but, in the end, he realized that this platform has big limits when the program lines

项目信息

预算
50 - 500 USD

客户

所下订单1
仲裁计数0