Where to go with your trading bot software?

Well, this is quite a crossroads. My automated options trading platform has been running almost flawlessly (with a good number of users letting it manage their portfolios) for nearly 5 years. I had leveraged the TD Ameritrade API to it’s fullest extent and built an outstanding app with tens of thousands of lines of code. It is one of my greatest creations.

But Schwab is going to be shutting down the TDA API. My plan was to port over to the API Schwab is releasing, but after some research, I was a little dubious. It is not clear that the API will be available in time, and you have to get approved as a company to get the commercial version. People use and love my software . . . . but I don’t charge them.

So I thought I would take a look at Tastytrade, since I had been pining for them to release an open API years ago. At a glance, it looked great. They have a more simple and logical means of authenticating and there is even an open source TypeScript sdk to use (perfect).

However, I discovered very quickly that in order to get the option prices and greeks, you have to subscribe to a streaming connection (which is much different from the https REST only method I use with TD Ameritrade). Ok, that would take a lot more effort to make such a big shift, but after mulling it over, I got used to the idea.

So, I contemplated how to drive my automatic trading when I’m getting data streamed to me, rather than making my https calls to a server. I would take some creativity, but I figured I was up for the task.

Then, on my second day of working with the Tastytrade API, their production API stopped responding….for hours….during trading hours. Not a good sign.

Now I’m back to looking at Schwab. Stay tuned.

Petition for Tastyworks to create a public API

It has become apparent in the past few weeks that Tastyworks is the best brokerage for traders in the United States. Not only did they recently achieve the #1 spot in Investor’s Business Daily’s online brokerage survey, but more importantly they stood strong through the Gamestop short squeeze. When the other brokers killed people’s ability to freely trade popular stocks and options, Tastyworks did all they could to keep things open. However, the only thing that is preventing them from being a true big player in the brokerage space is the lack of an API for their customers (application programming interface). Then there would be no reason to trade with anyone else.

At the beginning of 2021, TD Ameritrade was considered the top broker for traders. That was until the WallStreetBets crowd started driving up the price of GameStop stock, and in a panic TD Ameritrade (among other brokers) shut off trading for stocks they deemed too volatile. But these were not crazy penny stocks with no liquidity that you couldn’t trade, they were important companies like AMC, BBBY, BB, NOK, and about 15 others! At the time of this writing, I still cannot sell a simple cash secured put on AMC (the bread and butter trade for option traders) with TD Ameritrade. It is entirely ridiculous and insulting.

Yet, Tastyworks proves what Tom Sosnoff has always said about his brokerage; they are a company built by traders and built for traders. Through it all, to the best of their ability, Tastyworks keeps letting traders trade. Not to mention, nobody can compare to their accessibility to customers, especially when you can call into their daily Tastytrade shows and talk to them on-air. So with all of that great stuff, why do they need an API?

First off, an API allows any developer to create software or scripts that can log in to the broker as a user and execute trades. In this technology world, where more and more individuals are opening trading accounts, that is important. We need the freedom to develop automation that can execute our strategies if we are busy. Also, we need commercial developers, like Option Alpha, to be able to connect to our brokerage accounts so we can use their tools to give us an edge that is only available to the professionals.

Not only is providing an API for customers all about giving them freedom, but it is great business for the broker. My own bot executes around 30-40 trades per day, which is considerable commissions that are currently going to TD Ameritrade. I would prefer it if that money went to Tastyworks.

So when Tastyworks does release an API to their customers, I will post guides on this blog that help people connect and develop their own tools. Let’s hope that happens soon!

-J. Arthur Squiers

Your trading bot process

My bot goes through an execution process every five minutes. The actual workflow is really quite simple. You could make your bot execute much more often, almost approaching high frequency trading. But for what I do, that would be unnecessary and a waste of processing resources.

Here is the basic flow I use:

Step 1: Find any trades that should be closed. This was actually all my bot did at first, as it is the most beneficial thing to automate, in my opinion. For anyone who is building their own trading bot, I recommend simply creating logic that can close trades and only using that for a while. This helps a person get used to trusting their code to execute trades. It’s not that big of a deal if your bot malfunctions and starts closing trades on you. It can be kind of a big deal if the bot starts opening a ton of trades that you don’t want it to–especially if you are not available to kill the bot and close out of those trades right away.

When my bot goes through its execution cycle, it first looks at all the open positions I already have. I accomplish this by calling the order history API to see my past orders, so I can add any new positions to my list. Once my bot is able to look at the positions I have, it will determine if any of the rules for closing are met, such reaching a profit that is 50% of the credit I received for the put. If the rule is met, a closing trade for that position is sent to the broker’s API.

