CORTEXFLOW · FREE FOREVER

Automation

AI Stock Analysis Reports

↓ Download workflow JSON

Import in n8n: Workflows → ⋯ → Import from file, then add your credentials. Free download with a free account.

How it works

A 4-workflow multi-agent system that produces institutional-style stock reports. Download and import all four JSON files — they work as a team:

  1. ai-stock-reports.json — Main Orchestrator. Two triggers start it: a Schedule Trigger (every Monday 06:20) loops over a 15-ticker watchlist (LLY, UNH, JPM, V, XOM, HD, CAT, AAPL, MSFT, NVDA, AMZN, GOOGL, META, AVGO, COST), and a form trigger (“Manual Entry: Stock Analysis”) lets you analyze any single ticker on demand. Each ticker is passed to the Execute Workflow node, which calls this same workflow’s AI agent section.
  2. The AI Agent (Google Gemini) acts as orchestrator: it must call all three sub-workflow tools — technical_analysis, then trends_analysis, then fundamental_analysis — and synthesizes everything into a strict JSON report (recommendation, sentiment counts, chart URL, technical write-up, top articles, hot topics). Window Buffer Memory gives it short-term context.
  3. ai-stock-reports-technical.json — Technical Analysis. Validates the ticker on NASDAQ/NYSE via TwelveData, then pulls 180 days of price history, Bollinger Bands, MACD, and a TradingView chart image (Chart-IMG). A Code node computes Fibonacci levels plus support/resistance; GPT-4o Vision reads the chart (RSI, trend, candlestick patterns); a senior-analyst prompt merges it all into five sections.
  4. ai-stock-reports-fundamental.json — Fundamental Analysis. Pulls company Overview, Income Statement, and Balance Sheet from Alpha Vantage (with 12s waits between calls to respect rate limits), then an AI analyst extracts description, key metrics (MarketCap, P/E, EPS), and two-year revenue/net-income trends into clean JSON.
  5. ai-stock-reports-trends.json — Trends & News Analysis. Fetches Alpha Vantage news sentiment for the ticker, then a Code node counts bullish/neutral/bearish articles, averages the sentiment score, and ranks hot topics.
  6. Back in the main workflow: if the recommendation title contains “Buy”, a $7,000 paper buy order fires on Alpaca. The report JSON is rendered into a styled HTML email (sentiment-colored sections) and emailed via SMTP.

Set up steps

You’ll need:

  • n8n (self-hosted or cloud)
  • A TwelveData API key — twelvedata.com (price/exchange validation + indicators)
  • An Alpha Vantage API key — alphavantage.co (fundamentals + news sentiment)
  • A Chart-IMG API key — chart-img.com (TradingView chart images)
  • A Google PaLM/Gemini API key — aistudio.google.com (main orchestrator agent)
  • An OpenAI API key — platform.openai.com (vision + analyst prompts; used via OpenRouter-compatible model IDs)
  • SMTP credentials for sending the report email
  • (Optional) Alpaca paper-trading API keys — alpaca.markets (paper account)
  1. Download all four workflow JSONs using the download button on this page (main file) plus:
    • /templates/ai-stock-reports-technical.json
    • /templates/ai-stock-reports-fundamental.json
    • /templates/ai-stock-reports-trends.json
  2. In n8n, go to Workflows → ⋯ → Import from file and import all four files.
  3. Link the three tool nodes — open the main workflow and, in each of Technical Analysis Tool, Trends Analysis Tool, and Fundamental Analysis Tool, click the workflow field and select the matching imported sub-workflow.
  4. Link the Execute Workflow node — open Execute Workflow in the main workflow and select the AI Stock Analysis Reports — Main Orchestrator workflow itself (this is how the loop feeds tickers into the agent section).
  5. Paste API keys into the Set nodes — open Set Stock Symbol and API Key (technical workflow) and paste your TwelveData key; open Set Variables (fundamental) and Set Variables1 (trends) and paste your Alpha Vantage key. Nothing else in these nodes needs changing.
  6. Create credentials — Credentials → New: Google PaLM API (select in Google Gemini Chat Model), OpenAI (select in First Technical Analysis, ChatGPT 4o, ChatGPT 4o1), Header Auth named Chart-IMG API Key (select in Get Chart URL), SMTP (select in Send Stock Analysis), and optionally Header Auth named Alpaca API Key (select in Buy in Alpaca; also paste your key ID/secret into the node’s header values).
  7. Email addresses — open Send Stock Analysis and replace PASTE_YOUR_EMAIL_HERE in both To and From with your email.
  8. Activate all four workflows (toggle, top-right of each). The sub-workflows are called as tools, but n8n requires them active to be executed.

