Nano Course On Python For Trading
==========================
Module 3

In this post, I will attempt to teach you how to write an algorithm in python to automatically find support and resistance. We shall use the data we downloaded in module 2.

+

To visualize price action, I have used the daily candlestick chart. To quantify the meaning of support and resistance, I have taken below definitions:
In a series of 5 continuous candles, if the first three candles make increasing high and then 2 decreasing highs, then the

+
high of the third candle is considered resistance. Similarly, if the first 3 candles make lower lows and the next 2 make high lows then the low of the third candle is support.

+
The above explanation is for the sake of quantifying support and resistance at a very basic level. These are called fractals. Now let's get started with the code.

mpl_finance is the new module here. We will use its candlestick_ohlc function.

+
Now, if you remember, you downloaded data for nifty 50 stocks in module 2. We shall use that data. Let's work on ITC data this time.
We will use data from 1 Jan 2021 to 30 June 2021.

+
Let's plot the candlestick chart for this data frame. We are going to use the candlestick_ohlc function from the mpl_finance module. I have defined a function plot_chart() which you can see in the google colab link in the last thread

+
We will iterate over this dataframe and see if the low of the current candle is a support or high is a resistance. For that, we have created an array named levels.

Again remember the definition of fractals, we shall leave the first two candles and the last 2 candles as we

+
need two candles to the right of a candle in order to consider it a fractal. Similarly, we will leave the last two candles. We will iterate over the data frame from index 2 till it is 2 less than its size. We also need to define two functions "isSupport" and "isResistance"
+
determines and returns true/false if a candle low is a support or its high is resistance. In this image below 1-2-3-4-5 is a fractal as explained above, low of the candle on 10 Jan is support and high on 20 Jan is resistance. Repeating this process for the entire data frame.

+
To plot the levels we add it in our plot function (named it plot_all() ) and execute it.

+
But, alas it looks so ugly currently, I don't wanna look at it. There is a way that we can reduce the number of levels marked. What we will do that will first find the average length of a candle and reject all other price levels which are closed then twice this average

+
let's find the average length of a candle i.e. average of high - low

s = 2 * np.mean(df['High'] - df['Low'])

Using this number, we will reject the current price level if there is already another price level within the range +- s. For this, we defined a function isFarFromLevel
Finally, we have reduced the number of price levels and the chart looks like below:

+
If you want to work on the code and tinker with the code, go to Google Colab https://t.co/G8DuZvWO0g

I have shared the entire code on colab and added references for you to look into.

D: these won't help you become profitable but this will teach you how quant traders think &

+
automate their day-to-day tasks and quantify certain ideas. If you have any doubt reach out to me in DM.

+
In Module 4, we will learn about cloud computing and the use of cloud in trading. Until then, happy learning.

More from Finance

I'm lucky to attain financial freedom before 30.

I credit Fintwit for my learnings.

Here's 10 key concepts every investor must know:

1. $$ needed to retire
2. Researching a business
3. Reading annual reports
4. Reading earnings calls
5. Criteria of a multi bagger

(Read on...)

6. Holding a multi bagger
7. Economic moats
8. When to buy a stock
9. Earnings vs cashflow
10. Traits of quality companies

Here's my 10 favourite threads on these concepts:

1. How much $$ do you need to retire

Before you start, you must know the end game.

To meet your retirement goals...

How much $$ do you need in your portfolio?

10-K Diver does a good job explaining what's a safe withdrawl rate.

Hint: It's NOT


2. Research a business

Your investment returns are a lagging indicator.

Instead, your research skills are the leading predictor of your results.

Conclusion?

To be a good investor, you must be a great business researcher.

Start with


3. Reading annual reports

This is the bread and butter of a good business analyst.

You cannot just listen to opinions from others.

You must learn to deep dive a business and make your own judgments.

Start with the 10k.

Ming Zhao explains it
As the DeFi bull market continues, some brutally honest tips for new founders fundraising in crypto.

👇


1/ The discount you offer to strategic investors is both to account for the risk of an unlaunched product, but also as compensation for continued value add and support.

So make sure you know the investor will support you and not leave you on read once the docs are signed!

2/ Having someone on your cap table/ token allocation is as important as hiring.

You wouldn't hire someone just because they are influencers on Twitter- you do your reference checks and find evidence of value add from other companies the investor has invested in.

3/ Don't trust, verify.

Many investors will promise you the world when they're trying to get on your cap table.

Talk to founders they backed to see how much of it is bullshit. Ask them about how the investor was there for them during hard times.

4/ Don't just go for "name brand" funds because you want the brand.

Sure, it's great validation, but optimize for fit, not vanity.

However, I do think many well-known VCs are good actors, especially those with roots in successful trad VCs. They have a rep for a reason!

You May Also Like

I just finished Eric Adler's The Battle of the Classics, and wanted to say something about Joel Christiansen's review linked below. I am not sure what motivates the review (I speculate a bit below), but it gives a very misleading impression of the book. 1/x


The meat of the criticism is that the history Adler gives is insufficiently critical. Adler describes a few figures who had a great influence on how the modern US university was formed. It's certainly critical: it focuses on the social Darwinism of these figures. 2/x

Other insinuations and suggestions in the review seem wildly off the mark, distorted, or inappropriate-- for example, that the book is clickbaity (it is scholarly) or conservative (hardly) or connected to the events at the Capitol (give me a break). 3/x

The core question: in what sense is classics inherently racist? Classics is old. On Adler's account, it begins in ancient Rome and is revived in the Renaissance. Slavery (Christiansen's primary concern) is also very old. Let's say classics is an education for slaveowners. 4/x

It's worth remembering that literacy itself is elite throughout most of this history. Literacy is, then, also the education of slaveowners. We can honor oral and musical traditions without denying that literacy is, generally, good. 5/x