My code may be in a endless loop, what happened?
-
This is my code on strategy
class Turtle(bt.Strategy): def __init__(self): self.ATR = list(range(len(self.datas))) for i in range(len(self.datas)): self.ATR[i] = bt.talib.ATR([self.datas[i].high, self.datas[i].low, self.datas[i].close], timeperiod=20) # P227 self.sys = None self.lasttrade = None
I used many datafeeds. When I use this code, the program never runs out.
When I commented out this code as followself.ATR = list(range(len(self.datas))) for i in range(len(self.datas)): self.ATR[i] = bt.talib.ATR([self.datas[i].high, self.datas[i].low, self.datas[i].close], timeperiod=20) # P227
Everything will be OK. What happened?
I hope someone can help me. -
Any reason as to why you pass a list to
ATR
? -
@backtrader
I have many stocks, so I just want to store ATRs by a list.
My aim is:self.ATR[0] = datas[0]'s ATR self.ATR[1] = datas[1]'s ATR ......
Now I use bt.indicators.ATR can achieve this goal:
self.ATR = list(range(len(self.datas))) for index, stock_data in enumerate(self.datas): self.ATR[index] = bt.indicators.ATR(self.datas[index], period=20)
But I still want to know why Ta-lib doesn't work. What is wrong with me?
-
If you change you
talib.ATR
call as follows it might also work:self.ATR[i] = bt.talib.ATR(self.datas[i].high, self.datas[i].low, self.datas[i].close, timeperiod=20)
-
@mike-van said in My code may be in a endless loop, what happened?:
I have many stocks, so I just want to store ATRs by a list.
The question was not why you store the ATRs in a list.
@backtrader said in My code may be in a endless loop, what happened?:
Any reason as to why you pass a list to ATR?
The question is why you pass a
list
to ATR.See the answer by @ab_trader
-
@ab_trader Thanks a lot. Let me try again.
-
@backtrader
I just define self.ATR as a list to store ATRs of different stocks.
What the better method should I use to store different stocks' indicators? -
Please, re-read the messages above. Nobody was talking about how you stored the ATRs.
-
@backtrader ohoh I get it. My English understanding is really poor. Thanks for your patience.