Skip to content

Fully automated pipeline using FastAPI, cTrader Open API, and Docker. Analyze charts, journal trades to Notion, and place market/limit/stop orders across Forex, indices, and stocks — all in natural language (English, French, Spanish, and more) through ChatGPT.

License

Notifications You must be signed in to change notification settings

maghdam/chatgpt-trading-strategy-assistant

Repository files navigation

📊 ChatGPT Trading Strategy Assistant with cTrader API

A fully automated and extensible trading assistant powered by ChatGPT — capable of analyzing, journaling, and executing trades in Forex, indices, and stocks using natural language.

This framework integrates the cTrader Open API, a FastAPI backend, and Docker, delivering a seamless end-to-end trading pipeline — from market analysis to order placement — all controlled through conversation.

🧐 Currently configured to run a Smart Money Concepts (SMC) strategy out of the box. 🛠️ You can easily adapt it to any strategy by modifying the ChatGPT instructions.


🔑 Key Features

  • Strategy-Agnostic Design Define your own rules — just update the ChatGPT prompt instructions, and the assistant adapts accordingly.

  • Advanced SMC Market Analysis Detects CHOCH, BOS, FVGs, OBs, liquidity sweeps, and premium/discount zones.

  • Trade Journaling Automatically logs trades to Notion with structured metadata, SMC checklists, and chart snapshots.

  • Order Execution Places market, limit, and stop orders in real time using plain English.

  • Multilingual Support Works in English, French, Spanish, and any language ChatGPT understands.

  • Live Market Sync Fetches price data and executes logic live through the cTrader Open API.


🧹 Top-Down SMC Flow (Full Sequence)

✅ The assistant follows strict Smart Money Concepts (SMC) methodology using a top-down flow: HTF (D1) → MTF (H4/H1) → LTF (M15/M5) — all layers are analyzed in sequence for every setup.


✨ Trade Confluence Scoring System

Element Weight
CHOCH 25%
Order Block (OB) 20%
Fair Value Gap (FVG) 15%
Liquidity Sweep 20%
Candle Confirmation 20%
Required to Enter ≥ 70%

🛡️ Risk Management Filters

The assistant will skip trade setups when any of the following are true:

  • 🔺 ADR ≥ 90%: Daily move exhausted
  • 🕐 High-impact news in next 30–60 minutes
  • 🔚 End-of-day (last 10% of ADR range)
  • 🔴 Counter-trend unless confluence ≥ 80%

📃 Journaling Logic

🧾 When a valid setup is found, the assistant auto-posts to /journal-entry, logging:

  • Full metadata (symbol, session, entry, SL, TP, confluence score)
  • Checklist (CHOCH, OB, FVG, Sweep, Candle)
  • News and session context
  • Optional chart snapshot

🖋️ Natural Language Prompts (Examples)

Prompt Action Triggered
Analyze EURUSD using SMC /analyze full structure scan
What’s the HTF bias on NAS100? D1-only HTF analysis
Has NY session swept London high? Liquidity mapping check
Reevaluate my GBPUSD long LTF/MTF revalidation
Place buy limit on EURUSD Places /place-order limit
Log this NAS100 trade Saves journal to Notion


🧩 Project Structure

chatgpt-smc-trading-assistant/
├── app.py                  # FastAPI app (exposes /analyze, /place-order, etc.)
├── ctrader_client.py       # cTrader Open API Twisted client
├── analysis/               # SMC detection logic (CHOCH, BOS, OB, FVG, sessions, etc.)
├── charts/                 # Plotly/lightweight-charts helpers (optional)
├── gpt_instructions.md     # Strategy prompt template for your Custom GPT
├── gpt-schema.yaml         # OpenAPI schema used by GPT Actions
├── docker-compose.yml      # Backend-only compose (optional)
├── Dockerfile              # Backend image
├── requirements.txt        # Python deps
├── .env.example            # Template for env vars
├── docker_usage_guide.md   # (Optional) Docker notes
└── README.md

📌 Strategy Customization – Create Your Own Logic

This assistant is strategy-agnostic — you're not limited to Smart Money Concepts (SMC).

You can define and run any trading strategy simply by rewriting the prompt instructions.

✍️ How to Create a New Strategy

  1. Open ChatGPT → My GPTs
  2. Select your GPT (e.g., SMC Swing Trading cTrader)
  3. Click Edit GPT → Configure
  4. In the Instructions field:
    • Replace the existing SMC prompt with your own strategy guide
    • Describe how the GPT should analyze OHLC and chart image inputs
    • Specify what to detect (e.g., trend direction, breakout signals, RSI divergence, etc.)
    • Define entry/exit rules (market/pending orders, SL/TP logic, filters)

💡 Example:
“Use Fibonacci retracement zones (0.5–0.618) combined with bullish MACD crossovers to identify long entries. Confirm structure with higher-timeframe trend direction. Return: signal, SL, TP, and confidence.”

Once saved, the GPT will analyze live data from cTrader and generate trading decisions based on your strategy logic — no additional code needed.


🧠 Project Overview

This assistant enables end-to-end automation of Smart Money Concepts trading:

