---
title: "Comment by Vimal Modi on \"Generating Buy and Sell Signals for SMA, MACD, and Bollinger-Bands with Python\" | Hashnode"
description: "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 :"
url: "https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26/comment/6379c27eb1e7ce95894549fa"
---

[Discussion](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26)

Comment [Generating Buy and Sell Signals for SMA, MACD, and Bollinger-Bands with Python](https://hashnode.com/posts/generating-buy-sell-signals-using-python/61241129663d427e19ff8e26)

[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
```
