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 creating non-working garbage 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:
ALL working hard to build a "Short squeeze indicator for the watchlist." Having a hard time coding this. Would appreciate any help.
See code below:
Code:
# === Short Squeeze Status Indicator (ORB-Style Framework) ===

def o = open;
def h = high;
def l = low;
def c = close;
def x = BarNumber();
def v = volume;

# — Float Proxy —
def liquidity = if volume > 0 then ((close * volume) / 1_000_000) else Double.NaN;
def isLowFloat = liquidity < 15;

# — Float Rotation Proxy —
def rotationScore = if liquidityProxy > 0 and (v / liquidityProxy) >= 1 then 1 else 0;

# — Momentum / Volume Filters —
def aboveVWAP = c > VWAP();
def rsiMomentum = RSI() > 60 and RSI()[1] < 40;
def volumeSurge = v > Average(v, 30) * 2;
def breakout = c > Highest(h, 10);

# — Composite Short Squeeze Score (0–5) —
def squeezeScore =
(isLowFloat ? 1 : 0) +
(rotationScore) +
(aboveVWAP ? 1 : 0) +
(rsiMomentum ? 1 : 0) +
(volumeSurge ? 1 : 0);

# — Time-Based Flag: First 30 Minutes —
def Active = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
GetTime() <= RegularTradingStart(GetYYYYMMDD()) + AggregationPeriod.Thirty_Min;

# — First 30-Min High/Low Capture —
def hh = if Active and !Active[1] then h
else if Active and h > hh[1] then h
else hh[1];

def ll = if Active and !Active[1] then l
else if Active and l < ll[1] then l
else ll[1];

# — Breakout Directional Status —
def current = if Between(c, ll, hh) then 0
else if c > hh then 1
else if c < ll then -1
else Double.NaN;

# — Label: Squeeze Score + Breakout Status —
AddLabel(1,
"Squeeze Score: " + squeezeScore + "/5 | " +
(if current == 0 then "In Range"
else if current == 1 then "Breakout ↑"
else if current == -1 then "Breakout ↓"
else "N/A"),
if squeezeScore >= 4 then Color.RED
else if squeezeScore >= 2 then Color.ORANGE
else Color.GRAY);

# — Background Color —
AssignBackgroundColor(
if squeezeScore >= 4 then CreateColor(255, 0, 0)
else if squeezeScore >= 2 then CreateColor(255, 140, 0)
else CreateColor(80, 80, 80));
 
Last edited by a moderator:
ALL working hard to build a "Short squeeze indicator for the watchlist." Having a hard time coding this. Would appreciate any help.
See code below:
Code:
# === Short Squeeze Status Indicator (ORB-Style Framework) ===

def o = open;
def h = high;
def l = low;
def c = close;
def x = BarNumber();
def v = volume;

# — Float Proxy —
def liquidity = if volume > 0 then ((close * volume) / 1_000_000) else Double.NaN;
def isLowFloat = liquidity < 15;

# — Float Rotation Proxy —
def rotationScore = if liquidityProxy > 0 and (v / liquidityProxy) >= 1 then 1 else 0;

# — Momentum / Volume Filters —
def aboveVWAP = c > VWAP();
def rsiMomentum = RSI() > 60 and RSI()[1] < 40;
def volumeSurge = v > Average(v, 30) * 2;
def breakout = c > Highest(h, 10);

# — Composite Short Squeeze Score (0–5) —
def squeezeScore =
(isLowFloat ? 1 : 0) +
(rotationScore) +
(aboveVWAP ? 1 : 0) +
(rsiMomentum ? 1 : 0) +
(volumeSurge ? 1 : 0);

# — Time-Based Flag: First 30 Minutes —
def Active = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
GetTime() <= RegularTradingStart(GetYYYYMMDD()) + AggregationPeriod.Thirty_Min;

