Skip to main content

AI trading assistant for Telegram using chatGPT-4o (with Position Sizing)

Workflow preview

Workflow preview
100%
AI trading assistant for Telegram using chatGPT-4o (with Position Sizing) preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

MT5 AI Trading Assistant Telegram Bot Workflow with position sizing capabilities Open trades for forex/xauusd/gold with this n8n template. It demonstrates how to automate MetaTrader 5 trading execu...

Best for

  • Crypto Trading automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.telegram, n8n-nodes-base.httprequest, n8n-nodes-base.telegramtrigger, n8n-nodes-base.code, n8n-nodes-base.if, n8n-nodes-base.switch, @n8n/n8n-nodes-langchain.chainllm, @n8n/n8n-nodes-langchain.lmchatopenai

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Cj Elijah Garay.

Original n8n.io source

1.1 Workflow description

Title
AI trading assistant for Telegram using chatGPT-4o (with Position Sizing)
Workflow name
AI trading assistant for Telegram using chatGPT-4o (with Position Sizing)

MT5 AI Trading Assistant - Telegram Bot Workflow with position sizing capabilities

Open trades for forex/xauusd/gold with this n8n template. It demonstrates how to automate MetaTrader 5 trading executions through natural language commands via Telegram, enabling hands-free trade management with AI-powered intent classification and parameter parsing.

Use cases are many

Try executing market orders right away when you see an opportunity using commands, setting up limit orders with precise entry points, or managing pending signals directly from your phone! This workflow handles everything from simple "buy EU 1% 30 pip SL and 3R TP" commands to complex limit orders with risk-reward calculations.

Good to know

  • This template is for educational purposes only - requires significant security hardening before live trading use
  • OpenAI API costs apply - approximately $0.0001-0.0005 per message depending on complexity
  • Webhook endpoints are NOT authenticated by default - you must add authentication before production deployment or if you want extra security
  • No built-in position size limits - add validation to cap maximum risk percentage
  • MT5 Expert Advisor required - this workflow only sends signals; you need a separate EA to execute trades
  • Local/VPS deployment recommended - not suitable for public cloud without security hardening
  • Always test with demo accounts first - automated trading involves substantial risk of loss

How it works

  • The Telegram Chat Trigger listens for incoming messages from authorized users in your Telegram bot
  • A reaction emoji (👍) is immediately sent to acknowledge message receipt using the Telegram API
  • The first AI classifier (GPT-4o mini) analyzes the message intent and categorizes it into six types: trade execution, trade inquiry, help request, signal query, signal clear, or off-topic
  • For trade execution commands, a regex-based parser extracts parameters (asset, direction, risk, stop loss, take profit) from natural language
  • If initial parsing is incomplete or confidence is low, an LLM fallback parser attempts to extract missing parameters with strict validation
  • Complete trade parameters are routed through a Switch node to determine order type (market vs limit)
  • Market orders trigger an HTTP POST to webhook/mt5-market-order with asset, direction, risk, SL, and TP parameters
  • Limit orders include an additional entry price parameter and route to webhook/mt5-limit-order
  • For signal queries, the workflow fetches pending signals from webhook/mt5-signals and formats the response
  • Signal clearing commands POST to webhook/mt5-clear-all to remove all pending orders
  • Trade execution success/failure is validated and appropriate confirmation messages are sent back to Telegram
  • Help requests receive multi-part instructional messages with command examples and formatting guidelines

How to use

  • Set up your Telegram bot via BotFather and obtain your bot token
  • Configure the Telegram credentials in both the Chat Trigger and all response nodes
  • Add your OpenAI API key to the three "4o mini" language model nodes
  • Deploy the four MT5 webhook endpoints (market-order, limit-order, signals, clear-all) on your local machine or VPS
  • Critical: Implement authentication on all webhook endpoints before connecting to live MT5 accounts
  • Test commands with demo account first: try "buy EU 1% 30 pip SL 3R TP" or "show pending signals"
  • Consider adding user ID whitelisting in the "set credentials and params" node for access control
  • Modify the AI prompts in the classifier nodes to adjust trading parameter validation rules

