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

If you want to become financially independent and don't know where to start, here is a thread that will help you get started

/THREAD/

1. Review your expenses and make a budget

It will help you see where you overspend, make a plan to save, pay down debt and start


2. Set your investing and retirement goals

How much do you need to support yourself in retirement and when do you want to


3. The earlier you start investing, the better.

Here's why and how time and compounding can become your


4. Invest in an index fund

It's easy, safe, cheap, and the best choice for a beginner in investing, with not much time for

You May Also Like

ARE WE FAMILIAR WITH THE MEANING & POWER OF MANTRAS WE CHANT?

Whenever we chant a Mantra in Sanskrit, it starts with 'Om' and mostly ends with 'Swaha' or 'Namaha'. This specific alignment of words has a specific meaning to it which is explained in Dharma Shastra.


Mantra is a Sanskrit word meaning sacred syllable or sacred word. But Mantras r not just words put together,they r also vibrations.The whole Universe is a cosmic energy in different states of vibration &this energy in different states of vibration forms the objects of Universe.

According to Scriptures,Om is considered to be ekaakshar Brahman,which means Om is the ruler of 3 properties of creator,preserver&destroyer which make the
https://t.co/lyhkWeCdtv is also seen as a symbol of Lord Ganesha, as when starting the prayer,it's him who is worshipped 1st.


'Om' is the sound of the Universe. It's the first original vibration of the nothingness through which manifested the whole Cosmos. It represents the birth, death and rebirth process. Chanting 'Om' brings us into harmonic resonance with the Universe. It is a scientific fact.

Therefore, Mantras are described as vibrational words that are recited, spoken or sung and are invoked towards attaining some very specific results. They make very specific sounds at a frequency that conveys a directive into our subconcious.
These 10 threads will teach you more than reading 100 books

Five billionaires share their top lessons on startups, life and entrepreneurship (1/10)


10 competitive advantages that will trump talent (2/10)


Some harsh truths you probably don’t want to hear (3/10)


10 significant lies you’re told about the world (4/10)
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