You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying to specifically test for the Tenkan part of the Ichimoku indicator but am running into some trouble. I am not able to pull the specific column as I have previously done for other indicators. This is my code:
`def indicator(data, tenkan_length = 30, kijun_length = 26, senkou_length = 52):
ichimoku = ta.overlap.ichimoku(high=df.High, low=df.Low, close=df.Close, tenkan=tenkan_length, kijun=kijun_length, senkou=senkou_length, include_chikou=False)
if ichimoku is None:
ichimoku = np.ichimoku(len(data))
else:
ichimoku = ichimoku[:len(data)] # Truncate to match data length
ichimoku = np.nan_to_num(ichimoku) # Replace NaN values with zeros
return ichimoku
class TENKAN(Strategy):
tenkan_length = 30
def init(self):
self.tenkan = self.I(indicator, self.data, self.tenkan_length)
self.Buy_position_open = False
self.Sell_position_open = False
def next(self):
if (crossover(self.data.Close, self.tenkan[2])):
self.buy(size=0.5)
self.Buy_position_open = True
elif (crossover(self.tenkan[2], self.data.Close)):
self.sell(size=0.5)
self.Sell_position_open = True
if (self.position.pl_pct < -0.003 and self.Buy_position_open) or (self.position.pl_pct > 0.015 and self.Buy_position_open):
self.position.close()
self.Buy_position_open = False
elif (self.position.pl_pct < -0.015 and self.Sell_position_open) or (self.position.pl_pct > 0.003 and self.Sell_position_open):
self.position.close()
self.Sell_position_open = False`
RuntimeError: Indicator "indicator(30)" errored with exception: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
Not sure what this error means. I've tried using chat gpt but that hasn't helped. Is there any other way to do this?
The text was updated successfully, but these errors were encountered:
Would be great if you can provide more info, such as Pandas TA version, and other relevant details. Also it would be great if you could clean up your code so it is more readable.
I have been trying to specifically test for the Tenkan part of the Ichimoku indicator but am running into some trouble. I am not able to pull the specific column as I have previously done for other indicators. This is my code:
`def indicator(data, tenkan_length = 30, kijun_length = 26, senkou_length = 52):
ichimoku = ta.overlap.ichimoku(high=df.High, low=df.Low, close=df.Close, tenkan=tenkan_length, kijun=kijun_length, senkou=senkou_length, include_chikou=False)
if ichimoku is None:
ichimoku = np.ichimoku(len(data))
else:
ichimoku = ichimoku[:len(data)] # Truncate to match data length
ichimoku = np.nan_to_num(ichimoku) # Replace NaN values with zeros
return ichimoku
class TENKAN(Strategy):
tenkan_length = 30
def init(self):
self.tenkan = self.I(indicator, self.data, self.tenkan_length)
self.Buy_position_open = False
self.Sell_position_open = False
def next(self):
if (crossover(self.data.Close, self.tenkan[2])):
self.buy(size=0.5)
self.Buy_position_open = True
elif (crossover(self.tenkan[2], self.data.Close)):
self.sell(size=0.5)
self.Sell_position_open = True
if (self.position.pl_pct < -0.003 and self.Buy_position_open) or (self.position.pl_pct > 0.015 and self.Buy_position_open):
self.position.close()
self.Buy_position_open = False
elif (self.position.pl_pct < -0.015 and self.Sell_position_open) or (self.position.pl_pct > 0.003 and self.Sell_position_open):
self.position.close()
self.Sell_position_open = False`
RuntimeError: Indicator "indicator(30)" errored with exception: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.
Not sure what this error means. I've tried using chat gpt but that hasn't helped. Is there any other way to do this?
The text was updated successfully, but these errors were encountered: