ChatGPT, BARD, Other AI Scripts Which Can't Be Used In ThinkOrSwim

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
90% of the members attempting chatGPT scripting; do not provide good detailed specifications.

Members know what end result that they want but lack the ability to tell chatGPT, the step-by-step logic required to code a script to achieve that end result.
This results in chatGPT providing poor code.

Here is a video on how to successfully have chatGPT create functional scripts.

The above video, explains the basics of providing good specifications to AI which results in better scripts.
AOzhl05.png
 
Last edited:
I am trying to write a simple script to pull the price of a specific option using thinkscript but I am running into an error I am not sure how to get around. Any help?

# Define the option symbol and expiration date
def symbol = "CMG";
def expirationDate = 20230505;

# Define the strike price
def strikePrice = 1500;

# Get the current option price
optionPrice = close(symbol = symbol, period = "DAY", optionType = OptionType.CALL, expirationdate = expirationDate, strike = strikePrice);


And then I also wanted the live stock price for the same symbol and was using:

# Get the current stock price
def stockPrice = close(symbol);

but this is returning errors as well.

any help?

Thank you

reply to post77

hello,
you 'get around' errors by looking up functions in the manual and seeing if they exist and seeing what the valid parameters are.


close has 3 parameters. no option related ones.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals/close


try using this one
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Option-Related/OptionPrice
OptionPrice ( strike, isPut, daysToExpiration, underlyingPrice, Volatility, isEuropean, yield, interestRate);


i threw this together to generate a number. you can research and take it from here.

i used a constant for the days (7) to expire. so it should work for today.
you can experiment with date functions and come up with a formula to use in its place.

i used a simple version for implied volitility. there is a longer formula in the example for optionprice()


Code:
# chat77_option_price

#https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-123458
#post77
#degenjay

#I am trying to write a simple script to pull the price of a specific option using thinkscript but I am running into an error I am not sure how to get around. Any help?

# Define the option symbol and expiration date
input symbol = "CMG";
def expirationDate = 20230505;

# Define the strike price
def strikePrice = 1500;

# Get the current option price
#optionPrice = close(symbol = symbol, period = "DAY", optionType = OptionType.CALL, expirationdate = expirationDate, strike = strikePrice);

def iv = imp_volatility(symbol);

#try using this one
#https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Option-Related/OptionPrice
def op = OptionPrice( strike = strikePrice , isPut = no, daysToExpiration = 7, underlyingPrice = close(symbol), Volatility = iv, isEuropean = no);
#, yield,  interestRate);  


addlabel(1, " ", color.black);
addlabel(1, "stock " + symbol, color.yellow);
addlabel(1, "option price " + op, color.yellow);


#-------------------------
#And then I also wanted the live stock price for the same symbol and was using:

# Get the current stock price
def stockPrice = close(symbol);

addlabel(1, "stock price " + stockprice, color.yellow);
#
 
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I have tried to write a script that counts Fair Value Gaps on whatever time frame the aggregation period is set to. The code is returning a few errors and I can't seem to figure out how to get rid of the errors. Any help or guidance woiuld be greatly appreciated. The code is posted below with my notes for each section:

#ThinkScript for FVG label to count like a sequence counter
#Counts consecutive positive or negative, when the direction changes the previous direction resets to zero
#There are still errors in this code that I am trying to chase down

# Inputs default at daily chart
#For 1 minute chart change to timeframe = AggregationPeriod.MIN
#For 5 minute chart change to timeframe = AggregationPeriod.FIVE_MIN
#For 1 day chart change to timeframe = AggregationPeriod.DAY

input timeframe = AggregationPeriod.MIN;
input fairValue = 0.0;

# Calculate Fair Value Gap
def high1 = high(period = timeframe)[1];
def low1 = low(period = timeframe)[1];
def high3 = high(period = timeframe)[3];
def low3 = low(period = timeframe)[3];
def fairValueGap = if high1 < low3 then 1 else if low1 > high3 then -1 else 0;

# Track Consecutive Positive and Negative Gaps
def consecutivePositiveGaps = if fairValueGap == 1 then Max(1, consecutivePositiveGaps[1] + 1) else 0;
def consecutiveNegativeGaps = if fairValueGap == -1 then Max(1, consecutiveNegativeGaps[1] + 1) else 0;

