AI Code Mode: Write, Save, and Run Trading Strategies

LamaTrader's Code Mode lets the AI write complete TypeScript trading strategy scripts, execute them in a secure sandbox, and save them to your personal strategy registry for one-click execution whenever you need them.
aicode-modefeatures

Code Mode is LamaTrader's most powerful AI capability. Instead of answering questions with text, the AI writes complete, executable trading strategy scripts in response to your plain-English descriptions. You review the code, approve it, run it in a secure sandbox, and save it to your personal registry — ready to execute on demand, forever.

This is what makes LamaTrader an Integrated Trader Environment rather than a trading app with a chatbot.

The Problem Code Mode Solves

A typical AI trading interaction is ephemeral. You ask a question, get an answer, and the session ends. Tomorrow you start from scratch — re-explaining your context, re-asking your question, re-interpreting the result. For one-off queries this is fine. For systematic trading strategies it's completely inadequate.

A real trading strategy is a program: scan a universe of symbols, filter by multiple criteria, evaluate account state, calculate risk metrics, construct the right order, log the result. That's not a chat interaction — it's code. Code Mode lets the AI write it.

How Code Mode Works

1. Describe your strategy in plain English

Switch to Code Mode in the AI panel and describe what you want. Be as specific or as high-level as your thinking is at that point — the AI will ask clarifying questions if needed.

Example: "Every Monday morning, check the IV rank on SPX. If it's above 40, find the 10-delta put and call strikes expiring that Friday, calculate the net credit for selling an Iron Condor, and place the order if the credit is at least $2.00 per share."

2. The AI writes the strategy

The AI produces a complete TypeScript strategy script using LamaTrader's full API surface:

  • Market data (quotes, options chains, screener data, IV calculations)
  • Account information (positions, buying power, Greeks)
  • Order construction and submission
  • Logging and structured output

3. Review the code

The script is displayed in full before anything runs. Read exactly what it will do, what data it accesses, what conditions trigger an order. Request revisions in plain English if the logic doesn't match your intent.

4. Approve and run

The strategy executes inside a secure QuickJS sandbox — an isolated JavaScript runtime with:

  • No access to your filesystem or operating system
  • No network calls outside LamaTrader's defined market data and execution APIs
  • Strict CPU and memory resource limits
  • Full execution logging with structured output

5. Save to your registry

When a strategy runs successfully, save it to your personal strategy registry with a name you choose. It's stored, versioned, and available for one-click execution at any time.

The Strategy Registry

The registry is your personal library of automated trading strategies. Each entry shows the strategy name, description, last run time, and last run result. Run any strategy against live market data in seconds — no re-prompting, no copy-pasting, no re-explaining.

The registry accumulates value over time. A strategy you build for Monday's Iron Condor routine runs every Monday. A portfolio delta check you built last month runs any time you want a second opinion on your risk. The more you use Code Mode, the more your personal trading automation library grows.

What Strategies Can Do

Code Mode strategies have access to LamaTrader's full API surface:

Market data

  • Real-time quotes for any symbol
  • Full options chain with live Greeks for any underlying and expiration
  • Historical price data for any timeframe
  • Screener data: top movers, most actives, IV rank across a symbol universe
  • News feed and economic calendar data

Account and portfolio

  • Current positions with entry price, current P&L, and Greeks
  • Open and pending orders
  • Account buying power and net liquidation value
  • Trade history

Order execution

  • Construct and submit any supported order type: market, limit, stop, bracket, OTO, OCO, multi-leg options combo
  • Cancel or replace open orders
  • Check fill status

Output

  • Structured results displayed as interactive widgets in the chat
  • Text summaries and logs
  • Alerts and notifications

Security Model

Our secure sandbox prevents any action outside the defined API boundaries:

  • Strategies cannot access your filesystem, browser storage, or operating system
  • All network calls are proxied through LamaTrader's API gateway — arbitrary HTTP requests are blocked
  • CPU and memory limits prevent runaway execution
  • Every execution is logged with a complete audit trail

You approve the strategy code before it runs. The sandbox enforces the boundaries after you do. Two independent layers of control.

Practical Examples

Weekly Iron Condor scanner Checks IV rank on a watchlist of underlyings every Monday. For any symbol with IVR above threshold, finds the target-delta strikes for the current weekly expiration, calculates net credit, and places the order if the credit meets your minimum.

Portfolio delta hedge check Calculates your current net delta across all equity and options positions. If net delta exceeds your threshold, calculates the hedge quantity (SPY puts or index futures) needed to bring it back to neutral and presents a recommendation.

Earnings volatility play setup For every symbol in your watchlist reporting earnings in the next three days, calculates the implied move from the options chain and checks whether selling an at-the-money straddle would generate a credit above your target. Returns a ranked list of candidates.

Position sizing calculator Given a symbol, an entry price, a stop price, and your target risk per trade in dollar terms, calculates the correct share quantity and pre-populates the order form.

Getting Started

Open the AI panel, switch to Code Mode, and describe a strategy. Start with something simple — a screener query or a position sizing calculation — to see the workflow in action. Build complexity from there as you get comfortable reviewing and approving the generated code.

Your registry starts empty. It won't stay that way.

Optimax Software LtdLama Trader
An Integrated Trader Environment for stocks, options, and crypto. Built by Optimax Software Ltd.
© 2026 Optimax Software Ltd · All rights reserved
All systems operational

LamaTrader provides technology, interface, analytics, and workflow software. This page is not an offer, solicitation, or advice to buy or sell securities or open a brokerage account.

Securities brokerage services, where applicable, for supported accounts are provided by Alpaca Securities LLC (dba "Alpaca Clearing"), member of FINRA and the Securities Investor Protection Corporation (SIPC). Alpaca is not affiliated with, endorsed by, or responsible for the products or services offered by Lama Trader. Any references to Alpaca on this site are made by the third party and do not imply a partnership, sponsorship, or recommendation by Alpaca.