1/ In this thread, I'll cover the things you do regularly during trading in terms of **execution** and how to approach execution from the perspective of automation.

#TradingAutomation
2/ You may think execution is easy.

But that is only because you are attuned to it and you don't pay mindful attention to the sheer number of actions and decisions you take throughout the trading day, in terms of execution.

The following are some of the actions you do.
3/ Once your strategy says you've to put on a position

- you pick the relevant scrip to put on a trade
- you decide the required qty/lot size to trade
- based on the signal, it has to be a buy or sell order
- based on the strategy, it has to be a market or limit order.
4/ You also decide on

- whether you should attach a stop loss to the order
- whether you should attach a target to the order
- whether the order has to be intraday/MIS or overnight/NRML.
5/ While attaching the stop loss to the actual order, you have to decide

- if the stop loss is going to be fixed or trailing
- if the stop loss is going to be executed as a market order or a limit order
- if it is a fixed stop loss, is it price based or % based?
6/ If you use a trailing stop loss

- do you trail based on price?
- do you trail based on %?
- do you trail based on some condition? (1h low/high, trail on every 5m close, etc.)
- do you trail based on some indicator? (ATR, Moving Average, etc.)
7/ If you have to set a target for exit,

- is it price based / percentage based / "R" based / any other condition?
- is it dynamic and moving (split exit at 1R, 2R, 3R, etc.)
- is it based on any indicator?
8/ Essentially, when the SL order executes,

- you need to check whether a target order is open, and close it.
- you need to check if the SL order actually got executed in full or only partially

Same applies for target order too (close the SL order if not automatically closed).
9/ Then there are things like basket orders, where you create a basket and issue orders at the same time.

Here you have to check each order and whether each order got executed correctly, under multiple conditions.
10/ Once positions are open and neither SL nor target get executed, you need to check the status near EOD after 3.15, and decide on whether

- you want to convert the order to an overnight position
- you want to close the position
11/ These are some of the things you do in terms of execution.

While the above list may not be the exhaustive list of actions, it's a good list to start with in terms of thinking about what all actions you do regularly in execution.
12/ Now we come to the **ISSUES** part of the execution. While the list may not be exhaustive, we have all faced it at some point or the other.

First category of issues we face is related to connectivity.

This could be connectivity issues

- at broker's end
- at exchange end
13/ If you're using a data vendor, it could also be connection issues at the data vendor's end.

Essentially due to these connection issues you may face a host of errors/problems that interrupt/prevent an on-point execution.
14/ Very first problem is something we are all familiar with: while trying to login for placing orders, you're not able to login.

Usually it's because of broker facing higher than normal load. It could be due to other reasons as well. When you can't login, you can't execute.
15/ So you're logged in. Now you're trying to order, but your order is not getting accepted.

This issue is also quite prevalent.

If your strategy depends on timely execution, this could lead to a lot of slippage and even losses.
16/ You have successfully placed the order. The order got accepted.

But the order didn't get executed immediately.

It stays in pending for a while (could be 30s-1m) and then executes.

This is also something we have seen with few many brokers.
17/ Your account is fine.

All the segments are activated.

Your market data is working fine too.

You have enough margin to execute the order you have created.

But your broker rejects your order.

This happened to me on Zerodha.

Broker side technical glitch.
18/ Say your strategy requires for closing price (specific timeframe bar close) to be above or below a certain price for executing the order, or for executing stop loss.

If there are any connection/data issues, essentially you won't execute due to not seeing the required data.
19/ For instance, if 5m close has to be above 29550 for you to go long BNF and the 12:20 to 12:25 bar's last few ticks reach that high and actually closes around 29560.

But, the data connection wasn't right and the ticks didn't come through in your system, you'd not execute.
If the very next bar is a breakout bar and price goes to 29700, there's a huge upswing, you have essentially missed the boat.

You'll essentially enter on close of next bar above 29700, at a slippage of 150+ points.
20/ Even if broker side has no issues, we can't guarantee that the exchange won't have issues.

There were few many days when data from exchange got interrupted, when exchange wasn't accepting orders - entry or exit, when exchange was rejecting fno orders.
21/ You enter an order and successfully manage to place the order. The order executes too. Now you're in the trade.

You get logged out. You aren't able to login.

Sometimes, near market closing.

You should close your position, but you aren't able to.
22/ Broker's own datastream is not building candles properly.

So you see the prices wrongly and place an order that shouldn't have gotten placed or vice versa.

Or your already placed order misses executing the stop loss or target orders because of this.

EOD you're at loss.
23/ Sometimes, price runs through your stop, and your stop order is not executed.

Happened to me in march crash with a stop loss.

I was long on open, market went circuit break down in a flash. That particular candle was fast, price went through SL, SL didn't execute.
24/ Your order needs to be closed intraday.

You try to close your order by 3.15-3.25pm.

Only that, your broker's system is not allowing your exit.

Your exit orders are getting rejected, and aren't going through.
25/ You entered an extra zero or some extra number in quantity.

The order got executed with higher than intended quantity.

Potential for losses is very high in this scenario.

