Hi,
does this library supports two different colors for fill between function? I would like to visualize the Ichimoku clouds with this library.
Below I pasted a script that uses a matplotlib to draw Ichimoku clouds and other lines to show what a mean.
# Import packages
import pandas as pd
import matplotlib.pyplot as plt
import yfinance as yf
from datetime import timedelta
import finplot as fplt
# Read BTC/USD data
df = yf.download(tickers='GC=F', period="1y", interval="1d", group_by="ticker")
# dft = yf.Ticker("GC=F")
# Define length of Tenkan Sen or Conversion Line
tenkansen_period = 9
# Define length of Kijun Sen or Base Line
kijunsen_period = 26
# Define length of Senkou Sen B or Leading Span B
senkou_span_b_period = 52
# Define length of Chikou Span or Lagging Span
chikou_span_period = 26
senkou_span_shift_period = 26
# Calculate Tenkan-sen line
tenkansen_max = df['High'].rolling(window = tenkansen_period).max()
tenkansen_min = df['Low'].rolling(window = tenkansen_period).min()
df['tenkansen'] = (tenkansen_max + tenkansen_min) / 2
# Calculate based line
kijunsen_high = df['High'].rolling(window = kijunsen_period).max()
kijunsen_min = df['Low'].rolling(window = kijunsen_period).min()
df['kijunsen'] = (kijunsen_high + kijunsen_min) / 2
# this is to extend the 'df' in future for 26 days for senkou spans
df = df.reindex(df.index.append(pd.date_range(df.index[-1] + pd.Timedelta(days=1), periods = 26, freq = 'B')))
# Calculate leading span A
df['senkou_span_A'] = ((df.tenkansen + df.kijunsen) / 2).shift(chikou_span_period)
# Calculate leading span B
senkou_span_b_max = df['High'].rolling(window = senkou_span_b_period).max()
senkou_span_b_min = df['Low'].rolling(window = senkou_span_b_period).min()
df['senkou_span_B'] = ((senkou_span_b_max + senkou_span_b_min) / 2).shift(senkou_span_shift_period)
# Calculate lagging span
df['chikou_span'] = df['Close'].shift(-chikou_span_period)
# Drop NA values from Dataframe
# df.dropna(inplace=True)
##### using matplotlib
# Add figure and axis objects
fig, ax = plt.subplots(1, 1, sharex=True, figsize=(20, 9))
# Plot Close with index on x-axis with a line thickness of 4
ax.plot(df.index, df['Close'], linewidth=4)
# Plot Leading Span A with index on the shared x-axis
ax.plot(df.index, df['senkou_span_A'], color='lightskyblue')
# Plot Leading Span B with index on the sahred x-axis
ax.plot(df.index, df['senkou_span_B'], color='orange')
# Use the fill_between of ax object to specify where to fill
ax.fill_between(df.index, df['senkou_span_A'], df['senkou_span_B'],
where=df['senkou_span_A'] >= df['senkou_span_B'], color='skyblue')
ax.fill_between(df.index, df['senkou_span_A'], df['senkou_span_B'],
where=df['senkou_span_A'] < df['senkou_span_B'], color='darkorange')
ax.plot(df.index, df['chikou_span'], color='lightgreen')
ax.plot(df.index, df['tenkansen'], color='chocolate')
ax.plot(df.index, df['kijunsen'], color='blue')
plt.legend(loc=0)
plt.grid()
plt.show()
# create axe
# ax = fplt.create_plot('y title', rows=1)
# fplt.candlestick_ochl(df[['Open', 'Close', 'High', 'Low']], ax=ax)
# seknkou_a_plt = fplt.plot(df.index, df['senkou_span_A'], ax=ax, color='skyblue')
# seknkou_b_plt = fplt.plot(df.index, df['senkou_span_B'], ax=ax, color='darkorange')
# fplt.show()
Hi,
does this library supports two different colors for fill between function? I would like to visualize the Ichimoku clouds with this library.
Below I pasted a script that uses a matplotlib to draw Ichimoku clouds and other lines to show what a mean.