# — First 30-Min High/Low Capture —
def hh = if Active and !Active[1] then h
else if Active and h > hh[1] then h
else hh[1];

def ll = if Active and !Active[1] then l
else if Active and l < ll[1] then l
else ll[1];

# — Breakout Directional Status —
def current = if Between(c, ll, hh) then 0
else if c > hh then 1
else if c < ll then -1
else Double.NaN;

# — Label: Squeeze Score + Breakout Status —
AddLabel(1,
"Squeeze Score: " + squeezeScore + "/5 | " +
(if current == 0 then "In Range"
else if current == 1 then "Breakout ↑"
else if current == -1 then "Breakout ↓"
else "N/A"),
if squeezeScore >= 4 then Color.RED
else if squeezeScore >= 2 then Color.ORANGE
else Color.GRAY);

# — Background Color —
AssignBackgroundColor(
if squeezeScore >= 4 then CreateColor(255, 0, 0)
else if squeezeScore >= 2 then CreateColor(255, 140, 0)
else CreateColor(80, 80, 80));

reply to 421

next time describe what you want to see.
you told us nothing, just 'this' doesn't work


liquidityProxy doesn't exist. change it to liquidity
def rotationScore = if liquidityProxy > 0 and (v / liquidityProxy) >= 1 then 1 else 0;


fix def squeezeScore = formula
it had pinescript code


fix formula , def liquidity = . 1_000_000 isn't a number


i always start with making a chart study. then when it works, i change it into a column study.
experiment with this.
i made this into a lower study.
disable the AssignBackgroundColor( ) and add a label to show what the squeezeScore number is

Code:
#chat421_sqz_col

#JohnWick4
#7/25
#421

#ALL working hard to build a "Short squeeze indicator for the watchlist." Having a hard time coding this. Would appreciate any help.

# === Short Squeeze Status Indicator (ORB-Style Framework) ===

declare lower;

def o = open;
def h = high;
def l = low;
def c = close;
def x = BarNumber();
def v = volume;

# — Float Proxy —
def liquidity = if volume > 0 then ((close * volume) / 1000000) else Double.NaN;
def isLowFloat = liquidity < 15;

# — Float Rotation Proxy —
#def rotationScore = if liquidityProxy > 0 and (v / liquidityProxy) >= 1 then 1 else 0;
def rotationScore = if liquidity > 0 and (v / liquidity) >= 1 then 1 else 0;


# — Momentum / Volume Filters —
def aboveVWAP = c > vwap();
def rsiMomentum = RSI() > 60 and RSI()[1] < 40;
def volumeSurge = v > Average(v, 30) * 2;
def breakout = c > Highest(h, 10);

# — Composite Short Squeeze Score (0–5) —
#def squeezeScore =
#(isLowFloat ? 1 : 0) +
#(rotationScore) +
#(aboveVWAP ? 1 : 0) +
#(rsiMomentum ? 1 : 0) +
#(volumeSurge ? 1 : 0);

def squeezeScore = isLowFloat +
rotationScore +
aboveVWAP +
rsiMomentum +
volumeSurge;


# — Time-Based Flag: First 30 Minutes —
def Active = GetTime() >= RegularTradingStart(GetYYYYMMDD()) and
GetTime() <= RegularTradingStart(GetYYYYMMDD()) + AggregationPeriod.THIRTY_MIN;

# — First 30-Min High/Low Capture —
def hh = if Active and !Active[1] then h
else if Active and h > hh[1] then h
else hh[1];

def ll = if Active and !Active[1] then l
else if Active and l < ll[1] then l
else ll[1];

# — Breakout Directional Status —
def current = if Between(c, ll, hh) then 0
else if c > hh then 1
else if c < ll then -1
else Double.NaN;

# — Label: Squeeze Score + Breakout Status —
AddLabel(1,
"Squeeze Score: " + squeezeScore + "/5 | " +
(if current == 0 then "In Range"
else if current == 1 then "Breakout ↑"
else if current == -1 then "Breakout ↓"
else "N/A"),
if squeezeScore >= 4 then Color.RED
else if squeezeScore >= 2 then Color.ORANGE
else Color.GRAY);

