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 Have a failed CH GPT failed script I would like help on for a scan
# Define the scan
# Weighted matrix of indicators
def weight_PS = 1;
def weight_PB = 2;
def weight_DIV_YIELD = 3;
def weight_ROE = 6;
def weight_EARNINGS_GROWTH = 5;
def weight_DEBT_TO_EQUITY = 3;
def weight_FCF = 3;
def weight_OPERATING_MARGIN = 4;
def weight_P_OCF = 2;
def weight_MARKET_CAP = 5;

# Calculate weighted score for each stock
def weighted_score = weight_PS * Fundamental(priceType = PriceType.SALES) +
weight_PB * Fundamental(priceType = PriceType.BOOK_VALUE_PER_SHARE) +
weight_DIV_YIELD * Fundamental(priceType = PriceType.DIVIDEND_YIELD) +
weight_ROE * Fundamental(priceType = PriceType.RETURN_ON_EQUITY) +
weight_EARNINGS_GROWTH * Fundamental(priceType = PriceType.EARNINGS_GROWTH_RATE) +
weight_DEBT_TO_EQUITY * Fundamental(priceType = PriceType.DEBT_TO_EQUITY) +
weight_FCF * Fundamental(priceType = PriceType.FREE_CASH_FLOW) +
weight_OPERATING_MARGIN * Fundamental(priceType = PriceType.OPERATING_MARGIN) +
weight_P_OCF * Fundamental(priceType = PriceType.PRICE_TO_OPERATING_CASH_FLOW) +
weight_MARKET_CAP * Fundamental(priceType = PriceType.MARKET_CAPITALIZATION);

# Scan condition for highest weighted score
plot scan_condition = weighted_score > Highest(weighted_score, 34);

reply to #238?? , original deleted ?

all of your pricetypes are wrong
pricetype can be only , Last, Ask, Bid, or Mark
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Fundamental

fundamental doesn't have the data you are looking for
https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/FundamentalType

take a look at these label and see if any of them are what you are looking for
https://usethinkscript.com/threads/financial-fundamentals-labels-for-thinkorswim.5308/
 
Last edited:
Please help me find the error in this code. Thank you.
Goal of the code is to Scan for a Moving Average crossing above another moving average AFTER A SPECIFIED NUMBER OF DAYS (BARS)

# User inputs
input fastLength = 8;
input slowLength = 20;
input crossPeriod = 20;

# Calculate moving averages
def fastEMA = ExpAverage(close, fastLength);
def slowEMA = ExpAverage(close, slowLength);

# Check for crossover and if fastEMA has been below slowEMA for at least 5 days
def belowSlowEMA = fastEMA < slowEMA;
def belowSlowEMAPeriod = Sum(belowSlowEMA, crossPeriod) == crossPeriod;
def cross = if (fastEMA > slowEMA and belowSlowEMAPeriod) then 1 else 0;

# Plot the crossover signal
plot scanSignal = cross;

reply to #240
the cross = line is wrong,
it should be looking at the previous value of belowSlowEMAPeriod, not the current value.
i added an offset to read a value from 1 bar ago.

replace your code line with this one,
def cross = if (fastEMA > slowEMA and belowSlowEMAPeriod[1] ) then 1 else 0;
 
Hey guys i'm new here and not a coder by any means, but will appreciate very much if somebody helps me in this.

I would like to build a scan in ToS for at least 3 consistant bar close higher than Upper Bollinger band
to show me intraday overextended stocks like DELL on 04/04/2024
dell chart 04-04-2024.png
and CZOO on 04/24/2024
czoo 04-24-2024.png
When addressing this problem to ChatGPT it provided me with a code that don't work and idk why. The scan criteria are basically simple:

1. Stock should be above upper bollinger band intraday on 2-min chart.
2. Chart must have at least 3 consecutive 2min candles above Upper BB that closed higher one after previous ( so close of candle 3 > close of candle 2 > close of candle 1) and at least 3 consecutive 2min candles which lows are higher than previous two candles (low of candle3> low of candle2> low of candle1)

Below is the code that ChatGPT provided:
Code:
# Define variables
input length = 20;
input numCandles = 3;

# Calculate Bollinger Bands
def price = close;
def SD = StDev(price, length);
def upperBand = BollingerBands(price, length, 2.0, 2.0).UpperBand;

# Check condition
def aboveUpperBand = close > upperBand;

# Count consecutive candles above upper band
def count = if aboveUpperBand then count[1] + 1 else 0;

# Condition for scan
def signal = count >= numCandles;

# Output
plot scan = signal;

Any help or afdvice will be highly appreciated.
 
Last edited by a moderator:
Lines at the last 3 highest volume vwap level within the last 52 weeks.
This is what i got from ChatGPT. Price is shown but no line is drawn on the chart. This is for just one line for the last highest vwap level.. I need it to draw 3 lines for the last 3 highest vwap level, add a number on each line in ascending order. Thank you for any help.



input lookbackPeriod = 52; # Lookback period in weeks

# Calculate the number of bars in the lookback period
def barsInPeriod = lookbackPeriod * 5;

# Find the highest volume day within the lookback period
def highestVolumeDay = Highest(volume, barsInPeriod);

# Calculate VWAP for the highest volume day
def vwapHighestVolumeDay = if volume == highestVolumeDay then reference VWAP() else Double.NaN;

