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:

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

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);
#
 
Good evening @SleepyZ, I am trying to replicate the indicator in the first photo, from what I could find out the logic of the indicator is that it uses the wick theory, as a starting point I used the MTF candle script from the community that was shared in this post https://usethinkscript.com/threads/multi-timeframe-candles-overlay-for-thinkorswim.1425/post-153504. Then with the help of chatGPT I tried to replicate the buy and sell labels, I copied the photos they shared and, put comments on them to be able to help create the script, but I have reached a point where I can not advance further with chatGPT, since I am not a programmer I hope that with your help I can replicate the indicator. As you can see, the original indicator showed the buy label when a candle opens on or above the cyan line, then it doesn't show again, as this could mean that the price is trending. From what I've seen in the photos, it only shows the sell label until a candle closes below the cyan line (the cyan line is the opening price of the MTF candle, in this case a 30-minute candle on a 5-minute candle chart. The red line is the closing price, and the white line is 50% of the body of the previous MTF candle). I'll copy the script that I was trying to create with ChatGPT. Thank you very much in advance for your help. I would paste some other pictures showing the buy and sell labels of the indicator, maybe that could help.

Screenshot 2025-08-08 141700.png


script created with the help of ChatGPT

Screenshot 2025-08-08 141949.png


input HTF = AggregationPeriod.THIRTY_MIN;
input ShowWicks = no;
input ShowMidline = yes;
input ShowOpenLine = yes;
input ShowCloseLine = yes;



def h = high(period = HTF);
def l = low(period = HTF);
def o = open(period = HTF);
def c = close(period = HTF);

def isBullish = c >= o;
def isBearish = c < o;
def valid = !IsNaN(h) and !IsNaN(l);

# Detect start of new HTF candle when open or close changes
def newCandle = (o != o[1]) or (c != c[1]);

# Cumulative candle count increments only on new candle
rec candleCount = if newCandle then candleCount[1] + 1 else candleCount[1];

# Alternate toggle for colors based on candleCount
def altToggle = candleCount % 2 == 0;

# === WICKS (Optional) ===
AddCloud(
if ShowWicks and valid and altToggle then h else Double.NaN,
if ShowWicks and valid and altToggle then l else Double.NaN,
Color.GRAY, Color.GRAY
);
AddCloud(
if ShowWicks and valid and !altToggle then h else Double.NaN,
if ShowWicks and valid and !altToggle then l else Double.NaN,
Color.DARK_GRAY, Color.DARK_GRAY
);

# === BODY BOXES ===
AddCloud(
if valid and isBullish and altToggle then c else Double.NaN,
if valid and isBullish and altToggle then o else Double.NaN,
Color.LIGHT_GREEN, Color.LIGHT_GREEN
);
AddCloud(
if valid and isBullish and !altToggle then c else Double.NaN,
if valid and isBullish and !altToggle then o else Double.NaN,
Color.LIGHT_GREEN, Color.LIGHT_GREEN
);
AddCloud(
if valid and isBearish and altToggle then o else Double.NaN,
if valid and isBearish and altToggle then c else Double.NaN,
Color.PINK, Color.PINK
);
AddCloud(
if valid and isBearish and !altToggle then o else Double.NaN,
if valid and isBearish and !altToggle then c else Double.NaN,
Color.PINK, Color.PINK
);

# === PREVIOUS MIDLINE (Flat through NEXT HTF candle only) ===
rec prevOpen = if newCandle then o[1] else prevOpen[1];
rec prevClose = if newCandle then c[1] else prevClose[1];
rec prevMid = if newCandle then (o[1] + c[1]) / 2 else prevMid[1];
def showMid = candleCount != candleCount[1];

plot Mid = if ShowMidline and showMid then prevMid else Double.NaN;
Mid.SetDefaultColor(Color.WHITE);
Mid.SetPaintingStrategy(PaintingStrategy.DASHES);
Mid.SetLineWeight(1);

# === OPEN LINE during HTF candle ===
def showOpen = valid;
plot OpenLine = if ShowOpenLine and showOpen then o else Double.NaN;
OpenLine.SetDefaultColor(Color.CYAN);
OpenLine.SetPaintingStrategy(PaintingStrategy.DASHES);
OpenLine.SetLineWeight(1);

