Trading Indicators with Python and ChatGPT

By Sushant Pisupati | June, 2025

When working with stock market data, the ability to visualize indicators and assets is an important part of the analysis process. Python is the most widely used tool for this kind of work, as it provides efficient ways to process and plot financial data. AI tools like ChatGPT can help speed up the coding process, especially for common tasks.

Moving Average Crossovers

Moving average crossovers are a simple way to identify possible trend changes. A short-term average crossing above a longer-term average can imply an upward trend, while the opposite can signify a potential downtrend.

Using ChatGPT, you can generate a Python script that:

  • Downloads historical stock data (e.g., for AAPL)
  • Calculates 20-day and 50-day simple moving averages
  • Plots both moving averages on the price chart
  • Labels crossover points as buy or sell signals

This visualization helps illustrate where signals occur and how they relate to existing trends.

Prompt:

Write a Python script that downloads AAPL stock data, calculates 20-day and 50-day moving averages, plots them on a chart, and marks buy/sell points.

Result:

RSI and Signal Zones

The RSI indicator is used to spot overbought and oversold zones. It is usually plotted with horizontal lines at 70 and 30 to indicate these zones.

A script generated with ChatGPT can:

  • Calculate the 14-day RSI
  • Display it in a separate plot below the price
  • Add lines at 70 and 30
  • Highlight the regions where RSI enters these zones

This makes it easier to see when the stock may be reaching potential reversal zones.

Prompt:

Generate Python code to calculate and plot the 14-day RSI for AAPL with lines at 70 and 30, and highlight overbought/oversold areas.

Result:

Comparing Two Assets

When comparing two assets, it can be helpful to visualize their price trends and correlation.

A Python script can be used to:

  • Download historical data for both stocks
  • Plot both assets on the same timeline
  • Create a plot comparing their daily closing prices

These charts provide a quick way to see how closely the two assets move together.

Prompt:

Create a Python script to download and plot MSFT and NVDA closing prices on the same chart. Also add a scatter plot of daily returns with their correlation coefficient.

Result:

Conclusion

While experienced traders can write these strategies without AI, it can be time-consuming, especially when exploring deeper strategies. ChatGPT can help by generating basic code quickly, which can then be modified.

More Resources:

About The Author

Sushant Pisupati competed in numerous finance, mathematics, and physics competitions, and has successfully translated his skills into the field quantitative finance. At Aries Profits, his goal is to help others learn about the fascinating field of quantitative trading/investing, and make this subject easy and accessible for everybody.

You Might Also Like

Submit Your Comment

Blog Comment Form