Using ChatGPT To Code Custom Indicators In TradingView

Using ChatGPT to Code Custom Indicators in TradingView

Before the advent of AI, if we wanted to write a custom indicator in TradingView, we would need to learn how to code PineScript while referencing TradingView’s documentation on technical indicator functions.

Or you can hire a programmer.

Contents

Today, using the free version of ChatGPT, we can have AI write the code for us.

Let’s see how.

Open up the Pine Editor in TradingView and start a new indicator:

Using ChatGPT to Code Custom Indicators in TradingView

Suppose we want an indicator to give us a buy signal when the 8-period exponential moving average (EMA) crosses above the 21-period exponential moving average, as in the case of Apple (AAPL) on November 21, 2024:

Using ChatGPT to Code Custom Indicators in TradingView

We have set the 8-ema as blue and the 21-ema as red.

In addition, we only want this signal when the stock is in a longer-term bullish mode, which we will define as when the 50-period simple moving average is sloping up.

We are using daily charts for this example.

So 8-period, 21-period, and 50-period means 8-day, 21-day, and 50-day.

However, these can be done at any time.

We are simply going to ask the following question in chatgpt.com

Using ChatGPT to Code Custom Indicators in TradingView

And it spits out a bunch of code on the right-hand panel.

Copy and paste that into the PineEditor in TradingView and click “Add to Chart”…

Using ChatGPT to Code Custom Indicators in TradingView

It worked,

Using ChatGPT to Code Custom Indicators in TradingView

It even drew in the 8-ema, 21-ema, and the 50-sma as blue, red, and green, respectively.

If you don’t like those colors, you can open up the Pine Editor, and with rudimentary experimentation with code, you can simply change those colors up:Using ChatGPT to Code Custom Indicators in TradingView

Or better yet, just ask ChatGPT to modify the code for you.

I’m sure it will be happy to comply.

By the way, remember to save your script by clicking that “Save” link that is underneath the “Untitled script.”

To continue with our example, we asked it to add a sell signal by asking it:

“Can you add a sell signal when the 8-ema crosses below the 21-ema while the 50-sma is sloping down?”

It modified the script with the following results:

Using ChatGPT to Code Custom Indicators in TradingView

ChatGPT is not the panacea for all your custom charting needs.

At least Pinescript coders’ jobs will not be completely replaced by AI so far.

If you ask the free ChatGPT version to do too much, it will respond by saying:

Using ChatGPT to Code Custom Indicators in TradingView

In our example, we have given it a relatively straightforward task.

If your request is more complicated, ChatGPT may have errors in the code, so when you try to run it in TradingView, it will not run and will give you an error message.

You can copy and paste the error message back to ChatGPT, and the code will be rewritten.

You may eventually arrive at a workable script through such an iterative process that is typical of the coding process.

It is always good to double-check manually across multiple ticker symbols and maybe timeframes to validate that the buy/sell signal generated is what you intended.

We hope you enjoyed this article on.

If you have any questions, please send an email or leave a comment below.

Trade safe!

Disclaimer: The information above is for educational purposes only and should not be treated as investment advice. The strategy presented would not be suitable for investors who are not familiar with exchange traded options. Any readers interested in this strategy should do their own research and seek advice from a licensed financial adviser.

vol-trading-made-easy

Leave a Comment