Step 2: Find new trades: This part is more complicated, and something you want to test thoroughly. In my bot, I am able to specify all of the stock tickers that I want to consider for potential trades. The bot process will call the broker API and get option chain information for each of those tickers for which I’m not already holding a position. Then, based on criteria such as stock price, liquidity, and available expirations, the logic will decide if a trade should be opened.

After coming up with potential trades to open, the bot goes through some final checking to make sure I wouldn’t be adding more notional risk than I want to take for the portfolio. If everything looks good, an order is sent to the API to open a trade.

From a high level, that’s it! Granted, my code is actually way more complex than that, because I wanted to make a bot that is flexible and can be configured to execute any strategy. But a person should definitely not start out that way. There is nothing wrong with creating a bot that is hard coded to execute a specific strategy.

Building your trading bot, step 1

If you are going to build your own trading bot, the first thing to do is connect to a brokerage through their API (application programming interface). Without being able to establish this connection, your bot will be worthless. So you need to make sure you are able to get this plumbing working first, or you’ll be wasting your time. I have tested out many brokerage APIs (if they even have one), so I will give my synopsis here:

TD Ameritrade: In my opinion, this is currently the best brokerage for bot trading and the one I currently use. Their API is very deep and full featured. It does have a few quirks (like an ALL_OR_NONE flag, which I wanted to use to prevent partial fills, isn’t usable), but I can work around those things. My one concern with TD Ameritrade is that Schwab (who recently acquired them) has not confirmed whether they will keep the API around in the future. If they ever ditch it, I will have to switch brokers.

eTrade: From a pure functionality standpoint, this was the next best API I found. The problem is that they have their authentication setup so that you would manually have to re-authenticate your bot every day in order to keep the bot connecting. This is okay if you plan to run your bot and be around to monitor it. However, that does not pass my test of being able to go on vacation for a week and trust that your bot will keep making money for you passively. eTrade does have a way to bypass this problem if you get approved as a vendor, but that involves setting up a demo where you have to show your application to their technical team and get their blessing. No thanks.

Tradestation: I had high hopes for Tradestation, as they initially seemed to meet all my requirements. They have an API that handles option trading well, and they are good about letting you establish an authentication where you don’t have to manually re-authenticate daily. However, after digging in I discovered that their API really doesn’t provide a usable order history. My entire bot revolves around the order history. While it would be possible to create a bot with this API, if anything gets messed up in your own data storage of your position history, there isn’t a good way to recover from that. No order history is a non-starter for me.

Interactive Brokers: I’ll be honest, I do have a bias against IB. Their pricing model has always felt off putting to me. And last I checked, their API is not a true API because you have to be running the IB software on your computer as sort of a gateway in order to make it work. This doesn’t bode well if you want to run your bot on a server, where you don’t have to rely on your own computer to always be up and running. So this is not an option for me, though others may be able to get it to work for them.

Once you have settled on a broker, you should decide on a programming language to use and write a simple piece of code that can authenticate to the API and retrieve data about your account.

I chose to use TypeScript for several reasons. First off, it is simply object oriented JavaScript and I think JavaScript is the most useful language to be proficient with, given that it can be found everywhere (browser and server side). Also, most APIs return data in the JSON data format, which is derived from the JavaScript syntax, and JSON goes hand in hand with the JavaScript language. I didn’t want go all the way to using Java, because while I’ve worked with Java for almost 20 years, I can write code much faster and cleaner with TypeScript. Plus, the compiling an deploying of Java code creates a lot more overhead.

Most examples of trading bots that you can find on the internet will be written in Python. I wouldn’t discourage anyone from using Python, if they are set on it. My reason for not using Python is that I find TypeScript code to be a lot cleaner and more readable. Not to mention, I already know JavaScript extremely well.

I won’t get too deep into the technical details of writing the connection code in this post, as most brokers have some good examples on their API site. For the most part, you will create a simple web page that allows you to authenticate with your broker and get a token that you can store. Once you have that token, your bot code can use it to authenticate with the API and make calls to get data and submit trades.

In subsequent posts, I will give some examples.

Bot trading: How to get started

First and foremost, I recommend finding a trading strategy that will work for you in a bot trading system. The last thing you want to do is go out and build or subscribe to a bot trading platform when you have no trading plan that fits your temperament and provides a high probability of success.

