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 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.
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
fv as the results of the given calculations. Then, three plots are created for the
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.