🔹 Backend (Python + FastAPI)

  • Connects to cTrader Open API via Twisted
  • Exposes endpoints for:
    • /analyze → complete SMC analysis pipeline (HTF bias, MTF zones, LTF entry)
    • /fetch-data → raw OHLC data per symbol/timeframe
    • /tag-sessions → tag M15/M5 candles with Asia/London/NY/PostNY
    • /session-levels → extract highs/lows by session (e.g. NY high/low)
    • /place-order → execute market/pending orders
    • /open-positions → list active trades
    • /pending-orders → list limit/stop orders
    • /journal-entry → log trades to Notion
  • Runs in Docker with automatic ngrok tunneling

🔸 Frontend (ChatGPT Custom GPT)

  • Built inside ChatGPT Plus under “My GPTs”
  • Automatically calls backend endpoints for:
    • 🔍 SMC trade analysis: CHOCH, FVG, OBs, liquidity, etc.
    • 📰 Macro event checking from Investing.com / ForexFactory
    • 🧾 Trade journaling with full setup summary
    • 📈 Live trade placement

🔬 New! Full Market Structure Analyzer (/analyze)

Instead of fetching candles and interpreting them manually, the /analyze endpoint automates full market analysis using Smart Money Concepts. It returns:

  • HTF bias (via D1 structure)
  • MTF OBs and FVGs (H4/H1)
  • LTF entry confirmation (M15/M5 sweep, candle, etc.)
  • Session high/low analysis (Asia, London, NY)
  • Previous day high/low
  • Macro news integration
  • SMC checklist status (CHOCH, OB, FVG, Sweep, Candle)

This powers most of ChatGPT’s decision-making.


🛠️ Setup Instructions

✅ Requirements

🌐 Deployment and Integration

🧠 1. Deploy Backend on Render (or Fly.io)