The strategy I settled on was selling naked puts. There are multiple reasons for this:

  1. Put selling is simple and repeatable. I do not believe in implementing a lot of strategies, nor creating complexity. All truly successful (long term) option traders I have known have found one strategy that they studied and became very good at. And they just keep repeating that simple strategy over and over.
  2. Put selling is easy to automate. Even though I have multiple enter and exit criteria for the trades, it was easy to configure.
  3. I have found selling naked puts provides the best probabilities and risk/reward control for me. It also takes the most pure advantage of option pricing and implied volatility. In other words, there is no more direct way to sell “insurance” to fear in the market than by selling naked puts.
  4. I do not need to take on leverage. My puts sold are always secured by cash. To make up for not using leverage, I have tweaked my strategy to make sure I have a lot of trade turnover.

Note: I used to sell long dated strangles, but that was when I traded by hand. And there was nothing wrong with that. Now that I am actually capable of using the law of large numbers through the use of my bot, I have the best results when selling puts around 45 days until expiration, near the 30 delta strike. After having used my trading bot for over a year, I would never try to manually sell options and expect to see the probabilities advantage again.

Once you have settled on your strategy, then it’s time to decide how to automate it. Since I know how to code, I chose to program mine using the TypeScript language. If you have no desire to write code, there are trading bots out there that can be used for a subscription fee. I know OptionAlpha has been working on releasing a high quality offering. There may also be open source or free bots available, though I’m not sure if there are any that handle options.

As I post more, I will talk about how I built my own bot from the ground up.

Why Bot Trading

Passive income is the best type of income. I think everyone can agree on that. But what if you are into trading? Well, that’s not really passive is it? No, usually not. You may like to think it is, but if you have to sit there and “trade” all day, you are not earning passive income. If you can not go on a trip for two weeks and know the entire time that you are still earning money while not even thinking about it, it is not passive income.

Yet, there is a way to earn passive income with trading. Some call it algorithmic trading. Some call it automated trading. But many just refer to it as “bot trading.” When you are bot trading, you are allowing software to make trading decisions on your behalf and execute the trades for you. If done right, it can become a passive income source that keeps works for you while you focus on other things, like a full time career or that all important leisure time.

I spent years building my own bot trading system. Since I have found it to be so rewarding and inspiring, I decided dedicate this blog to it. Hopefully it will be something that inspires you as well!

How I finesse my trades

I follow my trading plan with discipline, that is one of my secrets. However, there are some subtle things I do that I call “finessing my trades.” These are little tweaks and techniques that I use to allow some trader intuition without violating my trading plan. They are not required for the plan to work, but they can help squeeze a few more dollars out of the market without adding unnecessary risk.

Moving the calls in closer

By default, my plan suggests selling the 10 delta call and put. However, I will sometimes push the call down to 12-14 deltas.

You see, a lot of premium sellers like to carry negative overall portfolio delta, to offset losses on their positions when the market goes down and volatility expands. So they add a separate hedge, such as selling calls on the S&P 500, or buying puts.

I have never had a good experience with adding these hedges. They always create too much drag. However, sometimes pushing the call down a little on the strangles does add a very subtle premium sellers hedge without creating noticeable drag.

Transitioning from low volatility to high volatility

Premium sellers claim to like a high IV market, but if it suddenly arrives after a period of low IV, there is often panic. The positions they have on are suddenly showing significant losses due to IV expansion, and they don’t have extra buying power available to take advantage of the newly expanded premium. Otherwise, they might have kept usable cash on the sidelines, but that often means waiting for an IV spike forever without the money earning anything.

So I have some finesse I use to help this low IV to high IV transition. First, I will start taking all small winners off when there is a big increase in volatility. The mindset here is to not be married to any particular position. While I don’t want to lock-in any losers, taking small winners off will free up buying power to be put to use on a better trade that is likely to benefit from the IV spike.

Another method I use to help take advantage of a new IV spike is to look for existing positions that have much less days till expiration than I usually start with, and roll them out in time. This not only improves the cost basis of the position (more credit taken in), but it increases the vega of those positions–so when IV calms down, they have a stronger increase in profitability.

Those are a couple of the ways I add finesse to my trading. I will be sure to post some more tips soon.

Trade smart.

J. Arthur

How to use the Fire By Arthur Trading Engine

The Fire By Arthur trading engine was first created out of frustration that there was no way for Tastyworks options sellers to easily keep track of defensive rolls and overall position P/L throughout the life of a position.

When using this trading engine, the only real manual data entry required is to enter the amount of additional credit that was taken in when doing a roll. These values are entered in the columns named “1st Adj Credit,” “2nd Adj Credit,” etc.

One current limitation in the trading engine is that each ticker symbol is considered a position. So there is no way to keep track of multiple positions separately, under QQQ or SPY for example. It is all lumped together.

Once you have a position in your Open Positions tab, it will only get moved to the Closed Positions tab when you subsequently import a Tastyworks csv file that was exported after you have closed all options for that ticker. The program sees that you no longer have anything open for that underlying and assumes the position is closed.

