# How to draw support and resistence lines with DataFrame in Python

As we’ve seen in a trend line explanation, recognizing a trend and rallying patterns in a band is vital for technical traders. Support and resistence lines play a key role to understand a band that is created by higher prices and lower prices. If we conform to the principles,When the price hits the ceiling or the floor in the channel, behaivors of the price follow either bouncing back away from the support or resistance level, or violating the price level and continue in its direction—until it hits the next support or resistance level if it confirms to the principle.

Here’s what we drew in the previous article a trend line for both higher data points and lower data points those work as resistence line and support line.

In this article, I’d like to draw a static barrier that is a single straight horizontal line in a chart that represent support and resistence lines in Python. This is not either ascending or descending line following a trend like I introduced in the previous writing. These support and resistence lines are more simplified ones and aren’t influenced by upward and downward trend but it’s useful yet to predict a probable range of prices in a certain period of time.

There might be some approaches to compute support and resistence points from DataFrame data, I’ve just found this code and the approach leveraged scipy.signal.savgol_filter method. This algorithm looks fine to me.

A Simple Python Function to Detect Support/Resistance Levels

I use this function and drew support and resistence lines from DataFrame data in the following section. Firstly, here’s my understanding how this code works about the computation.

1. Apply savgol_filter with a specific window, it computes smoothed data
2. A substraction of matrices computes delta of adjacent smoothed data
3. A loop detects both local maxima value and local minima value

Now we’ve got variables support and resistence that are Python lists of values.

We’re ready to draw a graph with DataFrame and returned support & resistence values in matplotlib. I wrapped these tasks in a function and it takes df which is given DataFrame in OHLCV format and lists of support and resistence values in float.

``supres_plot(df, support, resistence)``

This is the result of Apple, Inc stock data. This price data seems unfit a little for the given Apple, Inc stock prices. We can try different data set and different time intervals.

I published the previous article how to aggregate OHLCV data in different time interval.

This can be a reference if you want to modify the time interval of your OHLCV data, for example between daily, weekly, monthly, or for intra-day data.

Mastering DataFrame – how to aggregate OHLCV data in a different time period

Here’s the Jupyter notebook for all samples above for your reference.

How to draw support and resistence lines with DataFrame in Python

## 3 thoughts on “How to draw support and resistence lines with DataFrame in Python”

1. Cool website!

My name’s Eric, and I just found your site – techflare.blog – while surfing the net. You showed up at the top of the search results, so I checked you out. Looks like what you’re doing is pretty cool.

But if you don’t mind me asking – after someone like me stumbles across techflare.blog, what usually happens?

I’m guessing some, but I also bet you’d like more… studies show that 7 out 10 who land on a site wind up leaving without a trace.

Not good.

Here’s a thought – what if there was an easy way for every visitor to “raise their hand” to get a phone call from you INSTANTLY… the second they hit your site and said, “call me now.”

You can –

Talk With Web Visitor is a software widget that’s works on your site, ready to capture any visitor’s Name, Email address and Phone Number. It lets you know IMMEDIATELY – so that you can talk to that lead while they’re literally looking over your site.

CLICK HERE http://www.talkwithwebvisitors.com to try out a Live Demo with Talk With Web Visitor now to see exactly how it works.

Time is money when it comes to connecting with leads – the difference between contacting someone within 5 minutes versus 30 minutes later can be huge – like 100 times better!

That’s why we built out our new SMS Text With Lead feature… because once you’ve captured the visitor’s phone number, you can automatically start a text message (SMS) conversation.

Think about the possibilities – even if you don’t close a deal then and there, you can follow up with text messages for new offers, content links, even just “how you doing?” notes to build a relationship.

Wouldn’t that be cool?

You could be converting up to 100X more leads today!
Eric

PS: Talk With Web Visitor offers a FREE 14 days trial – and it even includes International Long Distance Calling.
You have customers waiting to talk with you right now… don’t keep them waiting.

2. Hello, my name’s Eric and I just ran across your website at techflare.blog…

I found it after a quick search, so your SEO’s working out…

Content looks pretty good…

One thing’s missing though…

A QUICK, EASY way to connect with you NOW.

Because studies show that a web lead like me will only hang out a few seconds – 7 out of 10 disappear almost instantly, Surf Surf Surf… then gone forever.

I have the solution:

Talk With Web Visitor is a software widget that’s works on your site, ready to capture any visitor’s Name, Email address and Phone Number. You’ll know immediately they’re interested and you can call them directly to TALK with them – literally while they’re still on the web looking at your site.

CLICK HERE http://www.talkwithcustomer.com to try out a Live Demo with Talk With Web Visitor now to see exactly how it works and even give it a try… it could be huge for your business.

Plus, now that you’ve got that phone number, with our new SMS Text With Lead feature, you can automatically start a text (SMS) conversation pronto… which is so powerful, because connecting with someone within the first 5 minutes is 100 times more effective than waiting 30 minutes or more later.

The new text messaging feature lets you follow up regularly with new offers, content links, even just follow up notes to build a relationship.

Everything I’ve just described is extremely simple to implement, cost-effective, and profitable.

Eric
PS: Talk With Web Visitor offers a FREE 14 days trial – and it even includes International Long Distance Calling.
You have customers waiting to talk with you right now… don’t keep them waiting.

3. Cool website!

My name’s Eric, and I just found your site – techflare.blog – while surfing the net. You showed up at the top of the search results, so I checked you out. Looks like what you’re doing is pretty cool.

But if you don’t mind me asking – after someone like me stumbles across techflare.blog, what usually happens?

I’m guessing some, but I also bet you’d like more… studies show that 7 out 10 who land on a site wind up leaving without a trace.

Not good.

Here’s a thought – what if there was an easy way for every visitor to “raise their hand” to get a phone call from you INSTANTLY… the second they hit your site and said, “call me now.”

You can –

Talk With Web Visitor is a software widget that’s works on your site, ready to capture any visitor’s Name, Email address and Phone Number. It lets you know IMMEDIATELY – so that you can talk to that lead while they’re literally looking over your site.

CLICK HERE http://www.talkwithwebvisitors.com to try out a Live Demo with Talk With Web Visitor now to see exactly how it works.

Time is money when it comes to connecting with leads – the difference between contacting someone within 5 minutes versus 30 minutes later can be huge – like 100 times better!

That’s why we built out our new SMS Text With Lead feature… because once you’ve captured the visitor’s phone number, you can automatically start a text message (SMS) conversation.

Think about the possibilities – even if you don’t close a deal then and there, you can follow up with text messages for new offers, content links, even just “how you doing?” notes to build a relationship.

Wouldn’t that be cool?