import pandas as pd
def ichimoku(df):
# Calculate the Ichimoku components
high_9 = df['High'].rolling(window=9).max()
low_9 = df['Low'].rolling(window=9).min()
df['Tenkan-sen'] = (high_9 + low_9) / 2 # Conversion Line
high_26 = df['High'].rolling(window=26).max()
low_26 = df['Low'].rolling(window=26).min()
df['Kijun-sen'] = (high_26 + low_26) / 2 # Base Line
df['Senkou Span A'] = ((df['Tenkan-sen'] + df['Kijun-sen']) / 2).shift(26) # Leading Span A
df['Senkou Span B'] = ((df['High'].rolling(window=52).max() + df['Low'].rolling(window=52).min()) / 2).shift(26) # Leading Span B
df['Chikou Span'] = df['Close'].shift(-26) # Lagging Span
return df
# Example usage:
# df = pd.read_csv('your_data.csv') # Load your data
# df = ichimoku(df)
# print(df[['Tenkan-sen', 'Kijun-sen', 'Senkou Span A', 'Senkou Span B', 'Chikou Span']])
def ichimoku(df):
# Calculate the Ichimoku components
high_9 = df['High'].rolling(window=9).max()
low_9 = df['Low'].rolling(window=9).min()
df['Tenkan-sen'] = (high_9 + low_9) / 2 # Conversion Line
high_26 = df['High'].rolling(window=26).max()
low_26 = df['Low'].rolling(window=26).min()
df['Kijun-sen'] = (high_26 + low_26) / 2 # Base Line
df['Senkou Span A'] = ((df['Tenkan-sen'] + df['Kijun-sen']) / 2).shift(26) # Leading Span A
df['Senkou Span B'] = ((df['High'].rolling(window=52).max() + df['Low'].rolling(window=52).min()) / 2).shift(26) # Leading Span B
df['Chikou Span'] = df['Close'].shift(-26) # Lagging Span
return df
# Example usage:
# df = pd.read_csv('your_data.csv') # Load your data
# df = ichimoku(df)
# print(df[['Tenkan-sen', 'Kijun-sen', 'Senkou Span A', 'Senkou Span B', 'Chikou Span']])
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.