# — Background Color —
#AssignBackgroundColor(
#if squeezeScore >= 4 then CreateColor(255, 0, 0)
#else if squeezeScore >= 2 then CreateColor(255, 140, 0)
#else CreateColor(80, 80, 80));


addlabel(1, "      " + squeezeScore + "         ",
if squeezeScore >= 4 then CreateColor(255, 0, 0)
else if squeezeScore >= 2 then CreateColor(255, 140, 0)
else CreateColor(80, 80, 80));
#
 
I've used several AI to assist with a code for a label but it keeps giving me the incorrect value. I'm trying to write a code for a label that displays the value for 5000 divided by the high of the second bar of the day plus one. It must be the second bar of the current day and it should work on all intraday time frames including custom time frames. I keep getting a code similar to the one below but none of them have worked. Any assistance would be greatly appreciated.

def newDay = GetDay() <> GetDay()[1];
def barNumber = if newDay then 1 else barNumber[1] + 1;

def secondBarHigh = if barNumber == 2 then high else secondBarHigh[1];

def isToday = GetDay() == GetLastDay();

def ratio = if isToday and !IsNaN(secondBarHigh) then 5000 / (secondBarHigh + 1) else Double.NaN;

AddLabel(isToday and !IsNaN(secondBarHigh), "5000/(2nd Bar High+1): " + Round(ratio, 2), Color.GREEN);
 
I've used several AI to assist with a code for a label but it keeps giving me the incorrect value. I'm trying to write a code for a label that displays the value for 5000 divided by the high of the second bar of the day plus one. It must be the second bar of the current day and it should work on all intraday time frames including custom time frames. I keep getting a code similar to the one below but none of them have worked. Any assistance would be greatly appreciated.

def newDay = GetDay() <> GetDay()[1];
def barNumber = if newDay then 1 else barNumber[1] + 1;

def secondBarHigh = if barNumber == 2 then high else secondBarHigh[1];

def isToday = GetDay() == GetLastDay();

def ratio = if isToday and !IsNaN(secondBarHigh) then 5000 / (secondBarHigh + 1) else Double.NaN;

AddLabel(isToday and !IsNaN(secondBarHigh), "5000/(2nd Bar High+1): " + Round(ratio, 2), Color.GREEN);

this calcs a number , so.... it works

saying something 'doesn't work' , is useless.
tell us what you expected and what you saw.
tell us a real world example,
.. the high of a 2nd bar
.. what stock
.. time frame


why +1? is it adding 1 at the correct place in the formula?


it is a bad idea to use variable names the same as function names. sometimes strange things happen.
barnumber is used
#https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Others/BarNumber


my version to help you debug it. , as a lower, with,
.. the count variable changed,
.. a bubble added to show values,
.. a line plotted of the 2nd bar high.

Code:
declare lower;

# label, 
# (5000 / high of the second bar of the day + 1)


def newDay = GetDay() <> GetDay()[1];
def barcnt = if newDay then 1 else barcnt[1] + 1;

def secondBarHigh = if barcnt == 2 then high else secondBarHigh[1];

def isToday = GetDay() == GetLastDay();

def ratio = if isToday and !IsNaN(secondBarHigh) then 5000 / (secondBarHigh + 1) else Double.NaN;
#def ratio = if isToday then (5000 / (secondBarHigh + 1)) else Double.NaN;

AddLabel(isToday and !IsNaN(secondBarHigh), "5000/(2nd Bar High+1): " + Round(ratio, 2), Color.GREEN);


plot z = secondBarHigh;

addchartbubble(1, low,
barcnt + "\n" +
high + "\n" +
secondBarHigh 
, color.yellow, no);
#
 

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
298 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