# Plot Rectangle and Label with Sequence Counter
def isPositiveGap = fairValueGap == 1;
def isNegativeGap = fairValueGap == -1;
def positiveGapLabel = "+FVG " + consecutivePositiveGaps;
def negativeGapLabel = "-FVG " + consecutiveNegativeGaps;
AddChartBubble(isPositiveGap, low3, positiveGapLabel, Color.GREEN, no);
AddChartBubble(isNegativeGap, high3, negativeGapLabel, Color.RED, no);
AddVerticalLine(isPositiveGap, low3, high1, Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(isNegativeGap, high3, low1, Color.RED, Curve.SHORT_DASH);
AddCloud(isPositiveGap, low3, high1, Color.GREEN, Color.LIGHT_GRAY);
AddCloud(isNegativeGap, high3, low1, Color.RED, Color.LIGHT_GRAY);

reply to post79 MTF FVG

i have no idea what this is supposed to do.
your 2nd aggregation doesn't make any sense, if chart is 5 min, set to 5 min..... if it is to be the same, just use the data on the chart. don't need to use 2nd aggregation. there is no reason to use 1 min 2nd agg. just use chart data at 1 min.
i set the chart to 1 minute.

i changed some things and got rid of the errors. no idea if it is what is desired.


Code:
#chat79_fvg_mtf

#https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-123506
#theYaniac

#I have tried to write a script that counts Fair Value Gaps on whatever time frame the aggregation period is set to. The code is returning a few errors and I can't seem to figure out how to get rid of the errors. Any help or guidance woiuld be greatly appreciated. The code is posted below with my notes for each section:

#ThinkScript for FVG label to count like a sequence counter
#Counts consecutive positive or negative, when the direction changes the previous direction resets to zero
#There are still errors in this code that I am trying to chase down

# Inputs default at daily chart
#For 1 minute chart change to timeframe = AggregationPeriod.MIN
#For 5 minute chart change to timeframe = AggregationPeriod.FIVE_MIN
#For 1 day chart change to timeframe = AggregationPeriod.DAY

input timeframe = AggregationPeriod.MIN;
input fairValue = 0.0;

# Calculate Fair Value Gap
def high1 = high(period = timeframe)[1];
def low1 = low(period = timeframe)[1];
def high3 = high(period = timeframe)[3];
def low3 = low(period = timeframe)[3];
def fairValueGap = if high1 < low3 then 1 else if low1 > high3 then -1 else 0;

# Track Consecutive Positive and Negative Gaps
def consecutivePositiveGaps = if fairValueGap == 1 then Max(1, consecutivePositiveGaps[1] + 1) else 0;
def consecutiveNegativeGaps = if fairValueGap == -1 then Max(1, consecutiveNegativeGaps[1] + 1) else 0;

# Plot Rectangle and Label with Sequence Counter
def isPositiveGap = fairValueGap == 1;
def isNegativeGap = fairValueGap == -1;

#def positiveGapLabel = "+FVG " + consecutivePositiveGaps;
#def negativeGapLabel = "-FVG " + consecutiveNegativeGaps;
AddLabel(1, "+FVG " + consecutivePositiveGaps, Color.YELLOW);
AddLabel(1, "-FVG " + consecutiveNegativeGaps , Color.YELLOW);

#AddChartBubble(isPositiveGap, low3, positiveGapLabel, Color.GREEN, no);
#AddChartBubble(isNegativeGap, high3, negativeGapLabel, Color.RED, no);
AddChartBubble(isPositiveGap, low3, consecutivePositiveGaps, Color.GREEN, no);
AddChartBubble(isNegativeGap, high3, consecutiveNegativeGaps, Color.RED, no);


#AddVerticalLine(isPositiveGap, low3, high1, Color.GREEN, Curve.SHORT_DASH);
#AddVerticalLine(isNegativeGap, high3, low1, Color.RED, Curve.SHORT_DASH);

# AddVerticalLine ( visible, text, color, stroke); 
AddVerticalLine(isPositiveGap, high1, Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(isNegativeGap, low1, Color.RED, Curve.SHORT_DASH);

#AddCloud(isPositiveGap, low3, high1, Color.GREEN, Color.LIGHT_GRAY);
#AddCloud(isNegativeGap, high3, low1, Color.RED, Color.LIGHT_GRAY);
AddCloud(isPositiveGap, low3, Color.GREEN, Color.LIGHT_GRAY);
AddCloud(isNegativeGap, high3, Color.RED, Color.LIGHT_GRAY);
#
 
Whats the trick asking questions to the AI so it doesnt "wander" with the code language?
Ive tried: Using thinkscript create .... but it still uses code that doesnt work??
 
Whats the trick asking questions to the AI so it doesnt "wander" with the code language?
Ive tried: Using thinkscript create .... but it still uses code that doesnt work??

[edit...]

just my opinion.
i think we are a decade away from having anything useful.
[ to generate programs]

it does seem odd, that chatgpt, a program, written by programmers, does poorly at creating programs, while being able to create literature....

[ it was created to simulate human speech, and that it does well. it wasn't designed for programming.

ChatGPT, a language model developed by OpenAI, has become incredibly popular over the past year due to its ability to generate human-like responses in a wide range of circumstances.

chapgpt test stats
among 16 topics, it scored the lowest in
programming
https://www.visualcapitalist.com/how-smart-is-chatgpt/
]

----------

there is no trick,

it
doesn't
work

it
doesn't
understand
thinkscript

it
will
not
create
a
functional
complicated
study

if you want a study, learn the language and create it.
 
Last edited:
there is no trick,

it
doesn't
work

it
doesn't
understand
thinkscript

it
will
not
create
a
functional
complicated
study

if you want a study, learn the language and create it.

Unless you know every logical operation in the indicator you are trying to make with it to a high degree of certainty and can convey that logic well in plain English you will likely be disappointed. At that point you might as well know the code yourself. It can do simple things. It can modify existing code. And, something I've actually found very helpful is it can explain code to you in plain English. This, to me at least, has been very helpful for debugging because it gives you another perspective on the logic. You could automate the process of adding comments to your code if you make something complex and want others to understand. You can dump a library into the AI and see of it applies functions you may have overlooked. AI is just a tool. At best it can fill gaps in your knowledge as a programmer, automate basic tasks, or be used to help generate ideas. I've actually spent dozens of hours messing with it for the purpose of indicator generation (mostly in NinjaScript) and probably would have been better off just figuring the stuff out myself. You definitely need to spend time with it to learn it's limitations and know how to finesse real productivity gains out it. Because it has definitely helped me learn quite a bit and get unstuck from problems. Not by any means a magic bullet though.
 
@JoeDV You already got access to Google Bard? That was quick. I'm still on the waiting list, haha.

How is it compare to ChatGPT when it comes to thinkScripting?
ChatGPT works. Way better than bard. Chat works best when given think script examples in my opinion but it can create code that is accepted by the software just doesnt actually do anything or at least I cant get it to.
 
just my opinion.
i think we are a decade away from having anything useful.

it does seem odd, that chatgpt, a program, written by programmers, does poorly at creating programs, while being able to create literature....


there is no trick,

it
doesn't
work

it
doesn't
understand
thinkscript

it
will
not
create
a
functional
complicated
study

if you want a study, learn the language and create it.
ChatGPT seems to be getting better by the day. But no it cant create complex code like you guys. I feed it your code and it uses it to create what I need. I Don't know how considering it claims it doesn't use think script. But it works. 10 years away from anything useful? I suppose you're protecting your position, but it's obvious this will certainly hurt some jobs. This is probably the toy version of what the military has and I doubt we will ever see that. It took decades for us to see this. Anyway great website here always useful.
 
Watch Tony Zhang of OptionsPlay's video on how to successfully have chatGPT create functional scripts.

90% of the members attempting chatGPT scripting; do not provide good detailed specifications.
Members know what end result that they want but lack the ability to verbalize the step-by-step logic required to code a script to achieve that end result.
This results in chatGPT providing poor code.

The above video, explains the basics of providing good specifications to AI which results in better scripts.
 
Last edited:
I'm trying to use chatgpt to code because I'm illiterate basically when it comes to coding. But If i can get this going that would be amazing and I'll post my VSA code that is working really well. I'm trying to get a tradingview indicator by lonesomeblue consolidation box live to convert:

The script is also capable of identifying three potential directions that the price may move after breaking out of the consolidation zone. These directions are:
  1. Moving outside the consolidation zone above or below the high or low of the consolidation box area and then reversing back the entire distance of the box in the opposite direction.
  2. Moving outside the consolidation zone and continuing to go up with a lot of momentum.
  3. Reversing to the median price point after going up and then coming down.
If the price bounces off the median price line, the script labels the trend direction it will be going with momentum or breaking out. The same goes for when the price does not reverse outside the consolidation box.


input prd = 10;
input conslen = 5;
input paintcons = yes;
input zonecol = color.blue;

def hb_ = highestbars(prd) == 0 ? high : Double.NaN;
def lb_ = lowestbars(prd) == 0 ? low : Double.NaN;
def dir = 0;
def zz = Double.NaN;
def pp = Double.NaN;

dir = if (hb_ and !isNaN(lb_)) then 1
else if (lb_ and !isNaN(hb_)) then -1
else dir;

if (hb_ and lb_) {
if (dir == 1) {
zz = hb_;
} else {
zz = lb_;
}
} else {
zz = if (hb_) then hb_
else if (lb_) then lb_
else Double.NaN;
}

def condhigh = if (dir == 1) then highest(conslen) else Double.NaN;
def condlow = if (dir == -1) then lowest(conslen) else Double.NaN;

def consArea = if (paintcons) then zonecol else color.white;

AddCloud(condhigh, condlow, consArea);

def breakoutup = if high > condhigh and low > condlow then yes else no;
def breakoutdown = if low < condlow and high < condhigh then yes else no;
def upmomentum = if high > condhigh and low <= condhigh then yes else no;
def downmomentum = if low < condlow and high >= condlow then yes else no;

Alert(breakoutup, "Breakout Up", Alert.BAR, Sound.Ding);
Alert(breakoutdown, "Breakout Down", Alert.BAR, Sound.Ding);
Alert(upmomentum, "Up Momentum", Alert.BAR, Sound.Chimes);
Alert(downmomentum, "Down Momentum", Alert.BAR, Sound.Chimes);
 
hello, zero coding experience here. Iasked the bot "divergence for macd" (using the rsi divergence code from here) and this is the code it gives me, but unfortunately, I have to overlay it on the regular macd chart and uncheck the following:

macd
Signal
histogram
overbout
oversold.

if anybody can make it work under one single code, thanks in advance.


declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input Over_Bought = 0.5; #hint Over_Bought: Over Bought line
input Over_Sold = -0.5; #hint Over_Sold: Over Sold line

def MACDLine = ExpAverage(close, fastLength) - ExpAverage(close, slowLength);
def SignalLine = ExpAverage(MACDLine, MACDLength);
def MACDHist = MACDLine - SignalLine;

plot MACD = MACDLine;
plot Signal = SignalLine;
plot Histogram = MACDHist;

MACD.AssignValueColor(if MACDLine > SignalLine then Color.GREEN else Color.RED);
Signal.AssignValueColor(Color.YELLOW);
Histogram.AssignValueColor(if MACDHist > MACDHist[1] then Color.GREEN else Color.RED);

plot OverBought = Over_Bought;
plot OverSold = Over_Sold;

def bar = BarNumber();

def Currh = if MACDLine > OverBought
then fold i = 1 to Floor(MACDLength / 2)
with p = 1
while p
do MACDLine > getValue(MACDLine, -i)
else 0;

def CurrPivotH = if (bar > MACDLength and
MACDLine == highest(MACDLine, Floor(MACDLength/2)) and
Currh)
then MACDLine
else double.NaN;

def Currl = if MACDLine < OverSold
then fold j = 1 to Floor(MACDLength / 2)
with q = 1
while q
do MACDLine < getValue(MACDLine, -j)
else 0;

def CurrPivotL = if (bar > MACDLength and
MACDLine == lowest(MACDLine, Floor(MACDLength/2)) and
Currl)
then MACDLine
else double.NaN;

def CurrPHBar = if !isNaN(CurrPivotH)
then bar
else CurrPHBar[1];

def CurrPLBar = if !isNaN(CurrPivotL)
then bar
else CurrPLBar[1];

def PHpoint = if !isNaN(CurrPivotH)
then CurrPivotH
else PHpoint[1];

def priorPHBar = if PHpoint != PHpoint[1]
then CurrPHBar[1]
else priorPHBar[1];

def PLpoint = if !isNaN(CurrPivotL)
then CurrPivotL
else PLpoint[1];

def priorPLBar = if PLpoint != PLpoint[1]
then CurrPLBar[1]
else priorPLBar[1];

def HighPivots = bar >= highestAll(priorPHBar);
def LowPivots = bar >= highestAll(priorPLBar);

def pivotHigh = if HighPivots
then CurrPivotH
else double.NaN;
plot PlotHline = pivotHigh;

PlotHline.enableApproximation();

PlotHline.SetDefaultColor(GetColor(7));

PlotHline.SetStyle(Curve.Short_DASH);

plot pivotLow = if LowPivots

then CurrPivotL

else double.NaN;

pivotLow.enableApproximation();

pivotLow.SetDefaultColor(GetColor(7));

pivotLow.SetStyle(Curve.Short_DASH);

plot PivotDot = if!isNaN(pivotHigh)
then pivotHigh
else if!isNaN(pivotLow)
then pivotLow
else double.NaN;
pivotDot.SetDefaultColor(GetColor(7));

pivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);

pivotDot.SetLineWeight(3);
 
I'm trying to use chatgpt to code because I'm illiterate basically when it comes to coding. But If i can get this going that would be amazing and I'll post my VSA code that is working really well. I'm trying to get a tradingview indicator by lonesomeblue consolidation box live to convert:

The script is also capable of identifying three potential directions that the price may move after breaking out of the consolidation zone. These directions are:
  1. Moving outside the consolidation zone above or below the high or low of the consolidation box area and then reversing back the entire distance of the box in the opposite direction.
  2. Moving outside the consolidation zone and continuing to go up with a lot of momentum.
  3. Reversing to the median price point after going up and then coming down.
If the price bounces off the median price line, the script labels the trend direction it will be going with momentum or breaking out. The same goes for when the price does not reverse outside the consolidation box.


input prd = 10;
input conslen = 5;
input paintcons = yes;
input zonecol = color.blue;

def hb_ = highestbars(prd) == 0 ? high : Double.NaN;
def lb_ = lowestbars(prd) == 0 ? low : Double.NaN;
def dir = 0;
def zz = Double.NaN;
def pp = Double.NaN;

dir = if (hb_ and !isNaN(lb_)) then 1
else if (lb_ and !isNaN(hb_)) then -1
else dir;

if (hb_ and lb_) {
if (dir == 1) {
zz = hb_;
} else {
zz = lb_;
}
} else {
zz = if (hb_) then hb_
else if (lb_) then lb_
else Double.NaN;
}

def condhigh = if (dir == 1) then highest(conslen) else Double.NaN;
def condlow = if (dir == -1) then lowest(conslen) else Double.NaN;

def consArea = if (paintcons) then zonecol else color.white;

AddCloud(condhigh, condlow, consArea);

def breakoutup = if high > condhigh and low > condlow then yes else no;
def breakoutdown = if low < condlow and high < condhigh then yes else no;
def upmomentum = if high > condhigh and low <= condhigh then yes else no;
def downmomentum = if low < condlow and high >= condlow then yes else no;

Alert(breakoutup, "Breakout Up", Alert.BAR, Sound.Ding);
Alert(breakoutdown, "Breakout Down", Alert.BAR, Sound.Ding);
Alert(upmomentum, "Up Momentum", Alert.BAR, Sound.Chimes);
Alert(downmomentum, "Down Momentum", Alert.BAR, Sound.Chimes);

reply to post89

that's ok if you don't know thinkscript and are trying. just know chatgpt usually creates jibberish.


when asking for a conversion, please post a link to the original.
it helps quite a bit to see a picture of a chart, read about it, and see original code.
if i convert one, i always start with the original code, never with someones pasted in code.
i think this is it?
https://www.tradingview.com/script/xKSqR6P4-Consolidation-Zones-Live/

post code in a code window
click on </> in header.

you removed the header info from the program, that describes who made it and what it is. don't do that. at least you mentioned it in your words.

there are too many errors in that code to attempt to fix it. it seems to be a mixture of thinkscript and pine. almost every line is wrong, so it is likely that it is missing something, so if it was fixed, no guarantee it would be complete.


a few examples,

def hb_ = highestbars(prd) == 0 ? high : Double.NaN;

should be,
def hb_ = if highestbars(prd) == 0 then high else Double.NaN;

can't assign colors to a variable with def,
def consArea = if (paintcons) then zonecol else color.white;
 
Last edited:
ChatGPT seems to be getting better by the day. But no it cant create complex code like you guys. I feed it your code and it uses it to create what I need. I Don't know how considering it claims it doesn't use think script. But it works. 10 years away from anything useful? I suppose you're protecting your position, but it's obvious this will certainly hurt some jobs. This is probably the toy version of what the military has and I doubt we will ever see that. It took decades for us to see this. Anyway great website here always useful.
that's great if it can provide something useful for your project.
i agree, new technology always seems to shift the job market, usually to something more automated related.
my beef with it is, people who don't know any thinkscript are asking it to generate a code, and expect it to work, and it doesn't. i think a tool shouldn't exist until it works.
i have no position to protect. i'm just a guy, doing a hobby. i have random pockets of free time, that i like to use to volunteer on this site, to help out others.
 
Last edited:
that's great if it can provide something useful for your project.
i agree, new technology always seems to shift the job market, usually to something more automated related.
my beef with it is, people who don't know any thinkscript are asking it to generate a code, and expect it to work, and it doesn't. i think a tool shouldn't exist until it works.
i have no position to protect. i'm just a guy, doing a hobby. i have random pockets of free time, that i like to use to volunteer on this site, to help out others.
I meant protecting position is the sense you would feel more passionate about the coding and this field, more so than a person like me. Not necessarily monetarily. I feel it's extracting more info to be used for its own gain of course. It's helping me learn code I would say. One other oddity is sometimes it takes many reiterations of a code before its gets the solution, feeding it the thinkscript errors so it can correct. But sometimes I can request literally in layman's terms what I want to accomplish and it creates it right off the bat without any problems. I also believe the AI is narrative based but can be manipulated to provide an answer in keeping with ones own thinking. It will say one thing but then after interaction with it you can prove your point with its passed answers and cause a correction in its own conclusions. I dont believe at all it thinks. It's garbage in garbage out. This may be stating the obvious, but the whole sentient concept exists IMO for a future where they can blame AI for whatever engineered crisis they have coming next.
 
1. The amazing contributors of the forum provide their expertise gratis; they have "no position" to protect.
2. Historically, technology advances create more, albeit different opportunities.
3. chatGPT will reach a point in the future, where it will be able to create complex scripts.
It will be a matter of garbage-in-garbage-out. Just like on this forum; we and chatGPT will only be able to provide good detailed studies when we are given good detailed specifications.
4. The best ThinkScript sites on the internet are not about the scripts. The good sites provide the support for the scripts and education in their use in trading. So chatGPT will be providing more scripts which will provide opportunity for more discussion which grows the whole ThinkScript community.

@halcyonguy's point is that chatGPT is NOT there yet.
Besides the issues with chatGPT current shortcomings,
90% of the members submitting the chatGPT scripts here; not only do not provide good detailed specifications; they provide no specifications.
This results in frustrations on the part of the members and the contributors.

This is typical. chatGPT still has many growing pains ahead.
I posted another reply to @halcyonguy before I read this one.
First, everyone has a position when interrogated. Im using the term position in the sense of opinion and emotional attachment. I have coffee with retired men they claim no positions, get them talking and they're full of emotion and opinion. 😃
I wouldn't think of submitting chatGPT here and surprised anyone would. I would think that would cause a lot of problems as you mentioned. I do believe it's helping me learn thinkscript and basic coding like me playing on apple 2 e in the early 80s. Little did I know the ramifications of coding, never dreamed of such a thing. I assume we're doing the same with AI right now. Again this is probably the best site I know of and have appreciated the help I received in the past. I think 90 percent of the indicators in some way shape and form are redundant in relationship with what theyre all trying to accomplish and thats because we all have similar ideas expressed in different ways, but the conclusions to those problems are the same. 😂 Im 100percent positive I have contributed to that! Just because we have just enough knowledge to be dangerous!
 
I told Chat GPT to create a thinkscript for me. I entered it on thinkorswim but Its not working. I do not know how to code. Any help will be appreciated.
The message that I receive at the bottom of the screen
No such function: scan at 28:1
No Such function: scan at 28:1
Incompatible parameter: scanCriteria at 25:5

# Scan for stocks that are about to breakout

input length = 20; # Lookback period for the breakout
input threshold = 0.9; # Minimum breakout threshold

def priceHigh = high;
def priceLow = low;
def priceClose = close;

def highestHigh = Highest(priceHigh, length);
def lowestLow = Lowest(priceLow, length);
def priceRange = highestHigh - lowestLow;
def breakoutLevel = priceClose + (priceRange * threshold);

def isBreakout = priceClose > breakoutLevel;

def futureHigh = Highest(priceHigh[1], length);
def futureLow = Lowest(priceLow[1], length);
def futureRange = futureHigh - futureLow;
def breakoutLevelFuture = priceClose[1] + (futureRange * threshold);

def isFutureBreakout = priceClose[1] > breakoutLevelFuture;

# Criteria for the scan
def scanCriteria = isFutureBreakout and !isBreakout;

# Output the scan results
scan(scanCriteria);
 
I told Chat GPT to create a thinkscript for me. I entered it on thinkorswim but Its not working. I do not know how to code. Any help will be appreciated.
The message that I receive at the bottom of the screen
No such function: scan at 28:1
No Such function: scan at 28:1
Incompatible parameter: scanCriteria at 25:5

# Scan for stocks that are about to breakout

input length = 20; # Lookback period for the breakout
input threshold = 0.9; # Minimum breakout threshold

def priceHigh = high;
def priceLow = low;
def priceClose = close;

def highestHigh = Highest(priceHigh, length);
def lowestLow = Lowest(priceLow, length);
def priceRange = highestHigh - lowestLow;
def breakoutLevel = priceClose + (priceRange * threshold);

def isBreakout = priceClose > breakoutLevel;

def futureHigh = Highest(priceHigh[1], length);
def futureLow = Lowest(priceLow[1], length);
def futureRange = futureHigh - futureLow;
def breakoutLevelFuture = priceClose[1] + (futureRange * threshold);

def isFutureBreakout = priceClose[1] > breakoutLevelFuture;

# Criteria for the scan
def scanCriteria = isFutureBreakout and !isBreakout;

# Output the scan results
scan(scanCriteria);

hello and welcome,

when asking strangers for help,
describe the problem, what is the question? what are you trying to do?

where do you want to see something?
chart, list, scan,...

what do you want to see?

----------
when posting code,
paste it in a code window.
click on </> in the header.

------

my guess

change last line, from this
scan(scanCriteria);

to this
plot z = scanCriteria;
 
hello and welcome,

when asking strangers for help,
describe the problem, what is the question? what are you trying to do?

where do you want to see something?
chart, list, scan,...

what do you want to see?

----------
when posting code,
paste it in a code window.
click on </> in the header.

------

my guess

change last line, from this
scan(scanCriteria);

to this
plot z = scanCriteria;
Thanks for the input. It totally helped.
It was supposed to be scan to look for stocks prior to breaking out. I have no idea how to code.
Thanks for helping me out with the issue.
 
hello and welcome,

when asking strangers for help,
describe the problem, what is the question? what are you trying to do?

where do you want to see something?
chart, list, scan,...

what do you want to see?

----------
when posting code,
paste it in a code window.
click on </> in the header.

------

my guess

change last line, from this
scan(scanCriteria);

to this
plot z = scanCriteria;

I have another thinkscript assistance. It is scan to identify intraday breakouts. The error message that I receive is "No Such function: scan at 20:1" and "No such variable: stock at 20:75". Here is the thinkscript posted below

# Intraday Breakout Scan

# Define input parameters
input priceType = close;
input timeFrame = AggregationPeriod.FIVE_MIN;
input lookBack = 20;
input percentThreshold = 1;

# Calculate the high and low prices for the lookback period
def highPrice = highest(priceType, lookBack);
def lowPrice = lowest(priceType, lookBack);

# Calculate the percent change from the low to the high price
def percentChange = ((highPrice - lowPrice) / lowPrice) * 100;

# Define the scan criteria
def scanCriteria = percentChange >= percentThreshold;

# Run the scan and display the results
scan(scanCriteria, "Intraday Breakout " + percentThreshold + "%", stock = stock);
 
I have another thinkscript assistance. It is scan to identify intraday breakouts. The error message that I receive is "No Such function: scan at 20:1" and "No such variable: stock at 20:75". Here is the thinkscript posted below

# Intraday Breakout Scan

# Define input parameters
input priceType = close;
input timeFrame = AggregationPeriod.FIVE_MIN;
input lookBack = 20;
input percentThreshold = 1;

# Calculate the high and low prices for the lookback period
def highPrice = highest(priceType, lookBack);
def lowPrice = lowest(priceType, lookBack);

# Calculate the percent change from the low to the high price
def percentChange = ((highPrice - lowPrice) / lowPrice) * 100;

# Define the scan criteria
def scanCriteria = percentChange >= percentThreshold;

# Run the scan and display the results
scan(scanCriteria, "Intraday Breakout " + percentThreshold + "%", stock = stock);
reply to 98

same answer as before,
no function called scan exists
variable 'stock' was not defined

if the error message says something like function doesn't exist, you can go here and search for it, and verify if it exists or not. in this case, scan() doesn't exist,
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions

so your next guess/search would be
google how to use thinkscript to generate scan output

------------

a scan code wants to end with 1 plot , that will equal a formula that will have a true or false value

--------------

change def to plot,
change this ,
def scanCriteria = percentChange >= percentThreshold;

to this,
plot scanCriteria = percentChange >= percentThreshold;


delete last 2 lines,
# Run the scan and display the results
scan(scanCriteria, "Intraday Breakout " + percentThreshold + "%", stock = stock);
 
Hello,

messing around with Chat GPT and ThinkScript and just seeing what it can do. Having an issue with this if statement on line 60 under "# Reset the trend change flag". I've only just made this, haven't backtested anything yet, just seeing what GPT can do, don't take this and think it is going to be any kind of successful.

Code:
# Define the input variables
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input emaPeriod = 9;
input rsiPeriod = 14;
input vwapLength = 20;

# Define the MACD line
def MACDLine = MACD(fastLength, slowLength, MACDLength).Diff;

# Define the MACD signal line
def SignalLine = MACD(fastLength, slowLength, MACDLength).Avg;

# Define the MACD histogram
def Histogram = MACDLine - SignalLine;

# Define the 9EMA
def EMA9 = ExpAverage(close, emaPeriod);

# Define the RSI
input rsiPeriod = 14;
def RSIValue = RSI(close, rsiPeriod);

# Define the aggregation period for VWAP
def AggregationPeriod = AggregationPeriod.DAY;
# Define the VWAP
def VWAPValue = VWAP;

# Define the CCI
input cciPeriod = 14;
def CCIValue = CCI(cciPeriod);

# Define the trend direction
def Trend = if close > EMA9 then 1 else if close < EMA9 then -1 else 0;

# Initialize the trend change flag
def TrendChanged = 0;

# Determine if the trend has changed
def TrendChanged = if Trend != Trend[1] then 1 else 0;

# Define the conditions for a buy signal
def BuySignal = MACDLine > SignalLine and Histogram > 0 and close > EMA9 and RSIValue > 50 and close > VWAPValue and CCIValue > 0;

# Define the conditions for a sell signal
def SellSignal = MACDLine < SignalLine and Histogram < 0 and close < EMA9 and RSIValue < 50 and close < VWAPValue and CCIValue < 0;

# Determine if a signal should be generated
def Signal = if BuySignal and Trend > 0 and TrendChanged == 1 then 1 else if SellSignal and Trend < 0 and TrendChanged == 1 then -1 else 0;

# Update the trend direction
def NewTrend = if Signal == 1 then 1 else if Signal == -1 then -1 else Trend;
Trend = NewTrend;

# Determine if the trend has changed
def TrendChanged = if highest(Trend, TrendPeriod) != lowest(Trend, TrendPeriod) then 1 else 0;

# Reset the trend change flag
if Trend == Trend[1] {
    TrendChanged := 0;
}


# Plot a green arrow for a buy signal and a red arrow for a sell signal
plot BuySignalArrow = if Signal == 1 then low - 5 else Double.NaN;
BuySignalArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySignalArrow.SetDefaultColor(Color.GREEN);

plot SellSignalArrow = if Signal == -1 then high + 5 else Double.NaN;
SellSignalArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSignalArrow.SetDefaultColor(Color.RED);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
337 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top