Summary of "Advanced Algo Trading Series | Episode 3: Connecting Your Algo With Excel | Part 1"

Summary of “Advanced Algo Trading Series | Episode 3: Connecting Your Algo With Excel | Part 1”

This video tutorial focuses on integrating algorithmic trading strategies with Excel using Python, specifically leveraging the [xlwings](https://www.amazon.com/dp/1492081000?tag=dtdgstoreid08-20) library and trading APIs to create a live, interactive trading dashboard and automation system. The presenter guides through building a mini algorithmic trading bot (“Mini RoboCop”) that reads trading signals, market data, and order information in Excel, places orders via API, and manages trades with stop loss orders—all while handling real-time updates and rate limits.


Main Financial Strategies, Market Analyses, and Business Trends


Methodology / Step-by-Step Guide to Connect Algo Trading with Excel and Build a Trading Bot

  1. Setup and Import Libraries: - Use Python’s [xlwings](https://www.amazon.com/dp/1492081000?tag=dtdgstoreid08-20) library to interact with Excel workbooks and sheets. - Import trading API (e.g., Dhan API) for market data and order execution.

  2. Create and Connect to Excel Workbook: - Open or create an Excel file named (e.g., “Mini RoboCop”). - Connect to specific sheets like “Live Trading” and “Order Book”. - Read and write values to Excel cells to exchange data between Python and Excel.

  3. Manage Watch List: - Maintain a dynamic watch list in Excel (e.g., ACC, Cipla, Gail, etc.). - Read the watch list from Excel using [xlwings](https://www.amazon.com/dp/1492081000?tag=dtdgstoreid08-20) and Python. - Use Python’s list indexing to map stock names to Excel rows dynamically.

  4. Fetch Market Data: - Retrieve LTP (Last Traded Price) for all stocks in the watch list using API calls. - Optimize data fetching by requesting LTP for all stocks in one API call instead of looping individually. - Fetch historical data and calculate indicators like RSI on completed candles.

  5. Send Market Data and Indicator Values to Excel: - Write live LTP and RSI values back into corresponding Excel cells. - Use Excel to visualize and track real-time data and signals.

  6. Define Trading Logic in Excel: - Setup columns for buy/sell signals based on indicator thresholds (e.g., RSI > 60 for buy, RSI < 40 for sell). - Use Excel cells to input or modify strategy parameters like stop loss percentages, quantity, etc.

  7. Place Orders via API: - Read buy/sell signals from Excel. - Place market orders programmatically when conditions are met. - Place corresponding stop loss orders with correct trigger prices. - Store order IDs in Excel for tracking and future modifications/cancellations.

  8. Prevent Repeated Orders: - Implement logic to ensure orders are placed only once per signal. - Use an Excel column to mark if a script has already traded to avoid repeated orders during continuous loops.

  9. Use While Loop for Continuous Monitoring: - Run the algo inside a while True loop with delays to continuously monitor market data and signals. - Print or log current time and status for debugging and monitoring.

  10. Handle API Rate Limits:

    • Understand broker API rate limits (e.g., max 25 orders per second, 250 orders per minute).
    • Batch API calls where possible (e.g., fetch LTP for all watch list stocks in one call).
    • Use delays or throttling to avoid hitting limits and getting blocked.
  11. Debugging and Optimization:

    • Use Python’s PDB for step-by-step debugging.
    • Format and clean code for readability.
    • Handle exceptions and errors gracefully.
  12. Future Enhancements (Preview of Next Session):

    • Real-time option chain updates in Excel.
    • Telegram notifications for order placements and trail/slash updates.

Key Takeaways

Category

Business and Finance

Share this summary

Featured Products

Video