# Plot horizontal line at the VWAP level of the highest volume day
plot VWAPLine = if !IsNaN(vwapHighestVolumeDay) then vwapHighestVolumeDay else Double.NaN;
VWAPLine.SetDefaultColor(Color.BLUE);
VWAPLine.SetLineWeight(1);
reply to #241
on each bar, this finds the 3 highest volumes, in the past x bars. then finds a VWAP for those 3 volume bars, and draws 3 lines.

Code:
#chat241_3hi_vwap_lines

#https://usethinkscript.com/threads/chatgpt-bard-other-ai-scripts-which-cant-be-used-in-thinkorswim.13822/page-13#post-140670
#elborsagy  #241
#Lines at the last 3 highest volume vwap level within the last 52 weeks.

def na = double.nan;
def bn = barnumber();
def m = 1000000;
def rnd = 2;

input lookbackPeriod = 52; # Lookback period in weeks

# Calculate the number of bars in the lookback period
def barsInPeriod = lookbackPeriod * 5;

# Find the highest volume day within the lookback period
def v1 = volume;
def v1hi = Highest(v1, barsInPeriod);

def v2hi = fold i = 0 to barsInPeriod
  with m2
  do if v1hi > GetValue(v1, i) then max(GetValue(v1, i), m2) else m2;

def v3hi = fold j = 0 to barsInPeriod
  with m3
  do if v2hi > GetValue(v1, j) then max(GetValue(v1, j), m3) else m3;


# Calculate VWAP for the highest volume day
def vwapHi1Vol = if bn == 1 then na
 else if v1 == v1hi then reference VWAP()
 else vwapHi1Vol[1];
plot VWAP1 = vwapHi1Vol;
VWAP1.SetDefaultColor(Color.BLUE);
VWAP1.SetLineWeight(1);
vwap1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# Calculate VWAP for the 2nd highest volume day
def vwapHi2Vol = if bn == 1 then na
 else if v1 == v2hi then reference VWAP()
 else vwapHi2Vol[1];
plot VWAP2 = vwapHi2Vol;
VWAP2.SetDefaultColor(Color.BLUE);
VWAP2.SetLineWeight(1);
vwap2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# Calculate VWAP for the 3rd highest volume day
def vwapHi3Vol = if bn == 1 then na
 else if v1 == v3hi then reference VWAP()
 else vwapHi3Vol[1];
plot VWAP3 = vwapHi3Vol;
VWAP3.SetDefaultColor(Color.BLUE);
VWAP3.SetLineWeight(1);
vwap3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

#---------------------

# test stuff
def vr1 = round(v1/m, rnd);
def vr1hi = round(v1hi/m, rnd);
def vr2hi = round(v2hi/m, rnd);
def vr3hi = round(v3hi/m, rnd);

def x = (!isnan(close[-(barsInPeriod-1)]) and isnan(close[-(barsInPeriod)]));
addverticalline(x, "-",color.cyan);

addchartbubble(0, low*0.999,
 bn + "\n" +
 vr1 + "  \n" +
 " " + "\n" +
 vr1hi + " 1\n" +
 vr2hi + " 2\n" +
 vr3hi + " 3\n"
, color.yellow, no);

#addlabel(1, "len " +  barsInPeriod, color.cyan);
#


----------------------------
here is a volume study for testing
it displays the volume number, in millions, above the bars
Code:
#vol_nums
def v = volume;
def m = 1000000;
def rnd = 2;
def vr1 = round(v/m, rnd);
addchartbubble(1, v, vr1, color.yellow, yes);
 
Hey guys i'm new here and not a coder by any means, but will appreciate very much if somebody helps me in this.

I would like to build a scan in ToS for at least 3 consistant bar close higher than Upper Bollinger band
to show me intraday overextended stocks like DELL on 04/04/2024 View attachment 21700and CZOO on 04/24/2024 View attachment 21701When addressing this problem to ChatGPT it provided me with a code that don't work and idk why. The scan criteria are basically simple:

1. Stock should be above upper bollinger band intraday on 2-min chart.
2. Chart must have at least 3 consecutive 2min candles above Upper BB that closed higher one after previous ( so close of candle 3 > close of candle 2 > close of candle 1) and at least 3 consecutive 2min candles which lows are higher than previous two candles (low of candle3> low of candle2> low of candle1)

Below is the code that ChatGPT provided:
Code:
# Define variables
input length = 20;
input numCandles = 3;

# Calculate Bollinger Bands
def price = close;
def SD = StDev(price, length);
def upperBand = BollingerBands(price, length, 2.0, 2.0).UpperBand;

# Check condition
def aboveUpperBand = close > upperBand;

# Count consecutive candles above upper band
def count = if aboveUpperBand then count[1] + 1 else 0;

# Condition for scan
def signal = count >= numCandles;

# Output
plot scan = signal;

Any help or afdvice will be highly appreciated.

reply to 244
that is surprisingly close, coming from chatgpt.

it is missing the displace input parameter for BollingerBands.
because of this, the length 20 is applied as the displace (sideways shift), instead of 0.
then 2 is used as length, instead of 20.

replace this,
def upperBand = BollingerBands(price, length, 2.0, 2.0).UpperBand;

with this
def upperBand = BollingerBands(price, 0, length, 2.0, 2.0).UpperBand;
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
421 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