TradingAI transforms any YouTube trading video into a structured, actionable strategy report — and executable trading code — in minutes. Paste a URL: TradingAI downloads the audio, transcribes it locally using OpenAI Whisper (your data never leaves your machine), uses GPT-4o to extract every trading strategy, indicator, risk rule, and algorithm discussed, then automatically generates ready-to-use Pine Script v6 (TradingView) and MetaTrader 5 Python code from the extracted strategies.
Built for traders, analysts, and quant researchers who want to capture insights from hours of trading content — without watching every video.
- 🎥 YouTube to report in one click — paste any YouTube URL and get a full strategy report
- 🎙️ Local transcription — Whisper runs on your machine, no audio sent to third parties
- 📊 Live transcription progress — real-time progress bar shows % complete while Whisper processes
- 🧠 AI strategy extraction — GPT-4o extracts strategies, indicators, risk rules and algorithms
- 🧩 Code generation — auto-generates Pine Script v6 (TradingView) and MT5 Python from every report
- 📄 Export anywhere — download as PDF, Markdown, plain text, Pine Script (.pine) or MT5 (.py)
- 🔁 Handles long videos — automatic token-aware chunking for videos of any length
- 🌐 Beautiful web UI — React frontend with live progress, GPU/CPU selector, and code tabs
- 🖥️ CLI support — full pipeline available as a command-line tool
- 🐳 Docker ready — CPU variant, one command to run on any machine
- 🔌 Flexible LLM — works with Azure OpenAI or standard OpenAI API
| Layer | Technology |
|---|---|
| Transcription | OpenAI Whisper (local, GPU or CPU) |
| LLM | Azure OpenAI GPT-4o / OpenAI GPT-4o |
| Audio download | yt-dlp + ffmpeg |
| Backend | FastAPI + Python 3.9+ |
| Frontend | React 18 + Vite |
| Containerisation | Docker + docker-compose |
| Token counting | tiktoken |
| Code generation | Pine Script v6 + MetaTrader 5 Python |
| Progress tracking | Chunked Whisper transcription with callbacks |
YouTube URL
│
▼
┌─────────────────┐
│ downloader.py │ Downloads audio-only via yt-dlp + ffmpeg
└────────┬────────┘
│
▼
┌──────────────────┐
│ transcriber.py │ Transcribes locally with Whisper (GPU/CPU)
│ │ Live progress bar — shows % complete in UI + logs
└────────┬─────────┘
│
▼
┌─────────────────┐
│ chunker.py │ Counts tokens — splits into chunks if too long
└────────┬────────┘
│
▼
┌──────────────────────────┐
│ strategy_extractor.py │ Sends to GPT-4o — extracts strategies,
│ │ indicators, risk rules, algorithms
└────────┬─────────────────┘
│
▼
┌──────────────────────────┐
│ code_generator.py │ Generates Pine Script v6 (TradingView)
│ │ and Python MT5 code from strategies
└────────┬─────────────────┘
│
▼
┌─────────────────┐
│ reporter.py │ Formats and saves the final report
└─────────────────┘
trading_app/
├── backend/
│ ├── app.py # FastAPI server + SSE streaming
│ ├── main.py # CLI entry point
│ ├── config.py # Config loader (.env → constants)
│ ├── logger.py # Logging setup (console + file)
│ ├── requirements.txt # Core dependencies
│ ├── requirements_web.txt # Web/API dependencies
│ └── modules/
│ ├── downloader.py # yt-dlp audio download
│ ├── transcriber.py # Whisper transcription (with live progress %)
│ ├── chunker.py # Token counting + smart chunking
│ ├── strategy_extractor.py # GPT-4o strategy extraction
│ ├── code_generator.py # Pine Script v6 + MT5 Python generation
│ └── reporter.py # Report formatting + saving
├── frontend/
│ └── src/ # React 18 + Vite source
├── docker/
│ ├── Dockerfile # CPU Docker image
│ └── docker-compose.yml # CPU compose config
├── start.py # One-command launcher (builds frontend + starts server)
├── .env.example # Environment variable template
└── README.md
TradingAI supports two LLM providers. Set LLM_PROVIDER in your .env to choose:
LLM_PROVIDER=azure
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_API_KEY=your_azure_key_here
AZURE_OPENAI_API_VERSION=2024-02-01
AZURE_DEPLOYMENT_NAME=gpt-4oLLM_PROVIDER=openai
OPENAI_API_KEY=sk-your-openai-key-here
OPENAI_MODEL=gpt-4oNot sure which to use? Standard OpenAI is simpler to set up. Azure OpenAI is better for enterprise/team use with compliance requirements.
No Python, Node.js, or ffmpeg setup needed. Just Docker.
- Docker Desktop installed and running
- Your LLM credentials (Azure OpenAI or standard OpenAI)
git clone https://github.com/your-username/trading_strategy_extractor.git
cd trading_strategy_extractor
cp .env.example .env
# Open .env and fill in your credentialsdocker compose -f docker/docker-compose.yml up --buildhttp://localhost:8000
First build takes 3–5 minutes. Subsequent starts are instant.
| Command | Description |
|---|---|
docker compose -f docker/docker-compose.yml up --build |
First run |
docker compose -f docker/docker-compose.yml up |
Start (no rebuild) |
docker compose -f docker/docker-compose.yml down |
Stop the app |
docker compose -f docker/docker-compose.yml logs -f |
View live logs |
- Python 3.9+
- FFmpeg
- CUDA GPU (optional but recommended for Whisper speed)
- Azure OpenAI or OpenAI API credentials
# 1. Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
source venv/bin/activate # macOS / Linux
# 2. Install PyTorch (with CUDA — check your version with nvidia-smi)
pip install torch --index-url https://download.pytorch.org/whl/cu118 # CUDA 11.8
pip install torch --index-url https://download.pytorch.org/whl/cu121 # CUDA 12.1
pip install torch # CPU only
# 3. Install dependencies
pip install -r backend/requirements.txt
# 4. Set up environment
cp .env.example .env
# Fill in your credentialspip install -r backend/requirements_web.txt
python start.py
# Open http://localhost:8000| Variable | Required | Default | Description |
|---|---|---|---|
LLM_PROVIDER |
Yes | azure |
azure or openai |
AZURE_OPENAI_ENDPOINT |
If azure | — | Azure OpenAI endpoint URL |
AZURE_OPENAI_API_KEY |
If azure | — | Azure OpenAI API key |
AZURE_OPENAI_API_VERSION |
If azure | 2024-02-01 |
Azure API version |
AZURE_DEPLOYMENT_NAME |
If azure | gpt-4o |
GPT-4o deployment name |
OPENAI_API_KEY |
If openai | — | OpenAI API key (sk-...) |
OPENAI_MODEL |
If openai | gpt-4o |
OpenAI model name |
WHISPER_MODEL |
No | small |
tiny / base / small / medium / large |
WHISPER_DEVICE |
No | cpu |
cuda or cpu |
LOG_LEVEL |
No | DEBUG |
DEBUG / INFO / WARNING / ERROR |
MAX_TOKENS_SAFE |
No | 60000 |
Token limit before chunking kicks in |
CHUNK_OVERLAP_WORDS |
No | 200 |
Overlap words between chunks |
YTDLP_COOKIES_FILE |
No | — | Path to cookies.txt for authenticated downloads |
YouTube may require authentication to download some videos. If you see a "Sign in to confirm you're not a bot" error:
- Install the "Get cookies.txt LOCALLY" Chrome extension
- Go to youtube.com while logged in to your Google account
- Click the extension and export cookies as
cookies.txt - Place
cookies.txtin the project root folder - Add to your
.envfile:YTDLP_COOKIES_FILE=cookies.txt
Note:
cookies.txtis gitignored and should never be committed to version control as it contains your session credentials.
| Model | Size | VRAM | Speed | Recommended for |
|---|---|---|---|---|
| tiny | 75 MB | ~1 GB | fastest | quick tests |
| base | 145 MB | ~1 GB | fast | short videos |
| small | 465 MB | ~2 GB | good | default (4 GB GPU) |
| medium | 1.5 GB | ~5 GB | better | longer/complex content |
| large | 3 GB | ~10 GB | best | maximum accuracy |
Docker CPU mode uses
smallby default. Change viaWHISPER_MODELin.env.
Token checking and chunking happen automatically — no manual steps needed.
| Video length | Approx tokens | Behaviour |
|---|---|---|
| Under ~5 hours | Under 60,000 | Single pass — full transcript sent to GPT-4o |
| Over ~5 hours | Over 60,000 | Auto-split → MAP phase → REDUCE phase → merged report |
chunker.pycounts tokens usingtiktokenwith GPT-4o'scl100k_baseencoding- If within limit → single pass, normal flow
- If over limit → split into overlapping chunks → extract strategies per chunk (MAP) → merge and deduplicate (REDUCE)
# Test the chunker on any saved transcript
python backend/modules/chunker.py ./outputs/test_transcript.txtAfter extracting strategies, TradingAI automatically generates executable trading code in three formats — ready to use in real trading platforms.
- Ready to paste directly into TradingView's Pine Script Editor
- Implements entry/exit conditions, indicators, stop loss and take profit
- Uses Pine Script v6 syntax with built-in
ta.*functions - How to use:
- Open TradingView
- Go to Pine Script Editor
- Click "New Script"
- Paste the generated code
- Click "Add to chart"
- Runs natively inside MetaTrader 5 — no Python or external software needed
- Complete Expert Advisor (.mq5) with
OnInit(),OnDeinit(),OnTick()handlers - Uses MT5's built-in indicator functions (
iMA,iRSI,iATR, etc.) - Input parameters configurable directly from the MT5 interface
- How to use:
- Download the .mq5 file
- Open MetaTrader 5 → File → Open Data Folder
- Place file in
MQL5/Experts/folder - In MT5 Navigator → Expert Advisors → right-click → Refresh
- Double-click the EA to attach to a chart
- Enable "Allow Algo Trading" in MT5 settings
- Python script that connects to MT5 externally via the
MetaTrader5library - MT5 must be open and running on your machine
- More flexible for custom data processing and ML integration
- Prerequisite:
pip install MetaTrader5
| MQL5 | Python MT5 | |
|---|---|---|
| Runs inside MT5 | ✅ Native | ❌ External |
| Requires Python | ❌ No | ✅ Yes |
| Best for | Pure trading automation | Custom logic + ML |
| Recommended for | Most traders | Quant developers |
All three formats are available in the web UI as tabs:
[ Strategy Report ] [ Pine Script ] [ MQL5 (MT5) ] [ MT5 Python ]
Each tab has:
- Syntax-highlighted code block (github-dark theme)
- Copy button — copies code to clipboard instantly
- Download button — saves as
.pine,.mq5, or.pyfile
python backend/modules/code_generator.py ./outputs/test_transcript.txtThis generates and saves:
./outputs/test_pine_script.pine./outputs/test_expert_advisor.mq5./outputs/test_mt5_strategy.py
- URL bar — paste any YouTube URL, select CPU or GPU (CUDA), click Generate
- Left panel — live pipeline steps with animated status indicators, real-time transcription progress bar (updates every ~10% as Whisper processes), then video info card, token consumption card with progress bar, and stats grid (words, tokens, API calls, total time)
- Right panel — four tabs when report is ready:
- Strategy Report — fully formatted markdown report with section headers
- Pine Script — syntax-highlighted Pine Script v6 code with Copy + Download
- MQL5 (MT5) — Native MetaTrader 5 Expert Advisor with Copy + Download
- MT5 Python — syntax-highlighted MetaTrader 5 Python code with Copy + Download
- Download buttons — TXT · MD · PDF · Pine Script (.pine) · MQL5 (.mq5) · MT5 Python (.py)
# Full pipeline
python backend/main.py "https://www.youtube.com/watch?v=EXAMPLE"
# Transcription only (skip LLM)
python backend/main.py "https://youtube.com/watch?v=EXAMPLE" --transcript-only
# Override Whisper model
python backend/main.py "https://youtube.com/watch?v=EXAMPLE" --whisper-model base
# Verbose debug logging
python backend/main.py "https://youtube.com/watch?v=EXAMPLE" --log-level DEBUG
# Test individual modules
python backend/modules/downloader.py "https://youtube.com/watch?v=EXAMPLE"
python backend/modules/transcriber.py ./temp/audio.mp3
python backend/modules/strategy_extractor.py ./outputs/test_transcript.txt
python backend/modules/reporter.py
# Test code generator independently
python backend/modules/code_generator.py ./outputs/test_transcript.txt
# Test strategy extractor independently
python backend/modules/strategy_extractor.py ./outputs/test_transcript.txtReports saved to ./outputs/ as {title}_{timestamp}.txt:
================================================
TRADING STRATEGY REPORT
================================================
Source Video : Video Title Here
Channel : Channel Name
Duration : 28m 24s
Transcript : 6,732 words
Generated : 2026-04-06 14:22:00
Tokens Used : 8,738
================================================
[extracted strategies]
================================================
END OF REPORT
================================================
CUDA / GPU issues
- "CUDA not available" — Whisper falls back to CPU automatically. Check CUDA with
nvidia-smi. - GPU out of memory — Use a smaller model:
--whisper-model tinyorbase - torch not found — Use the CUDA-specific pip install command above
yt-dlp / ffmpeg errors
- "Video unavailable" — Video may be private, age-restricted, or region-blocked
- "ffmpeg not found" — Install FFmpeg and add its
bin/folder to your system PATH - "Sign in to confirm you're not a bot" — See the YouTube Authentication section above
Token / chunking issues
- A
WARNINGis logged automatically when transcript exceeds safe token limit - Chunking is fully automatic — no manual steps needed
- Use
python backend/modules/chunker.py ./outputs/transcript.txtto inspect token counts
Missing .env values
- A clear
ValueErroris raised if required credentials are missing - Check your
.envfile is in the project root (not inside a subfolder) - Make sure
LLM_PROVIDERmatches the credentials you have filled in
Pine Script or MT5 code not generating
- Check that your LLM API key is valid and has remaining quota
- Code generation makes 2 additional API calls after strategy extraction
- If code tabs appear empty, check the logs for
code_generatorerrors - Test independently:
python backend/modules/code_generator.py ./outputs/test_transcript.txt
- If the transcript is very short (under 100 words), the LLM may not generate meaningful code — try with a longer video
MQL5 Expert Advisor not compiling in MetaTrader 5
- Open MetaTrader 5 → Tools → MetaEditor (or press F4)
- Open the .mq5 file in MetaEditor
- Press F7 to compile — check the Errors tab for issues
- Common fix: make sure
#include <Trade\Trade.mqh>is available (comes with standard MT5 installation) - If you see "CTrade" errors, the Trade library may need to be enabled in MetaEditor's Include paths
- The generated EA is a starting template — you may need to adjust lot sizes and broker-specific settings
Transcription progress shows 0% or does not update
- Progress updates every ~10% as each audio chunk is processed
- Short videos (under 2 minutes) may complete too fast to see progress
- Check logs for
[DEBUG] Transcription progress:lines to confirm it is working - If using GPU (CUDA), transcription is faster and progress updates may flash briefly
- Try with a longer video (5+ minutes) to see progress updates clearly
Pull requests are welcome! For major changes please open an issue first.
- Fork the repo
- Create a feature branch:
git checkout -b feature/your-feature - Commit:
git commit -m "add your feature" - Push:
git push origin feature/your-feature - Open a Pull Request
