Pythonを使用してストラテジーテスターを実行したいがMT5にログインできない

 
 

以下のPythonコードでMT5のストラテジーテスターを実行したいのですが、MT5へのログインがうまくいかないようです。コードに不備等ありますでしょうか?アドバイス頂ければ幸いです。

import MetaTrader5 as mt5
import pandas as pd
import os
import time
from datetime import datetime

# MetaTrader 5に接続
login = 
12345678 
password = "your_password"
server = "broker_server"


if not mt5.initialize(login=login, password=password, server=server):
    print("MetaTrader 5 initialization failed, error code =", mt5.last_error())
    mt5.shutdown()
    exit()

# テストする通貨ペアとパラメータを設定
symbol = "EURUSD"
short_window = 10
long_window = 100

# データの取得期間を設定
utc_from = datetime(2023, 1, 1)
utc_to = datetime(2023, 12, 31)

# ストラテジーテスターの設定ファイルを生成
def create_test_config(symbol, short_window, long_window):
    config_content = f"""
[Test]
Expert=SMA_Cross
Symbol={symbol}
Period=H1
FromDate=2023.01.01
ToDate=2023.12.31
Optimization=0
Inputs=FastSMA={short_window};SlowSMA={long_window};
Deposit=10000
"""
    with open("tester.ini", "w") as file:
        file.write(config_content)

# ストラテジーテスターの実行
def run_strategy_tester():
    command = r'"C:\\Program Files\\Titan FX MetaTrader 5\\terminal64.exe" /portable /config:tester.ini'
    os.system(command)

# データフォルダのパスを設定
data_folder = 'data'
if not os.path.exists(data_folder):
    os.makedirs(data_folder)

print(f"Running test for {symbol} with FastSMA={short_window} and SlowSMA={long_window}")
create_test_config(symbol, short_window, long_window)
run_strategy_tester()

# 結果ファイルが生成されるまで待機
results_file = f"C:\\Program Files\\Titan FX MetaTrader 5\\tester\\{symbol}_{short_window}_{long_window}.csv"
while not os.path.exists(results_file):
    print(f"Waiting for {results_file} to be generated...")
    time.sleep(300)  # 300秒ごとにチェック

# 結果を取得して保存(例として、エクスポートされた結果を読み込む)
if os.path.exists(results_file):
    results = pd.read_csv(results_file)
    output_file = os.path.join(data_folder, f'{symbol}_SMA_{short_window}_{long_window}.csv')
    results.to_csv(output_file, index=False)
    print(f"Results saved to {output_file}")
else:
    print(f"Results file not found for {symbol} with FastSMA={short_window} and SlowSMA={long_window}")

# MetaTrader 5から切断
mt5.shutdown()