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
** MEGA THREAD ON Cryptocurrencies/Blockchain**

I wanted to know the best resources to learn about cryptocurrencies and blockchain for someone with zero knowledge. I asked Twitter, and Twitter answered.

This thread is a compilation of the best resources I was recommended. 👇👇

Let's start with ** BOOKS **

The first thing you should do before you pick up any book:

Learn about Bitcoin & Ethereum by reading the respective whitepapers.

- [Bitcoin white paper](https://t.co/cErOaFn6QL) by Satoshi Nakamoto

- [Ethereum White paper] (
https://t.co/0g5kYCGJGq) by Vitalik Buterin

Even if you are not tech savvy, you can get a good grasp about how blockchain functions from these papers.

1) *The Basics of Bitcoins and Blockchains: An Introduction to Cryptocurrencies and the Technology that Powers Them* by Antony Lewis

This book covers topics such as the history of Bitcoin, the Bitcoin blockchain, and Bitcoin buying, selling, and mining.

It also answers how payments are made and how transactions are kept secure.

Other cryptocurrencies and cryptocurrency pricing are examined, answering how one puts a value on cryptocurrencies and digital tokens.

You May Also Like

Trump is gonna let the Mueller investigation end all on it's own. It's obvious. All the hysteria of the past 2 weeks about his supposed impending firing of Mueller was a distraction. He was never going to fire Mueller and he's not going to


Mueller's officially end his investigation all on his own and he's gonna say he found no evidence of Trump campaign/Russian collusion during the 2016 election.

Democrats & DNC Media are going to LITERALLY have nothing coherent to say in response to that.

Mueller's team was 100% partisan.

That's why it's brilliant. NOBODY will be able to claim this team of partisan Democrats didn't go the EXTRA 20 MILES looking for ANY evidence they could find of Trump campaign/Russian collusion during the 2016 election

They looked high.

They looked low.

They looked underneath every rock, behind every tree, into every bush.

And they found...NOTHING.

Those saying Mueller will file obstruction charges against Trump: laughable.

What documents did Trump tell the Mueller team it couldn't have? What witnesses were withheld and never interviewed?

THERE WEREN'T ANY.

Mueller got full 100% cooperation as the record will show.