<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nimnambui</title>
    <description>The latest articles on DEV Community by Nimnambui (@nimnambui).</description>
    <link>https://dev.to/nimnambui</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4015671%2F6c8e4bca-9aa5-4613-981f-3c4878d4173e.png</url>
      <title>DEV Community: Nimnambui</title>
      <link>https://dev.to/nimnambui</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nimnambui"/>
    <language>en</language>
    <item>
      <title>How I Built an MT5 Trading Bot with Python and Smart Money Concept</title>
      <dc:creator>Nimnambui</dc:creator>
      <pubDate>Sun, 05 Jul 2026 01:57:18 +0000</pubDate>
      <link>https://dev.to/nimnambui/how-i-built-an-mt5-trading-bot-with-python-and-smart-money-concept-2j5i</link>
      <guid>https://dev.to/nimnambui/how-i-built-an-mt5-trading-bot-with-python-and-smart-money-concept-2j5i</guid>
      <description>&lt;p&gt;How I Built an MT5 Trading Bot with Python and Smart Money Concept&lt;/p&gt;

&lt;p&gt;Automated trading has always fascinated me. After months of building and iterating, I want to share the architecture behind my MT5 trading bot that combines Python, Smart Money Concept (SMC), and machine learning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Python over MQL5?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;While MQL5 runs natively inside MetaTrader 5, Python offers a much richer ecosystem:&lt;/li&gt;
&lt;li&gt;Machine learning libraries (scikit-learn, PyTorch) for signal scoring&lt;/li&gt;
&lt;li&gt;Easy integration with Telegram, databases, and web dashboards&lt;/li&gt;
&lt;li&gt;Better debugging with modern IDEs&lt;/li&gt;
&lt;li&gt;The official MetaTrader5 Python package lets you connect directly to the terminal:
python 
_  import MetaTrader5 as mt5
if not mt5.initialize():
   print("Connection failed:", mt5.last_error())
   quit()
# Get latest candles
rates = mt5.copy_rates_from_pos('XAUUSD', mt5.TIMEFRAME_M15, 0, 100)_&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Core Architecture&lt;/strong&gt;&lt;br&gt;
My bot has four main components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Data layer — connects to MT5, fetches real-time prices and historical candles&lt;/li&gt;
&lt;li&gt;Signal logic — analyzes market using Smart Money Concept (Order Blocks, FVG, BOS)&lt;/li&gt;
&lt;li&gt;Risk management — calculates position size based on account risk percentage&lt;/li&gt;
&lt;li&gt;Execution — places orders with proper SL/TP via the API&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Smart Money Concept for Entries&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Instead of traditional indicators, I use SMC to identify institutional footprints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Order Blocks — zones where big players placed orders before strong moves&lt;/li&gt;
&lt;li&gt;Fair Value Gaps — price imbalances that often get filled&lt;/li&gt;
&lt;li&gt;Liquidity Sweeps — stop hunts before real reversals.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The key insight: a valid Order Block requires the impulse candle after it to be significantly larger than average (1.5-1.8x), not just slightly bigger.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Position Sizing Done Right&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A common mistake is hardcoding lot calculation for one symbol. The correct approach uses tick_value and tick_size from MT5, which works universally across gold, forex pairs, and indices:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;pythoninfo = mt5.symbol_info(symbol)&lt;br&gt;
risk_usd = balance * risk_percent&lt;br&gt;
n_ticks = sl_distance / info.trade_tick_size&lt;br&gt;
lot = risk_usd / (n_ticks * info.trade_tick_value)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Adding a Machine Learning Layer&lt;/p&gt;

&lt;p&gt;The most interesting part: I log every trade's context (ATR, RSI, session, entry position in the Order Block) along with its outcome. A simple logistic regression model then learns which setups have higher win probability, filtering out low-quality signals.&lt;/p&gt;

&lt;p&gt;With 200+ trades of data, the model starts recognizing patterns like "this setup wins more during London session when RSI is below 40."&lt;/p&gt;

&lt;p&gt;Lessons Learned&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rigid entry conditions kill opportunities — I initially required BOS + sweep simultaneously, which made the bot miss most valid setups. Relaxing to weighted signals improved results significantly.&lt;/li&gt;
&lt;li&gt;Feature sync matters — ML features must stay identical between the bot's inference and the training pipeline, or you get silent failures.&lt;/li&gt;
&lt;li&gt;Backtest properly — walk-forward testing on out-of-sample data is essential to avoid overfitting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Full Documentation&lt;/p&gt;

&lt;p&gt;I've written detailed guides (in Vietnamese) covering each topic in depth:&lt;/p&gt;

&lt;p&gt;Complete MT5 Python Bot Guide&lt;br&gt;
Smart Money Concept Explained&lt;br&gt;
Risk Management Fundamentals&lt;br&gt;
AI &amp;amp; Machine Learning for Trading&lt;/p&gt;

&lt;p&gt;Disclaimer: Trading forex and CFDs carries high risk. This content is educational, not financial advice.&lt;/p&gt;

</description>
      <category>python</category>
      <category>trading</category>
      <category>machinelearning</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