Requirements

  • Telegram Bot API account for receiving and sending messages
  • OpenAI API key for GPT-4o mini language model (intent classification and parameter parsing)
  • MetaTrader 5 platform with custom Expert Advisor that listens to webhook signals
  • n8n instance running locally or on VPS (self-hosted or cloud)
  • Basic understanding of forex trading concepts (pips, risk management, order types)

Customising this workflow

  • Add a user whitelist validation node after the Telegram trigger to restrict access to specific Telegram user IDs
  • Implement maximum risk percentage caps (e.g., 5%) in the parameter validation nodes
  • Create an asset whitelist to only allow specific currency pairs your broker supports
  • Add audit logging by storing trade commands and execution results to a database
  • Include trade confirmation mode: send preview before execution and wait for "confirm" message
  • Integrate with position sizing calculators based on account equity and volatility
  • Add webhook authentication headers (API keys or JWT tokens) to all HTTP request nodes
  • Create a scheduled workflow to auto-expire pending signals after a certain time period
  • Try a popular use-case such as connecting to TradingView alerts instead of manual Telegram commands

Important Security Disclaimer

⚠️ This workflow is NOT production-ready in its current form.

Before using with live trading:

  • Add authentication to all webhook endpoints
  • Implement input validation for risk limits, asset whitelists, and parameter ranges
  • Add rate limiting to prevent spam attacks
  • Set up user authorization to restrict who can execute trades
  • Test extensively with demo accounts for at least 3-6 months
  • Understand that automated trading involves substantial risk of loss

This template is provided for educational purposes only and does not constitute financial advice. You are solely responsible for implementing security measures, testing thoroughly, and accepting all trading risks.

Purchasing this N8N workflow comes with the Metatrader5 and N8N Integration for Forex and Gold Trading via Webhooks Workflow too so it is sold together and vice versa as well along with the MQL code for the ExpertAdvisor listener all for the price of 120 usd total

Questions?

If you have questions or need help with this workflow, feel free to reach out:

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - respond: all clear

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 2 - respond: No pending signals

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 3 - respond: No pending signals1

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 4 - respond to query

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 5 - respond: missing params

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 6 - respond: LLM fallback

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 7 - respond: error1

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 8 - respond: http req error

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 9 - respond: trade placement success

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 10 - respond: error in trade placement

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 11 - react to message

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 12 - respond: part 1

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 13 - respond: part 2

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 14 - respond: part 3

Type / Role
n8n-nodes-base.telegram - telegram
Config choices
Version 1.2

Block 15 - Telegram Chat Trigger

Type / Role
n8n-nodes-base.telegramTrigger - telegramTrigger
Config choices
Version 1.2

Block 16 - parse ai response1

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 17 - if there is an error1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 18 - HTTP Request send market order1

Type / Role
n8n-nodes-base.httpRequest - httpRequest
Config choices
Version 4.2

Block 19 - Switch2

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.3

Block 20 - parse LLM output1

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 21 - Trading Assistant Classifier & Responder2

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.7

Block 22 - Trading Assistant Classifier & Responder3

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.7

Block 23 - If trade was successful1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 24 - Switch3

Type / Role
n8n-nodes-base.switch - switch
Config choices
Version 3.3

Showing the first 24 of 48 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow AI trading assistant for Telegram using chatGPT-4o (with Position Sizing)
Complexity advanced
Nodes 48
Categories Crypto Trading, AI Chatbot
Author Cj Elijah Garay
Published 03 Dec 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/11461/11461.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does AI trading assistant for Telegram using chatGPT-4o (with Position Sizing) do?

MT5 AI Trading Assistant Telegram Bot Workflow with position sizing capabilities Open trades for forex/xauusd/gold with this n8n template. It demonstrates how to automate MetaTrader 5 trading execu...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Crypto Trading, AI Chatbot use case.