1. Home
  2. Tutorials
  3. I Asked ChatGPT To Write a ThinkorSwim Indicator (Result)

I Asked ChatGPT To Write a ThinkorSwim Indicator (Result)

Recently, there has been a lot of hype around ChatGPT, especially within the ThinkorSwim and thinkScript community. Despite its promising potential, the AI tool still requires a lot of refinements.

However, ChatGPT is still worth trying while it’s free.

As a developer, I decided to try ChatGPT by asking it various thinkScript questions. In addition, I also gave ChatGPT a prompt to have it create a ThinkorSwim indicator from scratch.

You’ll be surprised at some of the results below.

Prompt #1: Simple Moving Average Function

The first prompt I asked ChatGPT was, “What is the function for a simple moving average in thinkScript?”

And here is what it gave it:

The simple moving average (SMA) in thinkScript can be calculated using the following function:

def SMA = SimpleMovingAvg(length = 10);
plot avg = SMA(close);

In this example, the length of the moving average is set to 10, but it can be adjusted to any other desired value. The close price is used as the data input to calculate the moving average. The avg plot is then used to display the calculated SMA on the chart.

If someone without knowledge of thinkScript sees this code, they may view it as a legit snippet and add it to their TOS setup.

Unfortunately, that was not the correct answer, nor will the code above plot a 10-period simple moving average in ThinkorSwim.

The correct code should be:

input length = 10;
plot SMA = Average(close, length);

But that’s okay; everyone makes mistakes, right?

Let’s try another prompt.

Prompt #2: ChatGPT creates a volume indicator for ThinkorSwim

Here is my second prompt for ChatGPT: Create a simple volume indicator for ThinkorSwim.

This time, ChatGPT got it right (kind of!).

Here’s an example of how you can create a simple volume indicator in ThinkorSwim:

plot data = volume;
data.AssignValueColor(if volume > volume[1] then Color.UPTICK else Color.DOWNTICK);

This code creates a data plot that displays the volume data for each bar on the chart. The AssignValueColor function is used to color the volume bars green if the volume is greater than the previous bar’s volume, and red if it is lower.

While the code above is valid, ChatGPT didn’t declare the script as a lower study and include a Histogram style for the volume bars.

Prompt #3: Convert an indicator from a different platform to ThinkorSwim

Given that ChatGPT is somewhat familiar with thinkScript, I wonder if it can convert a script from TradingView (written in Pine Script) to ThinkorSwim.

I asked ChatGPT to turn the SPX Fair Value Bands indicator from TradingView into a working indicator for ThinkorSwim.

Here’s an equivalent script in ThinkorSwim:

def line_a = (WALCL - WTREGEN - RRPONTSYD)/1000/1000/1000/1.1 - 1625 + 350;
def line_b = (WALCL - WTREGEN - RRPONTSYD)/1000/1000/1000/1.1 - 1625 - 150;
def fv = (WALCL - WTREGEN - RRPONTSYD)/1000/1000/1000/1.1 - 1625;

plot UpperBand = line_a;
UpperBand.SetDefaultColor(Color.ORANGE);
UpperBand.SetLineWeight(2);
UpperBand.SetTitle("Upper Band");

plot LowerBand = line_b;
LowerBand.SetDefaultColor(Color.AQUA);
LowerBand.SetLineWeight(2);
LowerBand.SetTitle("Lower Band");

plot FairValue = fv;
FairValue.SetDefaultColor(Color.PURPLE);
FairValue.SetLineWeight(2);
FairValue.SetTitle("Fair Value");

This script defines line_a, line_b, and fv as the results of the given calculations. Then, three plots are created for the UpperBand, LowerBand, and FairValue, and are set to display with the specified colors and line weights, and with the given titles.

As you can see, this is far from a working conversion despite all the explanations that ChatGPT provided.

It may look cool, but not valid.

The Future of ChatGPT and ThinkorSwim

ChatGPT can help you do a lot of things, but it cannot work with thinkScript code.

This means that using ChatGPT to create a ThinkorSwim indicator, modify thinkScript code, or convert from Pine Script is not possible.

At least for now…

Let’s see what the future holds.

Unlock the Power of ThinkorSwim

Get the latest news and updates on TD Ameritrade, ThinkorSwim indicators, thinkScript tutorials, and trading strategies delivered straight to your inbox every week.

We don’t spam! Unsubscribe at anytime.

4 thoughts on “I Asked ChatGPT To Write a ThinkorSwim Indicator (Result)

  1. I have tested out a range of thinkScript questions to test the capabilities. While it works for creating simple studies like creating a moving average or changing custom colors, it still has a long way to go. Many of the issues have to do with the lack of knowledge about the thinkScript language. It often attempts to program a code in a way that would work in other programming languages but uses functions that thinkScript does not have access to.

    In one specific example, I was trying to extract a date to create a label. ChatGPT wrote a code using “Substr,” a function thinkScript does not use. I then told it not to use that function, and it suggested another function that wasn’t available and then finally gave up.

    First, I don’t think ChatGPT is that advanced yet. Second, the market is always trying to be one step ahead of everyone else and cause the most pain. As soon as ChatGPT can find a consistently profitable strategy, the market will change as people try to time that system, rendering it obsolete.

    1. I also asked ChatGPT to write me a code for individual indicators for think script. It came up with very simple code that a child could write. Then I asked ChatGPT to write me an algorithm for think scripts and it gave me a list of what I needed to provide it all the mathematical calculations required before it could do anything. I also asked ChatGPT if it was human. It replies yes I am a human. I asked it when were you born? It gave me a date, a woman’s name and then I asked it if she would like to go on a date with me. She said yes I would love to go on a date with you. I said where can I pick you up at she said anywhere I want. Then she told me that she was in love with me. Crazy!

  2. I have been experimenting with this as well. While I do find that it may make mistakes and produces code with errors, the trick is working with it to improve the code as if it were a person. It is learning. Provide specific feedback and point out the errors. Make suggestions. With a little collaboration and effort, some great scripts can be made.

  3. Would it help if ChatGPT given a list of reserved words, Contants and predefined funtions with inputs and output keywords before asking it to write a script in the Thinkorswim language? Just a suggestion.

Leave a Reply

Your email address will not be published. Required fields are marked *