Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing For Specifically the Tenkan #847

Closed
TraderCode99 opened this issue Nov 5, 2024 · 1 comment
Closed

Testing For Specifically the Tenkan #847

TraderCode99 opened this issue Nov 5, 2024 · 1 comment
Labels
help wanted Extra attention is needed info Informational

Comments

@TraderCode99
Copy link

TraderCode99 commented Nov 5, 2024

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?

@twopirllc twopirllc added help wanted Extra attention is needed info Informational labels Nov 7, 2024
@twopirllc
Copy link
Owner

Hello @azimgiant,

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.

Kind Regards,
KJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed info Informational
Projects
None yet
Development

No branches or pull requests

2 participants