Render makes it easy to deploy your FastAPI backend:

  • Push code to GitHub
  • Connect repo to Render
  • Set environment variables manually (from your local .env)
  • Get a permanent public URL (e.g. https://your-service.onrender.com)

🤩 2. Connect Backend to ChatGPT

  • Inside ChatGPT Plus:
  • Go to Explore GPTs → Create → Configure
  • In Instructions, paste your trading logic (e.g., SMC)
  • In Actions, paste your gpt-schema.yaml
  • Under API Base URL, enter your Render public URL (e.g., https://your-service.onrender.com)

Done! You can now ask questions like: "Analyze EURUSD using SMC and journal the trade"

📦 Local Development (Optional)

  1. Clone the repo
git clone https://github.com/yourusername/chatgpt-smc-trading-assistant.git
cd chatgpt-smc-trading-assistant
  1. Edit with your:

    • cTrader clientId, accessToken, accountId
    • ngrok authtoken
  2. Run with Docker Compose

docker-compose up --build

But we recommend deploying it to the cloud for uninterrupted GPT access or ngrok to link the api to chatgpt.


🖼️ Screenshots

🧠 GPT Assistant (Frontend UI)

This is the interface of the custom GPT created for Smart Money Concepts trading analysis.

 GPT Assistant

🔍 GPT Setup (Instructions + Action Schema)

GPT Instruction Configuration GPT Setup

GPT Action Schema Integration GPT Setup

Example Natural Language Queries

  • Scan my 6-symbol list — EURUSD, NAS100, XAUUSD, GBPUSD, US30, BTCUSD — and give me the top 2–3 instruments showing the best SMC setups for today. Focus on clean structure, HTF alignment, and actionable intraday zones.
  • Analyze EURUSD for a swing trade setup
  • Reevaluate my EURUSD open position
  • Is my EURUSD trade still valid?
  • Should I move SL to breakeven on EURUSD?
  • Are there any major news events today?
  • What’s the macro outlook for EUR/USD this week?
  • Update me on any SMC confluence for EURUSD
  • Return all opened positions
  • Return all pending oders

Example Outputs

Analyze EURUSD for a swing trade setup

🔍 EURUSD – Full Top-Down SMC Swing Trade Analysis


📈 EURUSD Swing Trade SMC Analysis (as of Aug 19, 2025)


🟣 HTF (D1) Bias

  • Macro Structure: Sideways/Neutral trend.
  • Last Swing High: 1.17452 (July 25)
  • Last Swing Low: 1.14009 (July 29)
  • Current Price: 1.1663

Bias: Neutral, but leaning bullish as price is trading above the July 29 low and attempting to reclaim value inside July's range.


🔶 MTF Zones (H4 / H1)

H4

  • Macro Bullish OB: 1.15899 – 1.16175 (Aug 11, NY session close)
  • Minor Bearish OB: 1.17038 – 1.17153 (Aug 15, NY session)
  • Down FVG: 1.16817 – 1.17001 (Aug 15, NY session)
  • No CHOCHs observed.
  • Liquidity Sweep: Minor sweep of PDH on Aug 15 followed by retracement.

H1

  • Macro CHOCH: 1.16544 → 1.16756 (Aug 11 – Bullish shift)
  • Minor Bullish OB: 1.16471 – 1.16559 (Aug 19, Asia)
  • Down FVG: 1.16614 – 1.16679 (Aug 18)
  • Liquidity Sweep: Asia low sweep (1.1651) → price rejected back above 1.166.

🟢 LTF (M15 / M5) – Detailed Analysis

M15

  • Macro OB: None detected.
  • Minor Bullish OB: 1.16510 – 1.16560 (Asia session reaction)
  • FVGs: ✅ Up FVG: 1.16546 – 1.16586 (Post Asia reaction)
  • Sweeps: ✅ Sweep of Asia Low at 1.1651.
  • Candle Confirmations: ✅ Strong bullish engulfing at 03:00 UTC.

M5

  • Macro CHOCH: ✅ 1.16516 → 1.16585 (03:10 UTC breakout)
  • Minor Bullish OB: 1.16527 – 1.16548 (03:00 UTC)
  • FVGs: ✅ Bullish FVG: 1.16528 – 1.16554 (Post-CHOCH)
  • Sweeps: ✅ Confirmed Asia low liquidity sweep and rebound.
  • Candle Confirmations: ✅ Bullish engulfing + follow-through.

LTF Confluence Score:

  • Macro CHOCH: ✅ +15%
  • Minor OB: ✅ +8%
  • FVG: ✅ +15%
  • Sweep: ✅ +20%
  • Candle: ✅ +20%

➡️ Total: 78% (✅ Valid setup)


📌 Trade Recommendations

Limit Order: Buy

  • Entry: 1.16528 (M5 OB + FVG overlap)
  • Stop Loss: 1.16440 (below Asia low)
  • TP1: 1.16890 (inside H4 FVG)
  • TP2: 1.17150 (sweep of minor H4 OB)

Rationale: Post-Asia low sweep, bullish CHOCH, strong LTF confluence, rejection from M5 OB. No high-impact news within 4h. Clean internal liquidity target.


🛑 Risk Filters

  • ADR%: 38% (✅ acceptable range)
  • News: ❌ No high-impact events in next 4h.
  • Session: ✅ Transitioning into London Open (ideal for FX pairs).
  • Weekly Context: Neutral USD outlook — no major monetary catalyst.

📝 Suggested Journal Entry

  • Title: EURUSD LTF OB Reversal After Asia Sweep
  • Symbol: EURUSD
  • Session: London Open
  • HTF Bias: Neutral, leaning bullish
  • Entry Type: Sweep Reversal
  • Entry: 1.16528
  • SL: 1.16440
  • TP1: 1.16890, TP2: 1.17150
  • Order Type: Limit
  • Note: LTF bullish CHOCH after Asia liquidity sweep. Strong M5 confirmation.
  • Checklist: Macro CHOCH, M5 OB, FVG, Asia Sweep, Bullish Candle
  • News Events: None within next 4 hours
  • Chart URL: (can be added via platform screenshot)

Let me know if you want this trade journaled or visualized.


Limit Buy order placed successfully on EURUSD:

  • Entry: 1.16528
  • Stop Loss: 1.16440
  • Take Profit: 1.17150
  • Volume: 1.0 lot

Order is live and waiting for execution. Want me to monitor this or alert on activation/profit events?


📝 Trade Journal – EURUSD

Field Value
Title EURUSD – Asia Sweep into M5 OB Reversal
Symbol EURUSD
Session London
HTF Bias Neutral, leaning bullish
Entry Type Sweep Reversal
Entry 1.16528
Stop Loss 1.16440
Target Price 1.17150
Order Type Limit
Note M5 bullish OB + CHOCH + FVG after Asia low sweep
Checklist OB ✅ FVG ✅ Sweep ✅ CHOCH ✅ Candle ✅
News Events None

Would you like a visual SMC chart for this setup?

🧠 Trade Analysis Output Chart

Live OHLC analysis, SMC element detection, and structured journal suggestion.

ChatGPT Trade Analysis

Would you like me to journal this or place the trade?

📈 Order Execution via cTrader

Automatically places pending or market orders via the FastAPI backend.

Order Execution

📓 Notion Journal Entry

Posts the confirmed trades, with checklist, news context, and chart links into Notion.

Notion Entry



🔌 API Endpoints Reference

Endpoint Purpose
/analyze Full SMC analysis using all logic modules
/fetch-data Get raw OHLC data
/tag-sessions Tag each candle with Asia/London/NY label
/session-levels Get highs/lows for each trading session
/place-order Submit a trade via cTrader OpenAPI
/open-positions View currently open positions
/pending-orders View pending (limit/stop) orders
/journal-entry Save a trade with notes/checklist to Notion

⚠️ Disclaimer

This project is intended for educational and learning purposes only. Do not use it for real trading with live money. Always test with demo accounts as shown in the examples. Trading involves significant risk.


📄 License

This project is licensed under the MIT License.

About

Fully automated pipeline using FastAPI, cTrader Open API, and Docker. Analyze charts, journal trades to Notion, and place market/limit/stop orders across Forex, indices, and stocks — all in natural language (English, French, Spanish, and more) through ChatGPT.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published