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

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

1/18 After 3 months, @saffronfinance_ is no longer new on the scene. Now that the kid has climbed the ranks, it's time to see if he can hang with the big boys.

Below are some updated thoughts on potential integrations, improvements, and innovations for Saffron moving forward. ⬇️

2/18 First, if you haven't seen @Privatechad_'s alpha-leaking introductory thread, you should check it out.

I agree that @AlphaFinanceLab and @CreamdotFinance, specifically the Iron Bank, would be ideal targets for SFI risk tranches.

3/18 Speaking more broadly, Saffron is primarily integrated with @compoundfinance, which has served as a MVP of sorts.

The thing is, Compound is one of the safest (but also lowest yield) protocols in DeFi, so it's not surprising that there isn't much demand for the sen. tranche.

4/18 Expanding beyond Compound to higher-risk/higher-return protocols has always been key.

These protocols are the bread-and-butter target market for Saffron, and I would expect to see a surge in demand for senior tranche staking in these

5/18 Additionally, @DeFiGod1 convinced me that Senior Tranche pools would be more appealing if they offered fixed yield.

Essentially, Saffron would augment the product offerings of @Barn_Bridge by also offering senior stakers insurance in the form of junior tranche collateral.
Last week Hizbollah's finance institution Al Qard el Hasan was hacked by Spiderz. A group of people took that Data and tried to make sense out of it. Below are the findings

Loans are provided to borrowers for gold deposits or other guarantees, to the association's members and to unsecured applicants.

AQAH had a carried forward loan balance of $450 million as of December 31, 2019. This balance has been increasing at a yearly rate of 13.4%.

AQAH laundered around $475 million in 2019 in the form of disbursed loans paid to more than 20,000 borrower accounts; mostly to borrowers with gold deposits.

Deposits accounts have been offered to 307,000 members of the association, 83,000 contributors as well as to 600 companies. AQAH closed 2019 with an overall depositors accounts balance of around $500 million.

You May Also Like

“We don’t negotiate salaries” is a negotiation tactic.

Always. No, your company is not an exception.

A tactic I don’t appreciate at all because of how unfairly it penalizes low-leverage, junior employees, and those loyal enough not to question it, but that’s negotiation for you after all. Weaponized information asymmetry.

Listen to Aditya

And by the way, you should never be worried that an offer would be withdrawn if you politely negotiate.

I have seen this happen *extremely* rarely, mostly to women, and anyway is a giant red flag. It suggests you probably didn’t want to work there.

You wish there was no negotiating so it would all be more fair? I feel you, but it’s not happening.

Instead, negotiate hard, use your privilege, and then go and share numbers with your underrepresented and underpaid colleagues. […]
MDZS is laden with buddhist references. As a South Asian person, and history buff, it is so interesting to see how Buddhism, which originated from India, migrated, flourished & changed in the context of China. Here's some research (🙏🏼 @starkjeon for CN insight + citations)

1. LWJ’s sword Bichen ‘is likely an abbreviation for the term 躲避红尘 (duǒ bì hóng chén), which can be translated as such: 躲避: shunning or hiding away from 红尘 (worldly affairs; which is a buddhist teaching.) ( (abbrev. TWX)

2. Sandu (三 毒), Jiang Cheng’s sword, refers to the three poisons (triviṣa) in Buddhism; desire (kāma-taṇhā), delusion (bhava-taṇhā) and hatred (vibhava-taṇhā).

These 3 poisons represent the roots of craving (tanha) and are the cause of Dukkha (suffering, pain) and thus result in rebirth.

Interesting that MXTX used this name for one of the characters who suffers, arguably, the worst of these three emotions.

3. The Qian kun purse “乾坤袋 (qián kūn dài) – can be called “Heaven and Earth” Pouch. In Buddhism, Maitreya (मैत्रेय) owns this to store items. It was believed that there was a mythical space inside the bag that could absorb the world.” (TWX)

It was Ved Vyas who edited the eighteen thousand shlokas of Bhagwat. This book destroys all your sins. It has twelve parts which are like kalpvraksh.

In the first skandh, the importance of Vedvyas

and characters of Pandavas are described by the dialogues between Suutji and Shaunakji. Then there is the story of Parikshit.
Next there is a Brahm Narad dialogue describing the avtaar of Bhagwan. Then the characteristics of Puraan are mentioned.

It also discusses the evolution of universe.( )

Next is the portrayal of Vidur and his dialogue with Maitreyji. Then there is a mention of Creation of universe by Brahma and the preachings of Sankhya by Kapil Muni.

In the next section we find the portrayal of Sati, Dhruv, Pruthu, and the story of ancient King, Bahirshi.
In the next section we find the character of King Priyavrat and his sons, different types of loks in this universe, and description of Narak. ( )

In the sixth part we find the portrayal of Ajaamil ( ), Daksh and the birth of Marudgans( )

In the seventh section we find the story of Prahlad and the description of Varnashram dharma. This section is based on karma vaasna.