# === CLOSE LINE during HTF candle ===
def showClose = valid;
plot CloseLine = if ShowCloseLine and showClose then c else Double.NaN;
CloseLine.SetDefaultColor(Color.LIGHT_RED);
CloseLine.SetPaintingStrategy(PaintingStrategy.DASHES);
CloseLine.SetLineWeight(1);

# Wick Theory MTF Buy/Sell Signals - FINAL FIXED VERSION

input showBuy = yes;
input showSell = yes;

def na = Double.NaN;

# === MTF Structure ===
def htfOpen = open(period = htf);
def isNewHTF = htfOpen != htfOpen[1];
def barCount = if isNewHTF then 1 else barCount[1] + 1;

# Cyan dashed MTF open line
#plot HTFOpenLine = if !IsNaN(close) then htfOpen else na;
#HTFOpenLine.SetDefaultColor(Color.CYAN);
#HTFOpenLine.SetStyle(Curve.SHORT_DASH);

# === Candle Conditions ===
def isGreen = close > open;
def isRed = close < open;
def opensAtOrAbove = open >= htfOpen;
def closesAbove = close > htfOpen;
def closesBelow = close < htfOpen;
def validBuyBar = barCount == 1 or barCount == 5;

# === Raw Signal Conditions ===
def rawBuySignal = isGreen and opensAtOrAbove and closesAbove and validBuyBar;
def rawSellSignal = isRed and opensAtOrAbove and closesBelow;

# === Track persistent Buy state across boxes
def hasAnyBuyOccurred = if isNewHTF then rawBuySignal or hasAnyBuyOccurred[1] else hasAnyBuyOccurred[1] or rawBuySignal;

# === Buy Trigger (this box only)
def buyTriggeredThisBox = if isNewHTF then 0
else if rawBuySignal and buyTriggeredThisBox[1] == 0 then 1
else buyTriggeredThisBox[1];

# === Sell Trigger (this box only), defined after all dependencies
def sellTriggeredThisBox = if isNewHTF then 0
else if rawSellSignal and hasAnyBuyOccurred and sellTriggeredThisBox[1] == 0 then 1
else sellTriggeredThisBox[1];

# === Final Buy Plot (only if no sell has occurred in current box)
plot BuyArrow = if showBuy and rawBuySignal and buyTriggeredThisBox[1] == 0 and sellTriggeredThisBox[1] == 0
then low - TickSize() * 2 else na;
BuyArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuyArrow.SetDefaultColor(Color.GREEN);
BuyArrow.SetLineWeight(2);

AddChartBubble(
showBuy and !IsNaN(BuyArrow),
BuyArrow,
"Buy-" + AsText(close, NumberFormat.TWO_DECIMAL_PLACES),
Color.GREEN,
no
);

# === Final Sell Plot (after any prior buy across boxes)
plot SellArrow = if showSell and rawSellSignal and hasAnyBuyOccurred and sellTriggeredThisBox[1] == 0
then high + TickSize() * 2 else na;
SellArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellArrow.SetDefaultColor(Color.MAGENTA);
SellArrow.SetLineWeight(2);

AddChartBubble(
showSell and !IsNaN(SellArrow),
SellArrow,
"Sell-" + AsText(close, NumberFormat.TWO_DECIMAL_PLACES),
Color.MAGENTA,
yes
);
 

Attachments

  • Screenshot 2025-08-04 222153.png
    Screenshot 2025-08-04 222153.png
    84 KB · Views: 17
  • Screenshot 2025-08-04 214636.png
    Screenshot 2025-08-04 214636.png
    114.2 KB · Views: 19
  • Screenshot 2025-08-04 211527.png
    Screenshot 2025-08-04 211527.png
    63.5 KB · Views: 18
  • Screenshot 2025-08-04 222153.png
    Screenshot 2025-08-04 222153.png
    84 KB · Views: 17
  • Screenshot 2025-08-04 211527.png
    Screenshot 2025-08-04 211527.png
    63.5 KB · Views: 16
  • Screenshot 2025-08-04 211436.png
    Screenshot 2025-08-04 211436.png
    54.4 KB · Views: 17
  • Screenshot 2025-08-04 210803.png
    Screenshot 2025-08-04 210803.png
    61.6 KB · Views: 17
  • Screenshot 2025-08-01 234553.png
    Screenshot 2025-08-01 234553.png
    286.2 KB · Views: 18
  • Screenshot 2025-08-10 224327.png
    Screenshot 2025-08-10 224327.png
    128.5 KB · Views: 7
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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