Open-source trading tools (MQL5 & NinjaTrader) + DeFi crypto bot + AlgoSphere Quant showcase
Open-source tools & strategies for algorithmic trading โ from traditional markets to DeFi. Commercial products by AlgoSphere Quant are listed below but hosted on the MQL5 Marketplace.
๐ About
This repository brings together my algorithmic trading work across two worlds:
| | TradFi | DeFi | |---|---|---| | Platforms | MetaTrader 5, NinjaTrader | Ethereum, Arbitrum, Polygon, Solana | | Languages | MQL5, C# | Python, Solidity (learning) | | Focus | Indicators, EAs, position management | CEX/DEX connectors, arbitrage, MEV | | Status | Mature (14+ products) | Active development |
๐ Repository Structure
Algorithmic-Trading/
โ
โโโ tradfi/
โ โโโ mql5/
โ โ โโโ libraries/
โ โ โ โโโ SessionTimeFilter.mqh
โ โ โ โโโ PositionSizer.mqh
โ โ โโโ indicators/
โ โ โ โโโ SpreadAnalyzer.mq5
โ โ โ โโโ CandlePatternDetector.mq5
โ โ โ โโโ MultiTimeframeDashboard.mq5
โ โ โโโ experts/
โ โ โ โโโ DrawdownGuard.mq5
โ โ โ โโโ TradeStatistics.mq5
โ โ โโโ scripts/
โ โ โโโ RiskCalculator.mq5
โ โ โโโ TradeJournal.mq5
โ โ
โ โโโ ninjatrader/
โ โโโ indicators/
โ โ โโโ VolumeProfile.cs
โ โ โโโ OrderFlowImbalance.cs
โ โ โโโ SessionHighLow.cs
โ โโโ strategies/
โ โโโ snippets/
โ
โโโ defi/
โ โโโ crypto-trade-bot/
โ โ โโโ connectors/
โ โ โ โโโ cex/ # CEX connectors (Binance, Bybit, OKX)
โ โ โ โ โโโ base.py
โ โ โ โ โโโ binance.py
โ โ โ โ โโโ bybit.py
โ โ โ โ โโโ okx.py
โ โ โ โโโ dex/ # DEX connectors
โ โ โ โโโ base.py # AbstractDEXConnector
โ โ โ โโโ uniswap.py # Uniswap V3 (Web3.py)
โ โ โโโ services/
โ โ โ โโโ exchangeratelimiter.py # Token bucket rate limiting
โ โ โโโ config/
โ โ โโโ tests/ # 294 tests, 0 failures
โ โ
โ โโโ contracts/ # Solidity (coming soon)
โ โโโ README.md
โ
โโโ docs/
โโโ architecture.md
โโโ defi-roadmap.md
๐น TradFi โ MetaTrader 5 & NinjaTrader
MQL5 โ Open-Source Tools
| Tool | Description | Type | |------|-------------|------| | SessionTimeFilter | Filter trades by session (London, NY, Tokyo, Sydney) with overlap detection | Library | | PositionSizer | Risk-based position sizing โ fixed lot, percent risk, Kelly criterion | Library | | SpreadAnalyzer | Real-time spread monitoring with statistics (avg, max, percentile) | Indicator | | CandlePatternDetector | Automated detection of 15+ candlestick patterns with alerts | Indicator | | MultiTimeframeDashboard | Multi-timeframe trend direction panel (RSI, MA, ADX) | Indicator | | DrawdownGuard | Automated equity protection with daily/weekly drawdown limits | Expert | | TradeStatistics | Real-time win rate, expectancy, profit factor, Sharpe ratio | Expert | | RiskCalculator | One-click lot size calculator based on SL distance & risk % | Script | | TradeJournal | Export complete trade history to CSV for external analysis | Script |
All MQL5 tools are also available on the MQL5 Code Base.
NinjaTrader โ C# Indicators
| Indicator | Description | Market | |-----------|-------------|--------| | VolumeProfile | Volume distribution at each price level, VAH/VAL/POC | Futures | | OrderFlowImbalance | Bid/Ask imbalance detection for scalping | Futures | | SessionHighLow | Automatic session (RTH/ETH) high/low/mid levels | Futures |
โ๏ธ DeFi โ Crypto Trading Bot
Multi-exchange, multi-chain trading bot with CEX and DEX support, built in Python with async architecture.
Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Telegram Bot Interface โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Strategy Engine โ
โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ CEX Connectors โ DEX Connectors โ
โ โโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Binance โ โ โ Uniswap V3 (Web3.py) โ โ
โ โ Bybit โ โ โ โโ Ethereum mainnet โ โ
โ โ OKX โ โ โ โโ Arbitrum โ โ
โ โโโโโโโโโฌโโโโโโโโ โ โ โโ Polygon โ โ
โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โผ โ โ
โ โโโโโโโโโโโโโโโโโ โ Smart Contracts โ
โ โ Rate Limiter โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Token Bucket โ โ โ Quoter V2 (price quotes) โ โ
โ โ per-exchange โ โ โ SwapRouter02 (execute swaps) โ โ
โ โ per-endpoint โ โ โ ERC-20 (approve/balance) โ โ
โ โโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Config โ Logging โ 294 Tests โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Features
- 3 CEX connectors โ Binance, Bybit, OKX via ccxt (async)
- Uniswap V3 DEX connector โ Direct smart contract interaction via Web3.py (Quoter V2, SwapRouter02)
- Multi-chain โ Ethereum mainnet, Arbitrum, Polygon
- Token bucket rate limiter โ Per-exchange, per-endpoint (order/market_data/account), with 10-20% headroom below real limits
- Async-first โ
aiogramfor Telegram,asyncio.to_thread()for sync ccxt calls - 294 tests, 0 failures
Rate Limiter โ Exchange Limits
| Exchange | Global | Orders | Market Data | Account | |----------|:------:|:------:|:-----------:|:-------:| | Binance | 1000/min | 400/min | 800/min | 400/min | | Bybit | 5000/min | 500/min | 2000/min | 600/min | | OKX | 2000/min | 500/min | 1200/min | 500/min |
๐ Blockchain & Smart Contracts (Roadmap)
Currently learning Solidity and smart contract development. Planned projects:
| Phase | Project | Stack | Status | |:-----:|---------|-------|:------:| | 1 | Solidity fundamentals + first contract deployment | Solidity, Remix, Hardhat | ๐ Planned | | 2 | DEX mechanics โ study Uniswap V2/V3 source code | Solidity, Foundry | ๐ Planned | | 3 | Flashloan arbitrage bot | Solidity, Aave V3, Foundry | ๐ Planned | | 4 | MEV extraction (backrunning, sandwich detection) | Solidity, Flashbots | ๐ Planned | | 5 | Smart contract security auditing | Slither, Mythril, CTFs | ๐ Planned |
Learning resources in progress: CryptoZombies, Ethernaut, Damn Vulnerable DeFi
๐ข AlgoSphere Quant โ Commercial Products
Source code is private โ links point to the MQL5 Marketplace.
๐ Flagship Products
| Product | Description | Version | |---------|-------------|:-------:| | Trade Manager PRO | Position management โ automated BE, trailing, partial closes, TP ladders, session filter, journal export | v7.10 | | SafeScalperPro | Automated scalping EA with risk management and prop firm compliance | v3.0 |
Product Suite (14 products)
๐ 9 Indicators + ๐ก๏ธ 5 Utilities (click to expand)
Indicators: SmartMoney Concepts, Liquidity Heatmap, Volume Profile, Divergence Scanner, Order Flow, Correlation Matrix, Session Control, Account Analytics, Risk Manager
Utilities: PropGuard (prop firm compliance), Risk Manager (drawdown protection), Trade Journal, Position Sizer, News Filter
All products feature the unified ASQ Dark Theme built on shared includes (ASQTheme.mqh, ASQCommon.mqh).
๐๏ธ Architecture Philosophy
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ EA / Bot / DApp โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโ โ
โ โ Signal โ โ Filter โ โ Risk Management โ โ
โ โ Module โ โ Module โ โ Module โ โ
โ โโโโโโฌโโโโโโ โโโโโโฌโโโโโโ โโโโโโโโโโฌโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโ โ
โ โ Trade Management โ โ
โ โโโโโโโโโโฌโโโโโโโโโโ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Execution Layer โ โ
โ โ (Deterministic) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ TradFi: MQL5/C# โ DeFi: Web3.py/Solidity โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Shared principles across TradFi & DeFi:
- Deterministic execution โ Timer/block-driven, no race conditions
- Monotonic state machines โ States progress forward, never backward
- Rate limiting โ Token bucket per exchange/endpoint
- Modular composition โ Reusable signal, filter, risk modules
๐ Quick Start
git clone https://github.com/e49nana/Algorithmic-trading.git
cd Algorithmic-trading
โโ TradFi โโ
MQL5: Copy to MetaTrader data folder (Indicators/, Experts/, Include/, Scripts/)
NinjaTrader: Tools โ Import โ NinjaScript Add-On
โโ DeFi โโ
cd defi/crypto-trade-bot
pip install -r requirements.txt
Configure your API keys in config/
python -m pytest tests/ -q # 294 tests
๐ ๏ธ Tech Stack
| Domain | Languages | Frameworks & Tools | |--------|-----------|-------------------| | TradFi | MQL5, C# | MetaTrader 5, NinjaTrader | | DeFi | Python, Solidity (learning) | Web3.py, ccxt, aiogram, Hardhat | | Blockchain | โ | Ethereum, Arbitrum, Polygon, Solana | | Testing | Python | pytest (294 tests) | | Smart Contracts | โ | Uniswap V3 (Quoter, Router, Pool) |
๐ Roadmap
TradFi:
- [x] 10 open-source MQL5 Code Base publications
- [x] NinjaTrader indicator suite for futures
- [x] AlgoSphere Quant product suite (14 products)
- [x] TradeManager v7.10 with deterministic engine
- [ ] Modular EA Framework (CTradeManager, CPositionSizer, CRiskManager)
- [x] Multi-CEX async connector (Binance, Bybit, OKX)
- [x] Uniswap V3 DEX connector (Web3.py)
- [x] Token bucket rate limiter (294 tests)
- [ ] Solidity fundamentals + first testnet deployment
- [ ] Flashloan arbitrage contract (Aave V3)
- [ ] MEV extraction bot (Flashbots)
- [ ] Smart contract security auditing
โ ๏ธ Disclaimer
Trading involves significant risk of loss. The code in this repository is provided for educational and research purposes only. Past performance does not guarantee future results. Always test on demo/testnet before live trading.
๐ค Author
Emmanuel Nana Nana Founder, AlgoSphere Quant B.Sc. Applied Mathematics & Physics โ TH Nรผrnberg
๐ License
Open-source code: MIT License. AlgoSphere Quant products: proprietary โ see algosphere-quant.com.