---
title: "Discussion on \"Generating Buy and Sell Signals for SMA, MACD, and Bollinger-Bands with Python\" | Hashnode"
description: "Discussion on \"Generating Buy and Sell Signals for SMA, MACD, and Bollinger-Bands with Python\". If you've noticed that there are two major schools of thought with which you can decide upon When to Buy and When to Sell a Stock, one is Technical Analysis📈 the other is Fundamental Analysis.\nTechnical Analysis looks upon the price action of the un..."
url: "https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Generating Buy and Sell Signals for SMA, MACD, and Bollinger-Bands with Python](https://tradewithpython.hashnode.dev/generating-buy-sell-signals-using-python?utm_source=hashnode&utm_medium=feed)

If you've noticed that there are two major schools of thought with which you can decide upon When to Buy and When to Sell a Stock, one is Technical Analysis📈 the other is Fundamental Analysis. Technical Analysis looks upon the price action of the un...

Aug 23, 2021 · 10 min read · tradewithpython.hashnode.dev  
Updated Sep 2, 2023  
Read the article

-   [#python](https://hashnode.com/tag/python)
-   [#python-projects](https://hashnode.com/tag/python-projects)
-   [#algorithms](https://hashnode.com/tag/algorithms)
-   [#beginners-learningtocode-100daysofcode](https://hashnode.com/tag/beginners-learningtocode-100daysofcode)
-   [#algorithm](https://hashnode.com/tag/algorithm)

## Written by

[Utkarsh singhal](https://hashnode.com/@utkarsh060)

@utkarsh060 · Delhi, India

  
[View profile](https://hashnode.com/@utkarsh060)

Disseminating whatever little knowledge I have :)

Hi! I am Utkarsh, and I am currently working as a Quantitative Analyst. I have done my Bachelor's in Management Studies (BMS) from the University of Delhi. I am a 20-year-old with the curiosity to learn new tools and explore new technologies. I have a strong inclination towards finance, technology (FinTech) and analytics. I love to tell stories with data but what fascinates me the most is how the next big thing is going to change the world.

## Responses 9

Markdown supported · ⌘↵ to post

[Rajendra Damor](https://hashnode.com/@rajdamor)

[Jan 7, 2024](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/659a5d415a246ab4fe8f4ea3)

GOOD

[Riddhiman Bandyopadhyay](https://hashnode.com/@riddhiman9gentle)

[Jul 15, 2023](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/64b30c470470cd817f0df2dc)

Excellent Article guiding me learn things as newbie.... Thnx a Billion

[Anand Pavan Mandala](https://hashnode.com/@PavOne)

[Mar 4, 2023](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/64038eaaa50f11a2517c230a)

Very Nicely done. Thanks for sharing it. Truly appreciated.

[Vimal Modi](https://hashnode.com/@Vimalmodi)

[Nov 20, 2022](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/6379c27eb1e7ce95894549fa)

Solved the error this way....Correct way?

def MACD\_color(data): MACD\_color = \[\]

```
#for i in range(0, len(data)):
for i in range(0, len(data)):
    if i==0:
            MACD_color.append(False)
    if i>0:
        if data['MACDh_12_26_9'][i] > data['MACDh_12_26_9'][i - 1]:
            MACD_color.append(True)
        else:
            MACD_color.append(False)
return MACD_color
```

[Vimal Modi](https://hashnode.com/@Vimalmodi)

[Nov 20, 2022](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/6379bc2d8864d49c7d40cf9a)

Got same error as Jing Li

[Utkarsh singhal](https://hashnode.com/@utkarsh060)

Same error as above

Platform is not allowing me to share screenshot

[Vimal Modi](https://hashnode.com/@Vimalmodi)

[Nov 20, 2022](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/6379b29eb1e7ce958945481a)

very well written. cover all basic ideas. Can you plz share your other blogs which can help me to form multi time frame data from ticks? Thank you so much.

I am an elderly. You may plz also guide me to Buy you a cofee.

[Jing Li](https://hashnode.com/@JingL)

[Mar 31, 2022](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/6245d2cad1ff58fbe6947f52)

Hello Thank you! It is well written! I want a bit more information on the two points below:

1.  When I run the code to To visualize the MACD histogram we create a simple function to insert a boolean column. It showed me -1 is not in range. I don't know how to fix it.
2.  Is it possible to set your own short-term and long-term range, for example, 3 days and 7 days? I want to use it for my research project. Would be interesting to check how it works.

Thank you! Jing L

[Utkarsh singhal](https://hashnode.com/@utkarsh060)

[Apr 2, 2022](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/6245d2cad1ff58fbe6947f52#reply-6248211f4b4dde0dc0be6811)

Hi Jing,

1.  It would be great if you could give a more elaborate description of the error you're facing with a screenshot.
2.  Yes it's possible, you can configure the time period while generating the MACD using ta,

Here: ta.macd(data\['Close'\], \*\*)

Thanks

[Tom Stuart](https://hashnode.com/@tomsdev)

[Mar 8, 2022](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/622740808547ea809709df7e)

Hi, I'd like to get in touch with the author about a potential job opportunity. How's best to get in touch?

[Yash Roongta](https://hashnode.com/@yash12392)

[Mar 8, 2022](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/622740808547ea809709df7e#reply-6227413d8547ea809709dfa2)

Hi @tomsdev there are multiple authors for tradewithpython. For the author of this specific blog you can reach out to Utkarsh on utkarshsinghal06@gmail.com

[Rahul Raut](https://hashnode.com/@rahoolm)

[Aug 24, 2021](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/61255180663d427e19ffb0e8)

Please show some live trading example. These kind of articles are available freely everywhere on github. It will be interesting to know how you do the same things in live market with each new candle coming. Do you run the loop every 5 minutes and how you do it? Do you use python modules like `schedule` or using sleep? How do you avoid API rate Limits?

[Yash Roongta](https://hashnode.com/@yash12392)

[Aug 24, 2021](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/61255180663d427e19ffb0e8#reply-612555de663d427e19ffb181)

Hi [Rahul Raut](https://hashnode.com/@rahoolm) you are free to look at other free resources on Github if that suits your need. We are building a base with entry-level content for our community. Appreciate your patience till we move onto more advanced levels. There are many other Youtube videos available if you would like immediate answers to your questions. We have covered rate-limiting in one of our blogs here.

[tradewithpython.com/concurrency-in-python-using-s…](https://tradewithpython.com/concurrency-in-python-using-smartapi)
