Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Articles

15-minute candlestick chart with the MACD indicator in Python

15-minute candlestick chart with the Moving Average Convergence Divergence (MACD) indicator in Python

To create a 15-minute candlestick chart with the Moving Average Convergence Divergence (MACD) indicator in Python, you can use libraries like Pandas, Matplotlib, and TA-Lib (a technical analysis library). First, make sure you have these libraries installed:

```bash
pip install pandas matplotlib TA-Lib
```

Now, you can create a Python script to generate the chart:

```python
import pandas as pd
import matplotlib.pyplot as plt
import talib

# Sample price data (replace this with your own data)
price_data = [
    {'timestamp': '2023-10-26 09:00:00', 'open': 100, 'high': 110, 'low': 90, 'close': 105, 'volume': 1000},
    {'timestamp': '2023-10-26 09:15:00', 'open': 105, 'high': 115, 'low': 100, 'close': 110, 'volume': 1500},
    # Add more data points here
]

# Convert the data to a Pandas DataFrame
df = pd.DataFrame(price_data)
df['timestamp'] = pd.to_datetime(df['timestamp'])
df.set_index('timestamp', inplace=True)

# Resample the data to 15-minute intervals
df = df.resample('15T').agg({
    'open': 'first',
    'high': 'max',
    'low': 'min',
    'close': 'last',
    'volume': 'sum'
}).dropna()

# Calculate the MACD indicator
macd, signal, _ = talib.MACD(df['close'], fastperiod=12, slowperiod=26, signalperiod=9)

# Create the candlestick chart with MACD indicator
fig, ax1 = plt.subplots(figsize=(12, 6))

# Plot candlesticks
candlestick = ax1.plot(df.index, df[['open', 'high', 'low', 'close']].values, marker='o', linestyle='-')

# Plot MACD and Signal Line
ax2 = ax1.twinx()
ax2.plot(df.index, macd, label='MACD', color='blue')
ax2.plot(df.index, signal, label='Signal Line', color='red')

# Customize the chart
ax1.set_title('15-Minute Candlestick Chart with MACD')
ax1.set_xlabel('Time')
ax1.set_ylabel('Price')
ax2.set_ylabel('MACD')

# Show the legend
ax2.legend(loc='upper left')

# Show the chart
plt.show()
```

In this script:

- Replace the `price_data` list with your own 15-minute price data.
- We use Pandas to manipulate and resample the data to 15-minute intervals.
- The TA-Lib library is used to calculate the MACD and Signal Line.
- The Matplotlib library is used to create the candlestick chart and plot the MACD indicator.
- The script creates a dual-axis chart with candlesticks on one axis and the MACD indicator on the other axis.

This example demonstrates how to visualize a 15-minute candlestick chart with the MACD indicator in Python. You can modify the data and chart settings to fit your specific requirements.

caa October 28 2023 273 reads 0 comments Print

0 comments

Leave a Comment

Please Login to Post a Comment.
  • No Comments have been Posted.

Sign In
Not a member yet? Click here to register.
Forgot Password?