Happens due to fat fingers, esp in option buying, cash buying.

In code, this is due to logic bugs.
26/ Each and every action written down in the list above that we perform regularly has associated issues.

These issues aren't rare events. We have seen these happen with Zerodha (and sometimes with other brokers too) time and time again.
27/ When automating our execution, it's not a simple buy and sell or a simple short and cover.

Behind the scenes, for your automation system to be robust enough, all these corner/edge cases need to be covered and handled properly.
28/ Each issue is very much a regular event in terms of possibility.

Each execution step has potential issues associated with it.

While automating, we should put much more thought into different aspects of the execution of orders.
29/ Timing matters. If orders aren't executed in a timely manner, you could literally blow up your entire capital away.

Especially if you are careless, and you automate and think your system will do everything, you'll be surprised.

You should always monitor and keep tabs.
30/ Think about these steps we regularly make for trade execution.

For each of the actions mentioned, you'll write a function/module.

For each of the issues, you'll have to handle exceptions, edge cases, and put in place contingency measures that will prevent losses.
31/ Before you think these things through, do not venture into full automation.

It's important you think in pseudocode first.

Understand your broker's API docs.

Understand the API's limitations.

Also understand no matter how much you try, you'll face issues.
32/ Some brokers do not offer paper/test trading platform (unlike IBKR which offers a full featured demo receiving 15m delayed data, even for API testing).

With such broker APIs, you have to test in live trading only. So, it's best to check everything with lowest size possible.

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Shravan Venkataraman 🔥🚀💰

Shravan Venkataraman 🔥🚀💰 Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @theBuoyantMan

1 Dec
**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. Trading automation - rough sketch out of list of functions w
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.
Read 21 tweets
1 Dec
This is a raw output of the one lot backtest I did on one of the strategies I trade currently.

Essentially after all the optimisation and out of sample testing I want to look at the performance of the system holistically for the last 10 years.

This starts with a one lot test.
After that, I test for scenario where I'd use the equivalent of maxDD amount to compound each lot and scale the system.

If I test that, the risk of ruin is higher (as at some point you get wiped out having only max DD amount per lot, and facing the same maxDD)
These tests are very optimistic in it that they assume FILLS at the exact price point (which may not be possible). So, there are calculations to be made after this step.

That said, you see 2017? That's when our account got wiped out in this manner of scaling 1 lot per maxDD amt.
Read 5 tweets
24 Nov
Here's how writing can be leveraged to build an audience online:

1) Write a long form essay, publish it in your blog.
2) Convert that to a Youtube video series, as a talking head video or an illustrated presentation
3) Convert all the filmed videos to audio, publish as podcast.
4) Get the highlights from the essay, publish as tweets.
5) Create quotes in the form of illustrations/images, publish on Instagram and Facebook.
6) Extract highlights of the video series, publish on TikTok.
7) Extract those highlights as audio, and publish as byte-sized podcast.
8) Publish the long-form essay as downloadable PDF/ePub in exchange for people's email. Build your email List.
9) Publish independent sections of the essay as tweetstorms/threads.
10) Publish these threads as short essays on medium and other distribution platforms.
Read 6 tweets
23 Nov
Thank you, for all the wonderful people who took time to register your interest and comment on the form.

So, here's what I have thought about so far, with respect to the course.

1. 80% practical coding practice, with clear outcomes, assignments, and small projects, every week.
2. Working with financial and time-series data in some form from the very first day's assignment itself.

3. Developing algorithmic thinking from the standpoint of being able to write logic in English and then code.

4. Developing a mindset for backtesting and ideation approach.
5. A compound assignment like a mini-project every week. A compound project every 4 weeks, and one big project for the course completion.

6. Daily coding practice being built into the way the course will be structured - for you to build the habit of reading & writing code.
Read 9 tweets
23 Nov
Option selling is a game for larger players (probably those with at least 1-2cr in capital).

As a bare minimum, I suggest at least 50L in capital before you start thinking about option selling as a strategy to make money.
Intraday option selling and swing - both have their drawbacks, and both have potential to wipe you out.

Intraday - violent swings can move through your SL without executing.

Swing trades - gap up/down opens against you could lead to margin call.
While I'm oversimplifying the cases, it's very important to know where the landmines are so that you can avoid them.

If you don't even know where the landmines are and you're walking a field full of them, even if you're lucky 10 times, the 11th time you step on one, you die.
Read 6 tweets
22 Nov
If you're under 25 years of age,

and you have just begun trading in the financial markets

1) Don't take money to trade from your parents or family members.
2) Don't even think about option selling if your capital is less than 50L.
3) Trade only your money (not even friends')
4) Trade only the portion of your money that, if you got wiped out, wouldn't faze you. This means, don't use all the money you got as capital.
5) Don't start with intraday. Don't even start with trading. Start with sim/demo (ex: IBKR)
6) Don't confuse favorable markets (since 2017-18) for your own genius or having "figured it out".
7) Don't over leverage. If you can't generate decent returns un levered, your strategies are shit anyway.
8) Don't look at derivatives unless you have traded cash stocks.
Read 4 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!