Home MarketXLS
Dashboard MarketXLS
Screener MarketXLS
Options Profit Calculator MarketXLS
Stock Ranks MarketXLS
Spreadsheet Builder MarketXLS
Documentation MarketXLS
Logout MarketXLS

TradeSingleLegThinkOrSwim: Execute Single-Leg Orders Directly from Excel

The TradeSingleLegThinkOrSwim function allows you to place single-leg trades on the ThinkOrSwim platform directly through Excel. Whether you’re sending equity or options orders, you can pass in key parameters—such as quantity, side, order type, and duration—right in your spreadsheet. This function helps streamline the workflow by reducing the need to switch between your Excel models and a trading platform, enabling faster and more efficient order execution.

Why Use This Function?

  • Simplify Trade Entry: Enter orders for both equities and options from a familiar Excel interface.
  • Direct Integration with ThinkOrSwim: Avoid manual entry in ThinkOrSwim by letting MarketXLS handle order formatting.
  • Automated Checks on Inputs: Built-in validations (e.g., order side, order type) reduce mistakes or typos.
  • Versatile Usage: Supports Market, Limit, Stop, and Stop Limit order types.
  • Accommodates Extended Durations: Advanced durations like “ext_am” and “gtc_extended” can be handled for after-hours or discrete order preferences.
  • Streamlined Options Symbol Handling: Automatically re-formats complex option symbols for ThinkOrSwim compatibility.

Real-world scenario: Automate daily trading strategies on US stocks or options by referencing dynamic cell values (like current price, limit price, quantity) directly within Excel formulas.

How to Use in Excel

=TradeSingleLegThinkOrSwim(TradeType, Symbol, Quantity, OrderSide, OrderType, [Duration], [SymbolOption], [Price], [TriggerPrice])
  1. In an Excel cell, enter the function name followed by the required parameters.
  2. For optional parameters (Duration, SymbolOption, Price, TriggerPrice), either include them or rely on default values if applicable.
  3. Press Enter to see the function response—which can be an order confirmation string, an error message, or “NA” if something unexpected occurs.

Parameters Explained

Parameter Description Example Values Notes
TradeType Specifies whether this is an equity or an options trade. "equity", "options" If not recognized, returns "Tradetype can be either equity or option". For "options", SymbolOption is usually required.
Symbol The underlying symbol (equity ticker if TradeType is equity; root for the option if TradeType is options). "AAPL", "TSLA" For an options trade, this helps identify the underlying ticker. Keep under 5 characters for typical equity tickers.
Quantity Number of shares (equity) or contracts (option) to be traded. 100, 500, 1 Must be an integer. If invalid, returns "Quantity has an invalid format. Please check your inputs."
OrderSide Indicates buy/sell direction for equities, or buy/sell to open/close for options. "buy", "sellshort", "buytoopen" For equities: "buy", "sell", "sellshort", or "buytocover". For options: "buytoopen", "selltoclose", etc. Invalid entries return "Order side is invalid. Please check your inputs."
OrderType Trade order type. "MARKET", "LIMIT", "STOP", "STOPLIMIT" MARKET handles immediate execution, LIMIT requires Price, STOP/STOPLIMIT requires TriggerPrice and Price. If invalid, returns "Order type is invalid. Please check your inputs."
Duration (Optional) Time-in-force for the order. Supported durations include day, gtc, ext_am, ext_pm, extended_hours, or gtc_extended. "day", "gtc", "ext_pm" Default is "day". Pass a valid string to ensure correct TIF is used. An invalid or empty string reverts to "day".
SymbolOption (Optional) The option symbol details when placing an options trade. "@F1234567890123456789" For certain formats (e.g., length=22 starting with "@") it is auto-converted. Otherwise must be in a recognized format (>15 and <21 chars). If invalid, it returns "error". Not required if TradeType="equity".
Price (Optional) Used for Limit, Stop, or Stop Limit orders to specify the limit or stop price. 150, 10.5 If Price = 0 for non-market orders, the function may return an error. For buy STOP/STOPLIMIT, Price must be ? TriggerPrice; for sell STOP/STOPLIMIT, Price must be ? TriggerPrice.
TriggerPrice (Optional) Used primarily for STOP or STOPLIMIT orders. 149.5, 10 Combined with Price to set the stop limit range. If set to 0 for a STOP or STOPLIMIT order, returns an error.

Example Usage

Basic Examples

  1. Place a Market Buy for Equity
    • Formula:
    =TradeSingleLegThinkOrSwim("equity", "AAPL", 100, "buy", "MARKET")
    • Explanation: Sends an order to buy 100 shares of AAPL at the current market price.

  2. Place a Limit Sell for Equity
    • Formula:
    =TradeSingleLegThinkOrSwim("equity", "MSFT", 50, "sell", "LIMIT", "day", "", 300)
    • Explanation: Sells 50 shares of MSFT with a day limit at $300. SymbolOption is left blank because it's not an options trade.

  3. Place a Market Buy to Open for Options
    • Formula:
    =TradeSingleLegThinkOrSwim("options", "TSLA", 1, "buytoopen", "MARKET", "day", "@TSLA 230623 C 300", 0, 0)
    • Explanation: Buys 1 TSLA contract at market, day order. The SymbolOption parameter is recognized in “@xxxxx” format, which gets converted if needed.

Advanced Scenarios

  1. Stop Limit Order for Equities
    • Formula:
    =TradeSingleLegThinkOrSwim("equity", "NFLX", 100, "sell", "STOPLIMIT", "gtc", "", 280, 285)
    • Explanation: Places a GTC stop-limit order to sell 100 shares of NFLX. The stop (trigger) price is 285, and the limit price is 280.

  2. Extended Hours with Options
    • Formula:
    =TradeSingleLegThinkOrSwim("options", "SPY", 2, "selltoclose", "LIMIT", "ext_pm", "SPY_230630_C_390_XXXX", 4.5, 0)
    • Explanation: Sells to close 2 SPY call contracts with a limit price of 4.5, eligible for extended PM hours. If the SymbolOption string is in an acceptable format, it’s reformatted for ThinkOrSwim.

  3. Buy to Open with a Stop Order for Options
    • Formula:
    =TradeSingleLegThinkOrSwim("options", "AMD", 5, "buytoopen", "STOP", "day", "@AMD 230728 P 100", 95, 90) • Explanation: Places a STOP order for AMD puts, with TriggerPrice of 90 and Price of 95. Because it’s a buy order, the code checks that Price ? TriggerPrice.

Common Questions and Troubleshooting

• Q: Why do I get “Please check your inputs”?
A: Ensure you’ve used a valid TradeType (“equity” or “

Get Access to 1 Billion Usable Market data points IN YOUR EXCEL SHEETS WITH EASY TO USE EXCEL FUNCTIONS

Get started today
MarketXLS Excel Add-in Tutorial - How to Use Trade Single Leg ThinkOrSwim and Other Financial Formulas
How does MarketXLS work?