ALGORITHMIC TRADING FOR BEGINNERS -- CODE PACK
From Algorithmic Trading for Beginners by Ash Cole · agenticedgelab.ai

Every Python listing in the book as its own file, so you don't have
to type them in. The files match the printed code line for line.

WHAT'S INSIDE

  by_chapter/        110 files, one per code listing, in book order.
                     The name starts with the chapter and listing number:
                     C04-16_price_pipeline_mt5.py is Chapter 4's
                     16th listing.
  .env.example       Template for your secrets. Copy it to .env and
                     fill it in.
  risk_config.json   The bot configuration template from the companion
                     toolkit. Adjust every value before you use it.
  README.txt         This file.

BEFORE YOU RUN ANYTHING

1. Install Python 3.14 from python.org. Don't pick 3.15 yet: the
   MetaTrader 5 library may not support it.
2. Install the libraries with the book's pip lines:
     Path A (MT5):   pip install MetaTrader5 pandas requests
     Path B (IBKR):  pip install ib_async pandas requests
     Both paths:     pip install pytz matplotlib python-dotenv
3. The MetaTrader 5 Python package runs on Windows only. The IBKR path
   (ib_async) works on Windows, Mac and Linux.
4. Run everything on a demo or paper account first. Never point a new
   bot at real money.
5. Secrets -- passwords, tokens, chat IDs -- go only in your .env file.
   Never put them in risk_config.json or in a .py file.

HOW TO USE THESE FILES

Many listings are pieces of a bigger file. The book tells you which file
each one goes in: data_pipeline.py, session_range.py, detectors.py,
order_engine.py, risk_manager.py, bot.py, bot_ibkr.py and backtester.py.
Follow the chapter text when you put them together. Short examples
expect the earlier code in that chapter to be loaded first.

FILES BY CHAPTER

Chapter 2 -- Setting Up Your Lab
  C02-05_mt5_connection_test.py
  C02-07_ibkr_connection_test.py
  C02-09_load_env_credentials.py

Chapter 3 -- Python for Traders
  C03-01_variables.py
  C03-02_price_math.py
  C03-03_spread_check.py
  C03-04_loop_over_candles.py
  C03-05_position_size_function.py
  C03-06_lists_and_dicts.py
  C03-07_formatted_output.py
  C03-08_try_except.py

Chapter 4 -- Reading Price Data
  C04-01_mt5_first_candles.py
  C04-02_ibkr_first_candles.py
  C04-03_ibkr_futures_contract.py
  C04-04_dataframe_columns.py
  C04-05_latest_candle.py
  C04-06_filter_rows.py
  C04-07_candle_range.py
  C04-08_mt5_timeframes.py
  C04-09_ibkr_timeframes.py
  C04-11_mt5_utc_conversion.py
  C04-12_ibkr_time_zones.py
  C04-13_get_killzone.py
  C04-14_gap_check.py
  C04-15_anomaly_flag.py
  C04-16_price_pipeline_mt5.py
  C04-17_price_pipeline_ibkr.py

Chapter 5 -- Your First Indicator
  C05-01_get_session.py
  C05-02_label_sessions.py
  C05-03_assign_trading_day.py
  C05-04_calculate_asian_range.py
  C05-05_classify_position.py
  C05-06_detect_sweeps.py
  C05-08_plot_asian_range.py
  C05-09_test_asian_range.py
  C05-10_enrich_with_asian_range.py

Chapter 6 -- Detecting ICT Setups
  C06-01_detect_swings.py
  C06-02_detect_structure.py
  C06-03_h1_bias.py
  C06-04_detect_fvg.py
  C06-05_fvg_volume_filter.py
  C06-06_update_fvg_status.py
  C06-07_detect_order_blocks.py
  C06-08_detect_liquidity_sweeps.py
  C06-09_score_setups.py
  C06-10_killzone_filter.py
  C06-11_plot_detections.py
  C06-12_test_detectors.py

Chapter 7 -- The Order Engine
  C07-01_mt5_order_types.py
  C07-02_ibkr_order_types.py
  C07-03_place_market_order.py
  C07-04_place_market_order_ibkr.py
  C07-05_calculate_sl_tp.py
  C07-06_attach_sl_tp_ibkr.py
  C07-07_trail_stop_mt5.py
  C07-08_move_to_breakeven_mt5.py
  C07-09_close_position_mt5.py
  C07-10_close_position_ibkr.py
  C07-11_pre_order_checks.py
  C07-12_place_checked_order.py
  C07-13_check_fill_quality.py
  C07-14_safe_place_order.py
  C07-15_order_engine_reference.py

Chapter 8 -- Risk Management Module
  C08-01_calculate_position_size.py
  C08-02_graduated_size.py
  C08-03_daily_risk_manager.py
  C08-04_risk_manager_usage.py
  C08-05_correlation_risk.py
  C08-06_place_risk_checked_order.py
  C08-07_kill_switch.py
  C08-08_risk_config.py

Chapter 9 -- Building the Bot Loop
  C09-01_bot_mt5.py
  C09-02_direction_mapping.py
  C09-03_loop_state.py
  C09-04_manage_open_positions.py
  C09-05_record_closed_trades.py
  C09-06_process_symbol.py
  C09-07_multi_symbol_loop.py
  C09-08_error_handling_pattern.py
  C09-09_reconnect_mt5.py
  C09-10_bot_ibkr.py

Chapter 10 -- Backtesting Engine v1
  C10-01_run_backtest.py
  C10-02_load_mt5_history.py
  C10-03_load_csv_history.py
  C10-04_calculate_metrics.py
  C10-05_print_backtest_report.py
  C10-06_backtest_example.py
  C10-07_lookahead_example_wrong.py
  C10-08_audit_lookahead.py
  C10-09_cost_sensitivity_test.py
  C10-10_walk_forward_test.py
  C10-11_plot_equity_curve.py
  C10-12_cross_symbol_test.py
  C10-13_export_backtest.py

Chapter 11 -- Logging & Monitoring
  C11-01_setup_bot_logger.py
  C11-02_logger_usage.py
  C11-03_trade_log.py
  C11-04_trade_log_usage.py
  C11-05_send_telegram_alert.py
  C11-06_telegram_env_setup.py
  C11-07_alert_calls.py
  C11-08_alert_manager.py
  C11-09_send_email_alert.py
  C11-10_bot_errors.py
  C11-11_error_logging_usage.py
  C11-12_daily_summary.py
  C11-13_daily_summary_usage.py
  C11-14_heartbeat.py
  C11-15_clean_old_logs.py
  C11-16_bot_integration.py

RISK DISCLAIMER

Trading futures and forex carries a high risk of loss and is not right
for everyone. This code is for education only. It is not financial
advice, and nothing here promises a profit or that the code works with
your broker as it is. Test on demo first, and only risk money you can
afford to lose.

ICT CREDIT

The trading concepts in this code are an educational interpretation of
the methodology taught by The Inner Circle Trader (ICT),
youtube.com/@InnerCircleTrader. This is not official ICT material.