Customize it

  • Your watchlist — edit the tickers array in the Stock List node (any NASDAQ/NYSE symbols).
  • Schedule — open Schedule Trigger and change the day/time (currently Monday 06:20).
  • Trade size — in Buy in Alpaca, change "notional": 7000 to your amount. The URL already points at Alpaca’s paper API — switch to https://api.alpaca.markets only if you truly want live trading.
  • Disable auto-buy — delete or deactivate the Buy? → Buy in Alpaca branch to keep it reports-only.
  • Buy threshold — Buy? fires when the recommendation title contains “Buy”; tighten it (e.g. also require overallSentiment = Bullish) with an extra condition.
  • Email design — the Generate HTML node holds the full email template; the Adjust HTML Colors code node recolors sections by sentiment automatically.
  • Swap the brain — the main agent uses Google Gemini; point Google Gemini Chat Model at any Gemini model, or swap the node for an OpenAI chat model.

Workflow nodes

This workflow is built from 23 nodes. Here's what each one does:

#NodeTypeWhat it does
1 Schedule Trigger Schedule Trigger Starts the workflow automatically on a schedule.
2 Stock List Set Holds editable configuration values — fill in your own settings here before activating.
3 Split Out Split Out Splits one item containing a list into many items.
4 Loop Over Items Split In Batches Processes a long list of items in small batches.
5 On form submission n8n Form Trigger Starts the workflow from an n8n form submission.
6 Set Ticker for AI Agent Set Holds editable configuration values — fill in your own settings here before activating.
7 Execute Workflow Execute Workflow Calls another n8n workflow as a sub-workflow.
8 If IF Splits the flow into branches based on a condition.
9 Wait Wait Pauses the workflow until a condition or time is met.
10 When Executed by Another Workflow Execute Workflow Trigger Lets this workflow be called as a sub-workflow from another workflow.
11 AI Agent AI Agent The AI brain — reasons over the task and calls tools to get it done.
12 Google Gemini Chat Model Google Gemini Chat Model The language model powering the AI agent (Google Gemini).
13 Think Think Tool Lets the agent 'think' step-by-step before acting.
14 Structured Output Parser Structured Output Parser Forces the AI to return clean, structured JSON instead of free text.
15 Technical Analysis Tool Workflow Tool Exposes a sub-workflow as a tool the AI agent can call.
16 Trends Analysis Tool Workflow Tool Exposes a sub-workflow as a tool the AI agent can call.
17 Fundamental Analysis Tool Workflow Tool Exposes a sub-workflow as a tool the AI agent can call.
18 Buy? IF Splits the flow into branches based on a condition.
19 Buy in Alpaca HTTP Request Calls an external API or webhook endpoint.
20 Generate HTML HTML Renders an HTML page as a workflow response.
21 Adjust HTML Colors Code Runs custom JavaScript to transform, filter, or compute data between steps.
22 Send Stock Analysis Send Email (SMTP) Sends email through your SMTP server.
23 Window Buffer Memory Window Buffer Memory Gives the agent short-term chat memory across messages.

Setup instructions

1. Add your credentials

In n8n go to Credentials → New, create each credential below, then open the named node and select it:

NodeCredential to add
Google Gemini Chat Model Google PaLM / Gemini API
Buy in Alpaca HTTP Header Auth
Send Stock Analysis SMTP

2. Fill in your config values

Open the config node listed below and replace each placeholder with your own value before activating the workflow:

NodeFieldWhat to paste
Send Stock Analysis toEmail PASTE_YOUR_EMAIL_HERE
Your email here
Send Stock Analysis fromEmail PASTE_YOUR_EMAIL_HERE
Your email here

How this workflow starts

  • Schedule Trigger: Runs every weeks.
  • Form Trigger: Form "Manual Entry: Stock Analysis" — share the generated form URL to collect submissions.
  • Execute Workflow Trigger: Fires automatically on its event — activate the workflow and connect the service.

