**Automate your trading**

1/ The first step in automating your trading is defining whatever steps you're doing manually.

I just roughly sketched out some of the actions I do on a regular basis manually.
2/ When designing an automated trading system, it helps to write out the list of things you do during the trading hours, and design a scalable, reusable system accordingly.

This calls for functional or object-oriented programming to be put into use.
3/ Before you design the system, you write everything down in simple English language.

This helps clarify what all minutiae are involved.

A step you consider very small and intuitive, takes a lot of effort in reality to think in code.
4/ For ex: You may "just" be looking at option chain and deciding which strike to buy if your strike decision is based on OI and Volatility.

But in background, you have to pull the data of all strikes, their respective option type, get the relevant details one after another.
5/ Strike calculation to decide which strike to trade is also mathematical. You have to create a formula for doing that and code it up.

Like this, simple things take nuanced thought when it comes to automation.
6/ The first action we do is LOGIN.

We enter username, password.
We enter OTP or 2fa PIN.
We login.

This may not be as straight forward with API, but quite similar.

But before logging in, we check for connection to broker.

If not, we keep trying until we're able to connect.
7/ Once we login, we check if we can see the historical data and charts.

We check if previous day's data has been updated.

We check our margin, cash position in the account.

We check if the data connectivity is working fine.

Once it's 9:15, we check if the data is streaming.
8/ We may create a watchlist with a specific list of stocks for the day, based on some conditions.

For ex: If you only trade gapping stocks on the pre-open, you look at the price at 9:08, and create a watchlist.

You search for each individual stock and add it to watchlist.
9/ If you trade FNO, you will then search for relevant options and futures.

Then, you decide the strike price, the expiry date, etc., and get those into the watchlist.

You may even have to decide strike price on the go.
10/ If you have screeners, those screeners require historical data to screen for conditions that you need fulfilled.

It could be yesterday's intraday data.

It could be last week, month's data.

The screeners use such historical data to decide which ones to shortlist.
11/ You might also want to check until what point the historical data is available.

On charts, it says "data not available beyond this point".

At that point, you readjust your lookback period.

You'd want to adjust the historical data for different timeframes and check data.
12/ If you have any positions, you'll want to check the current status of positions in real time.

You'll need to receive streaming data to be updated about each item on your watchlist, tick by tick.

If you take your decisions based on a specific timeframe bar, you need that.
13/ Maybe you don't believe in zerodha's data being correct.

What do I do if the opening range data is wrong? I check with Google data and verify.

Otherwise, I check with Fyers.

So, data redundancy/accuracy is important.
14/ Then, once you're ready to trade, you choose the specific watchlist item to trade.

Say you want to trade 100 lots of Nifty Futures. That's your contract. You get the data about Nifty Futures, and create contract with 100 lot quantity to buy/sell.
15/ These are some of the things we do before placing orders.

This was just a rough sketch. But each of these actions require a piece of code to work as a holistic system.

And each mentioned action will have like few steps (some would have many steps) programmatically.
16/ It's then important to understand that these are all unique and different pieces of one system.

All of these pieces/actions have to work smoothly, independently, and work together when they need to.

Modularity, reusability, etc., are all important when you build a system.
17/ I'll cover ordering, order monitoring, different order types, etc., in a separate post.

Essentially, what I want to convey is, the actions that we do manually and think as simple, have nuances happening in the background while coding.
18/ This is why it's important to have a testbed where you can test everything, even the live trading, before you actually push the system live to automate.

Without testing, going live is a recipe for disaster.

And, without meticulous planning, testing is futile.
19/ So, to think about automation, first start listing down EVERYTHING you do manually, in simple steps.

This is your algorithm.

Now, you need a programming language (that broker supports) and an API (that the broker offers) to automate.
20/ Your duty is to soak up all the information about the broker API from their documentation, test everything locally, and then proceed with further development.

And, always be cautious at every step of the way if you're using a live trading account.
21/ As I build my own automation system, I'll cover each of these modules in detail in the coming days.

That said, do give it a thought, and see what all you can automate (from hourly scans to live scans updated every second for breakouts, you can automate scanning process too)
You can follow @theBuoyantMan.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled:

By continuing to use the site, you are consenting to the use of cookies as explained in our Cookie Policy to improve your experience.