Other than keeping track of the total credit received and calculating the total profit or loss of the position, the trading engine is also designed to run a process regularly that will send alerts when certain criteria in the position are met. These alerts are usually received via email. An advanced feature is also capable of displaying certain values on an Apple Watch.

In order to enable these advanced features, it is ideal to setup real time quotes using the TD Ameritrade API. In order to do this, you will need to go to developer.tdameritrade.com and create a developer account. Once this is done, you can take the Client ID you created and set it in the Engine Config tab as the ” TDAmeritradeAPIClientId.” This TD Ameritrade API will also need to be enabled for the Trade Finder tab to work.

Since the Tastyworks CSV import looks for a file within your Google Drive, a helpful process is to setup a synced Google Drive folder on your computer so that you can easily save an export from Tastyworks to that location and it will automatically sync to Google. Again, keep in mind that these columns MUST be visible in your Tastyworks portfolio list before exporting the csv:
Quantity, Cost, / Delta, Theta, NetLiq, Call/Put, Strike Price, DTE.

I will continue to update this page as I have time. Happy trading!

How To Get A Copy of the Fire By Arthur Trading Engine Google Sheet

I have been getting a huge flood of messages asking for help on getting setup with the Fire By Arthur Trading engine code. I’m afraid I just don’t have time to help everyone, so I’ve created a public read only copy of engine within a Google Sheet. Here is how to get it . . . .

First, you need to use this link to get to the public copy: https://docs.google.com/spreadsheets/d/1qNVtxkgz-SCIMnzHHA-1SVxl2F_Kx63oAJTiTksQwzQ/edit?usp=sharing

One inside the read-only Google Sheet, go to the File menu and select “Make a copy”

Now you can browse to your newly made copy in your Google Drive. Open this file.

If you do not see a “Fire By Arthur Trading Engine” menu item appear within this file, you will want to go to Tools | Script Editor and within that script, select the “onOpen” function and click the run button.

Now, in the spreadsheet, you can select the “Fire By Arthur Trading Engine” menu item and click “Run.”

You will be prompted to allow this script to have permission to access files in your Google account, etc.

Also note, in order to run this engine, you will NEED to have a Tastyworks csv file export of your portfolio somewhere on your Google drive. By default, the file must be named p.csv (you can change this on the “Engine Config” tab in the Google Sheet). Your Tastyworks portfolio view MUST include these columns before you do the export in the Tastyworks platform:
Quantity, Cost, / Delta, Theta, NetLiq, Call/Put, Strike Price, DTE.

Finally, if you want the engine to get quotes from the TD Ameritrade API, you will need to sign up for a developer account at developer.tdameritrade.com and get an API key, which is then configured on the Engine Config tab (after setting QuoteAPIFrequency to 1).

If you have questions, please post them at the bottom of this page. I must apologize, I have very limited time to help with this, but I’ll do what I can.

Happy trading,

J. Arthur Squiers

Why I never look at charts when I trade

I will admit, I have an advantage.

When I sell strangles with my plan, I don’t have to look at stock charts; I depend entirely on the probabilities suggested by the option prices. I also sell cash secured puts in my IRA. . . . and even there, I never look at charts.

In fact, I’ve found through experience that my portfolio performs measurably better the less I look at charts. How can this be? Well, if my strategy depends on probabilities and numbers, trying to add chart reading into the equation starts throwing the probabilities off. If I trade based on the belief that I “know something,” or see something in the chart, what I lose is my consistency.

And I’ve seen it happen with countless other traders as well. They want to trade the probabilities, but they can’t stop chasing the charts and end up chasing their tail.

Granted, it took many years to break my chart habit. For the longest time, I’d still open up a 3 month or 1 month chart and try to make an “assumption.” But eventually, I noticed that I no longer even bother to look at them. I realized all I need is the option chain and IV rank—looking back, that is when everything started running like clockwork.

I make all of my trade decisions based on this

That’s when my trading became a business—a repeatable process of execution based on a few simple numbers.

Of course, sometimes it’s hard to trust the probabilities the option greeks give you. Some might say that simply selling options doesn’t tilt the odds in one’s favor enough—that implied volatility overstatement isn’t enough of an edge. That may be true. Which is why a trading plan must have specific guidelines on trade defense, as well as exit strategies that take profits early and cut off trades that have become stinkers poised to cause more trouble than they are worth. Everything and anything possible should be done to tilt the odds even further in your favor. Why do it any other way?

At the same time, I’m not trying to put down the technical analysts. Every trader has to find their own way. I have found mine.

Good luck to all traders, and be careful out there.