Python Forum
TypeError that i can't solve it
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TypeError that i can't solve it
#1
class MACD_Strategy:
    def __init__(self, stock_price, MACD, MACD_Signal):
        self.stock_price = stock_price
        self.MACD = MACD
        self.MACD_Signal = MACD_Signal
    
    def trade(self):
        if MACD[-1] < MACD_Signal[-1] and MACD[-2] > MACD_Signal[-2]:
            print(stock_price[0])

        elif MACD[-1] > MACD_Signal[-1] and MACD[-2] < MACD_Signal[-2]:
            print(stock_price[0]*-1)
    
I want to return stock price that fulfill the criteria set out in def trade function.

then i move to the next

Testing = MACD_Strategy(China_Mobile['China Mobile Ltd - Last Price'], China_Mobile['MACD'], China_Mobile['MACD_Signal'])
Testing.trade()
Chnina_Mobile is a dataframe consisting date, last price, MACD and MACD signal.

then i got the error

Error:
TypeError Traceback (most recent call last) <ipython-input-140-4ca2b450b15b> in <module> ----> 1 Testing.trade() <ipython-input-138-debb79fae608> in trade(self) 6 7 def trade(self): ----> 8 if MACD[-1] < MACD_Signal[-1] and MACD[-2] > MACD_Signal[-2]: 9 print(stock_price[0]) 10 TypeError: 'type' object is not subscriptable
PLease help
Reply
#2
Apperently the parameters you give are not as expected. Try to play with the parameters. Inspect the contents of the structure "China_Mobile".
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question how to solve `'TypeError: 'int' object is not iterable`? netanelst 2 1,524 May-24-2022, 12:03 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020