Use cases

A four-workflow multi-agent system that produces institutional-style stock research every week. The main orchestrator runs on a Schedule Trigger every Monday at 06:20, loops over a 15-ticker watchlist with Loop Over Items, and a form trigger ("Manual Entry: Stock Analysis") allows on-demand analysis of any single ticker. Each ticker is fed through Execute Workflow into an AI Agent on the Google Gemini chat model, which must call all three sub-workflow tools in order — Technical Analysis Tool, then Trends Analysis Tool, then Fundamental Analysis Tool — and synthesizes everything into a strict JSON report: recommendation, sentiment counts, chart URL, technical write-up, top articles, hot topics. The technical sub-workflow validates the ticker via TwelveData, pulls 180 days of price history with Bollinger Bands and MACD, renders a TradingView chart image via Chart-IMG, computes Fibonacci levels and support/resistance in a Code node, and has GPT-4o Vision read the chart. The fundamental sub-workflow pulls company Overview, Income Statement, and Balance Sheet from Alpha Vantage (with 12-second waits between calls to respect rate limits) and extracts MarketCap, P/E, EPS, and two-year revenue and net-income trends. The trends sub-workflow fetches Alpha Vantage news sentiment and counts bullish, neutral, and bearish articles with hot-topic ranking. Back in the main workflow, if the recommendation title contains "Buy," a $7,000 paper buy order fires on Alpaca; Generate HTML renders the report into a styled email, Adjust HTML Colors recolors sections by sentiment, and Send Stock Analysis emails it via SMTP. These are research aids for study and decision support, not financial advice — and the buy branch can be removed to keep the system reports-only.

The retail investor's Monday watchlist review

An investor tracking fifteen US stocks used to spend Sunday evenings assembling research from five websites. The Monday 06:20 run does it while he sleeps: by breakfast, one styled HTML email covers all fifteen tickers with the same structure — technicals, fundamentals, news sentiment, recommendation. The sentiment-colored sections from Adjust HTML Colors let him triage visually before reading a word. Practical tip: edit the tickers array in the Stock List node — any NASDAQ or NYSE symbols work, and the TwelveData validation step rejects bad tickers before they waste API calls.

The investment club's shared research desk

An eight-member investment club argues from different data every month because everyone researches differently. The strict JSON report schema fixes that: every ticker gets the same sections, the same sentiment counts, the same structure, so the club debates conclusions instead of data. The top articles and hot topics fields give the meeting its discussion agenda. Because the sub-workflows are separate imported files called as tools, the club's technically inclined member can improve the technical analysis once and every future report benefits. Practical tip: move the Schedule Trigger to Sunday evening so the reports are waiting when the club meets Monday night.

The finance newsletter writer's research assistant

A newsletter author covering markets needs a research draft per stock without spending a day per stock. The form trigger is her tool: type a ticker into "Manual Entry: Stock Analysis" and get the full three-agent report on demand, with the technical write-up and top articles sections serving as the draft's backbone. She rewrites in her own voice — the workflow is a research starting point, not publishable copy. Practical tip: delete or deactivate the Buy? to Buy in Alpaca branch. A writer has no use for paper orders, and reports-only mode keeps the workflow simpler and cheaper to run.

The paper trader testing strategy ideas

A swing trader wants to test whether acting on the agent's recommendations would have worked, without risking money. The Alpaca integration already points at Alpaca's paper API: when the recommendation title contains "Buy," Buy in Alpaca places a $7,000 notional paper order, creating a real track record of the strategy's calls. The notional value is editable to match his actual position sizing. Practical tip: tighten the Buy? condition — for example, also require the overall sentiment to be Bullish — so the paper portfolio only acts on high-conviction calls, which is the version of the strategy worth evaluating.

The finance student learning real analysis

A finance student finds textbooks abstract and real analyst reports opaque. Watching this system work teaches the structure of equity research: the agent must call technical, then trends, then fundamental analysis, mirroring how professionals triangulate price action, news flow, and financials. The Fibonacci and support/resistance Code node shows how levels are computed, not just asserted, and the sentiment-colored HTML makes the relationship between news tone and recommendation visible. Practical tip: use the "swap the brain" customization — point the Google Gemini Chat Model at different Gemini models and compare how the recommendations change, which is itself a lesson in model sensitivity.

← All templates