|
| 1 | +# MQPy Examples |
| 2 | + |
| 3 | +!!! danger "Trading Risk Warning" |
| 4 | + **IMPORTANT: All examples should be tested using demo accounts only!** |
| 5 | + |
| 6 | + - Trading involves substantial risk of loss |
| 7 | + - These examples are for educational purposes only |
| 8 | + - Always test with fake money before using real funds |
| 9 | + - Past performance is not indicative of future results |
| 10 | + - The developers are not responsible for any financial losses |
| 11 | + |
| 12 | +MQPy provides a variety of example trading strategies to help you understand how to implement your own algorithmic trading solutions using MetaTrader 5. |
| 13 | + |
| 14 | +## Getting Started |
| 15 | + |
| 16 | +If you're new to MQPy, we recommend starting with the [Getting Started Example](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/getting_started.py) which introduces you to the basics of: |
| 17 | + |
| 18 | +- Initializing the trading environment |
| 19 | +- Fetching market data |
| 20 | +- Making trading decisions |
| 21 | +- Executing trades |
| 22 | + |
| 23 | +## Basic Strategies |
| 24 | + |
| 25 | +### Moving Average Crossover |
| 26 | + |
| 27 | +The [Moving Average Crossover](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/basic_moving_average_strategy.py) strategy is a classic trading approach that: |
| 28 | + |
| 29 | +| Feature | Description | |
| 30 | +|---------|-------------| |
| 31 | +| Signal Generation | Uses crossovers between short and long moving averages | |
| 32 | +| Implementation | Includes proper crossover detection logic | |
| 33 | +| Error Handling | Comprehensive logging and exception handling | |
| 34 | + |
| 35 | +[Read detailed explanation of the Moving Average strategy →](strategies/moving_average.md) |
| 36 | + |
| 37 | +```python |
| 38 | +def calculate_sma(prices, period): |
| 39 | + """Calculate Simple Moving Average.""" |
| 40 | + if len(prices) < period: |
| 41 | + return None |
| 42 | + return sum(prices[-period:]) / period |
| 43 | +``` |
| 44 | + |
| 45 | +## Technical Indicator Strategies |
| 46 | + |
| 47 | +### RSI Strategy |
| 48 | + |
| 49 | +The [RSI Strategy](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/rsi_strategy.py) example demonstrates: |
| 50 | + |
| 51 | +| Feature | Description | |
| 52 | +|---------|-------------| |
| 53 | +| Indicator | Implementation of the Relative Strength Index (RSI) | |
| 54 | +| Trading Approach | Entry/exit based on overbought and oversold conditions | |
| 55 | +| Technical Analysis | Practical example of calculating and using indicators | |
| 56 | + |
| 57 | +[Read detailed explanation of the RSI strategy →](strategies/rsi_strategy.md) |
| 58 | + |
| 59 | +### Bollinger Bands Strategy |
| 60 | + |
| 61 | +The [Bollinger Bands Strategy](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/bollinger_bands_strategy.py) shows: |
| 62 | + |
| 63 | +| Feature | Description | |
| 64 | +|---------|-------------| |
| 65 | +| Trading Approach | Using Bollinger Bands for trading range breakouts | |
| 66 | +| Strategy Type | Mean reversion trading principles | |
| 67 | +| Signal Generation | Volatility-based entry and exit logic | |
| 68 | + |
| 69 | +[Read detailed explanation of the Bollinger Bands strategy →](strategies/bollinger_bands.md) |
| 70 | + |
| 71 | +## Advanced Strategies |
| 72 | + |
| 73 | +### Fibonacci Retracement Strategy |
| 74 | + |
| 75 | +The [Fibonacci Retracement Strategy](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/fibonacci_retracement_eurusd.py) for EURUSD: |
| 76 | + |
| 77 | +| Feature | Description | |
| 78 | +|---------|-------------| |
| 79 | +| Strategy Type | Implements the FiMathe strategy | |
| 80 | +| Pattern Recognition | Uses Fibonacci retracement levels for entries and exits | |
| 81 | +| Risk Management | Includes dynamic stop-loss adjustment based on price action | |
| 82 | + |
| 83 | +[Read detailed explanation of the Fibonacci Retracement strategy →](strategies/fibonacci_retracement.md) |
| 84 | + |
| 85 | +### Market Depth Analysis |
| 86 | + |
| 87 | +The [Market Depth Analysis](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/market_depth_analysis.py) provides insights into order book data: |
| 88 | + |
| 89 | +| Feature | Description | |
| 90 | +|---------|-------------| |
| 91 | +| Order Book Analysis | Examines buy/sell order distribution and concentration | |
| 92 | +| Support/Resistance | Identifies potential support and resistance levels from actual orders | |
| 93 | +| Visualization | Creates horizontal bar charts showing bid/ask distribution with key levels | |
| 94 | + |
| 95 | +[Read detailed explanation of the Market Depth Analysis →](strategies/market_depth_analysis.md) |
| 96 | + |
| 97 | +### Multi-Timeframe Analysis |
| 98 | + |
| 99 | +The [Rate Converter Example](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/rate_converter_example.py) demonstrates: |
| 100 | + |
| 101 | +| Feature | Description | |
| 102 | +|---------|-------------| |
| 103 | +| Timeframe Conversion | How to convert between different timeframes using the RateConverter | |
| 104 | +| Multi-timeframe Analysis | Calculating moving averages across different timeframes | |
| 105 | +| Visualization | Creating charts for price data across 1-minute, 5-minute, and 1-hour timeframes | |
| 106 | + |
| 107 | +### Indicator Connector Strategy |
| 108 | + |
| 109 | +The [Indicator Connector Strategy](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/indicator_connector_strategy.py) shows: |
| 110 | + |
| 111 | +| Feature | Description | |
| 112 | +|---------|-------------| |
| 113 | +| Connectivity | How to connect to MetaTrader 5's custom indicators | |
| 114 | +| Signal Combination | Combining multiple indicator signals (Stochastic and Moving Average) | |
| 115 | +| Advanced Techniques | Advanced signal generation and filtering approaches | |
| 116 | + |
| 117 | +## Running the Examples |
| 118 | + |
| 119 | +To run any of these examples: |
| 120 | + |
| 121 | +1. Ensure you have MQPy installed: |
| 122 | + ```bash |
| 123 | + pip install mqpy |
| 124 | + ``` |
| 125 | + |
| 126 | +2. Make sure MetaTrader 5 is installed and running on your system |
| 127 | + |
| 128 | +3. Run any example with Python: |
| 129 | + ```bash |
| 130 | + python getting_started.py |
| 131 | + ``` |
| 132 | + |
| 133 | +## Contributing Your Own Examples |
| 134 | + |
| 135 | +If you've developed an interesting strategy using MQPy, consider contributing it to this examples collection by submitting a pull request! |
| 136 | + |
| 137 | +## Disclaimer |
| 138 | + |
| 139 | +These example strategies are for educational purposes only and are not financial advice. Always perform your own analysis and risk assessment before trading with real money. |
| 140 | + |
| 141 | +## All Example Files |
| 142 | + |
| 143 | +You can access these examples in several ways: |
| 144 | + |
| 145 | +1. **Clone the entire repository**: |
| 146 | + ```bash |
| 147 | + git clone https://github.com/Joaopeuko/Mql5-Python-Integration.git |
| 148 | + cd Mql5-Python-Integration/docs/examples |
| 149 | + ``` |
| 150 | + |
| 151 | +2. **Download individual files** by clicking on the links in the table below. |
| 152 | + |
| 153 | +3. **Copy the code** from the strategy explanations page for the strategies with detailed documentation. |
| 154 | + |
| 155 | +Here are direct links to all the example files in the MQPy repository: |
| 156 | + |
| 157 | +| Strategy | Description | Source Code | |
| 158 | +|----------|-------------|-------------| |
| 159 | +| Getting Started | Basic introduction to MQPy | [getting_started.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/getting_started.py) | |
| 160 | +| Moving Average Crossover | Simple trend-following strategy | [basic_moving_average_strategy.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/basic_moving_average_strategy.py) | |
| 161 | +| RSI Strategy | Momentum-based overbought/oversold strategy | [rsi_strategy.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/rsi_strategy.py) | |
| 162 | +| Bollinger Bands | Mean reversion volatility strategy | [bollinger_bands_strategy.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/bollinger_bands_strategy.py) | |
| 163 | +| Fibonacci Retracement | Advanced Fibonacci pattern strategy | [fibonacci_retracement_eurusd.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/fibonacci_retracement_eurusd.py) | |
| 164 | +| Market Depth Analysis | Order book and volume analysis | [market_depth_analysis.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/market_depth_analysis.py) | |
| 165 | +| Rate Converter | Multi-timeframe analysis example | [rate_converter_example.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/rate_converter_example.py) | |
| 166 | +| Indicator Connector | Custom indicator integration | [indicator_connector_strategy.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/indicator_connector_strategy.py) | |
| 167 | +| Sockets Connection | Advanced MetaTrader connectivity | [example_sockets_connection.py](https://github.com/Joaopeuko/Mql5-Python-Integration/blob/main/docs/examples/example_sockets_connection.py) | |
0 commit comments