Skip to content

Commit 74325c8

Browse files
committed
pre commit batch
1 parent 76b857d commit 74325c8

File tree

8 files changed

+74
-45
lines changed

8 files changed

+74
-45
lines changed

.github/workflows/test-metatrader5-integration.yml

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
run: |
2323
# Download MT5 setup
2424
Invoke-WebRequest -Uri "https://download.mql5.com/cdn/web/metaquotes.software.corp/mt5/mt5setup.exe" -OutFile mt5setup.exe
25-
25+
2626
# Install MT5 silently
2727
Start-Process -FilePath .\mt5setup.exe -ArgumentList "/auto" -Wait
28-
28+
2929
# Verify installation
3030
$mtPath = "C:\Program Files\MetaTrader 5\terminal64.exe"
3131
if (Test-Path $mtPath) {
@@ -40,39 +40,57 @@ jobs:
4040
python -m pip install --upgrade pip
4141
pip install MetaTrader5
4242
43-
- name: Run MT5 terminal
43+
- name: Run MT5 terminal with desktop parameter
4444
run: |
45-
# Start MT5 in portable mode
46-
Start-Process -FilePath "C:\Program Files\MetaTrader 5\terminal64.exe" -ArgumentList "/portable" -PassThru
47-
Write-Host "Started MetaTrader 5 terminal"
48-
Start-Sleep -Seconds 20
45+
# Kill any existing MT5 instances
46+
taskkill /F /IM terminal64.exe 2>$null
47+
Start-Sleep -Seconds 3
48+
49+
# Start MT5 with the /desktop parameter as suggested in MQL5 forum
50+
$process = Start-Process -FilePath "C:\Program Files\MetaTrader 5\terminal64.exe" -ArgumentList "/portable", "/desktop" -PassThru
51+
$pid = $process.Id
52+
Write-Host "Started MetaTrader 5 terminal with PID $pid using /desktop parameter"
53+
Start-Sleep -Seconds 30
4954
5055
- name: Test MT5 Initialization
5156
run: |
52-
# Simplified Python script for testing MT5 initialization
57+
# Python script for testing MT5 initialization
5358
$script = @"
54-
import sys
55-
import time
56-
import MetaTrader5 as mt5
57-
58-
print(f"MetaTrader5 package version: {mt5.__version__}")
59-
path = r"C:\Program Files\MetaTrader 5\terminal64.exe"
60-
61-
# Try initialization with timeout
62-
print("Attempting MT5 initialization...")
63-
result = mt5.initialize(path=path, timeout=60000)
64-
error = mt5.last_error()
65-
print(f"Result: {result}, Error code: {error}")
66-
67-
# Always exit with success for CI
68-
sys.exit(0)
69-
"@
59+
import sys
60+
import time
61+
import MetaTrader5 as mt5
62+
63+
print(f"MetaTrader5 package version: {mt5.__version__}")
64+
path = r"C:\Program Files\MetaTrader 5\terminal64.exe"
65+
66+
# Try initialization with the approach from the forum
67+
print("Attempting MT5 initialization...")
68+
result = mt5.initialize(path=path, timeout=60000)
69+
error = mt5.last_error()
70+
print(f"Result: {result}, Error code: {error}")
71+
72+
if result:
73+
print("Successfully initialized MetaTrader 5!")
74+
# Get terminal info
75+
terminal_info = mt5.terminal_info()
76+
if terminal_info:
77+
print(f"Terminal info - Path: {terminal_info.path}")
78+
print(f"Terminal connected: {getattr(terminal_info, 'connected', 'N/A')}")
79+
80+
# Shut down properly
81+
mt5.shutdown()
82+
else:
83+
print("Failed to initialize MetaTrader 5")
84+
85+
# Always exit with success for CI
86+
sys.exit(0)
87+
"@
7088
7189
# Save script to temporary file
7290
$script | Out-File -FilePath "test_mt5.py" -Encoding utf8
73-
91+
7492
# Run the test
7593
python test_mt5.py
76-
94+
7795
# Always continue build
7896
exit 0

examples_of_expert_advisor/example_sockets_connection.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
This example uses stochastic oscillator and moving average indicators to generate trading signals.
33
"""
44

5+
import logging
6+
57
import MetaTrader5 as Mt5
68
from include.indicator_connector import Indicator
79
from include.rates import Rates
810
from include.tick import Tick
911
from include.trade import Trade
1012

13+
# Configure logging
14+
logger = logging.getLogger(__name__)
15+
logger.setLevel(logging.INFO)
16+
1117
# You need this MQL5 service to use indicator:
1218
# https://www.mql5.com/en/market/product/57574
1319
indicator = Indicator()
@@ -45,7 +51,7 @@
4551
# It uses "try" and catch because sometimes it returns None.
4652
try:
4753
# When in doubt how to handle the indicator, print it, it returns a Dictionary.
48-
# print(moving_average)
54+
# logger.info(moving_average)
4955
# It prints:
5056
# {'symbol': 'PETR4', 'time_frame': 1, 'period': 50, 'start_position': 0, 'method': 0,
5157
# 'applied_price': 0, 'moving_average_result': 23.103}
@@ -105,5 +111,5 @@
105111
trade.close_position("End of the trading day reached.")
106112
break
107113

108-
print("Finishing the program.")
109-
print("Program finished.")
114+
logger.info("Finishing the program.")
115+
logger.info("Program finished.")
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""FiMathe strategy examples for MetaTrader 5.
22
33
This package contains examples of Expert Advisors using Fibonacci retracement levels.
4-
"""
4+
"""

examples_of_expert_advisor/fimathe/eurusd_fimathe.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
"""
2-
EURUSD FiMathe Expert Advisor for MetaTrader 5.
1+
"""EURUSD FiMathe Expert Advisor for MetaTrader 5.
32
43
This Expert Advisor uses Fibonacci retracement levels to determine entry and exit points.
54
"""
5+
66
import MetaTrader5 as Mt5
77
import numpy as np
88
from include.rates import Rates
@@ -73,10 +73,13 @@
7373
trade.take_profit = zone_618
7474

7575
if len(Mt5.positions_get(symbol=trade.symbol)) == 1:
76-
if Mt5.positions_get(symbol=trade.symbol)[0].type == 0 and tick.last > Mt5.positions_get(symbol=trade.symbol)[0].price_open + zone_236: # if Buy
77-
trade.stop_loss = trade.sl_tp_steps
78-
79-
elif Mt5.positions_get(symbol=trade.symbol)[0].type == 1 and tick.last < Mt5.positions_get(symbol=trade.symbol)[0].price_open - zone_236: # if Sell
76+
if (
77+
Mt5.positions_get(symbol=trade.symbol)[0].type == 0
78+
and tick.last > Mt5.positions_get(symbol=trade.symbol)[0].price_open + zone_236
79+
) or (
80+
Mt5.positions_get(symbol=trade.symbol)[0].type == 1
81+
and tick.last < Mt5.positions_get(symbol=trade.symbol)[0].price_open - zone_236
82+
): # if Buy
8083
trade.stop_loss = trade.sl_tp_steps
8184

8285
trade.emergency_stop_loss = trade.stop_loss + zone_236

examples_of_expert_advisor/fimathe/win_fimathe.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
"""WIN FiMathe Expert Advisor for MetaTrader 5.
22
3-
This Expert Advisor is designed for WING21 futures, using Fibonacci retracement levels to
3+
This Expert Advisor is designed for WING21 futures, using Fibonacci retracement levels to
44
determine entry and exit points.
55
"""
6+
67
import MetaTrader5 as Mt5
78
import numpy as np
89
from include.rates import Rates
@@ -82,10 +83,13 @@
8283
trade.take_profit = zone_618
8384

8485
if len(Mt5.positions_get(symbol=trade.symbol)) == 1:
85-
if Mt5.positions_get(symbol=trade.symbol)[0].type == 0 and tick.last > Mt5.positions_get(symbol=trade.symbol)[0].price_open + zone_236: # if Buy
86-
trade.stop_loss = trade.sl_tp_steps
87-
88-
elif Mt5.positions_get(symbol=trade.symbol)[0].type == 1 and tick.last < Mt5.positions_get(symbol=trade.symbol)[0].price_open - zone_236: # if Sell
86+
if (
87+
Mt5.positions_get(symbol=trade.symbol)[0].type == 0
88+
and tick.last > Mt5.positions_get(symbol=trade.symbol)[0].price_open + zone_236
89+
) or (
90+
Mt5.positions_get(symbol=trade.symbol)[0].type == 1
91+
and tick.last < Mt5.positions_get(symbol=trade.symbol)[0].price_open - zone_236
92+
): # if Buy
8993
trade.stop_loss = trade.sl_tp_steps
9094

9195
trade.emergency_stop_loss = trade.stop_loss

mqpy/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
""" Python integration package.
1+
"""Python integration package.
22
33
This package provides a bridge between Python and MetaTrader 5, allowing users to
44
create Expert Advisors and implement trading strategies in Python.
55
"""
6-
7-
from .version import __version__ as __version__

scripts/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Scripts for the project."""

scripts/gen_ref_pages.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#!/usr/bin/env python
21
"""Generate the API reference pages for the MQPy package."""
32

43
import sys

0 commit comments

Comments
 (0)