The Use of AI with ThinkOrSwim Scripts

I’ve been creating financial dashboard models and scripts, and from my experience, one LLM is never enough if you care about accuracy, logic, and security.

AI can help a lot, but I would not trust one model by itself. I set up a loop or bridge so one model builds or reviews the script, then another model checks it against the goal, logic, errors, and possible security issues.

For example, if I use Claude or Claude Code to build something, I’ll run it through ChatGPT or Codex to verify it. The model that writes the code should not be the only one reviewing it.
 
I’ve been creating financial dashboard models and scripts, and from my experience, one LLM is never enough if you care about accuracy, logic, and security.

AI can help a lot, but I would not trust one model by itself. I set up a loop or bridge so one model builds or reviews the script, then another model checks it against the goal, logic, errors, and possible security issues.

For example, if I use Claude or Claude Code to build something, I’ll run it through ChatGPT or Codex to verify it. The model that writes the code should not be the only one reviewing it.
Hi Art,
Long investor-trader, I'd ask about the reviewing code on another network apart. Isn't that laborious and defeating the difference in the AI modeling. It seems the outputs build on all the data exchange and coding produced, (Warp speed Captain), and singular AI data bases collectively code, so about flip-flopping between - is that degraded script? Some ultra-scripted monitoring indicators will grab the total chart, you can't add any lower. The Suite of CarbonStation monitoring studies may and can lead to predictions, [never works].
2026-07-15-TOS_CHARTSA.png

DYODD
 
Well hello .Greg. and welcome if I may say.

That will depend on your initiative to program script into working code. Being mindful the direction you may be biased to trade, a person's personal trade-technique should dominate the scripts to the trader's routine. That is, what are you seeking to find using the AI to write?

I've only worked with a narrow range of AIs, learning subtle differences which were changing as AI development keeps moving ahead. The primary AI I chose wrote codes to picture a market as it moves, colorful first attempt, so I was shaken with losses. Instead, eventually, the fifth one (ChatGPT) was using data within the intricate folds of script! Coding indicators and monitoring using "AI" type scripted results that worked.

Add here, DYODD, don't think these indicators and monitors can predict. They can not and will not. What may be the next step, to have AI to trade - maybe? So, back of your first choice, which one is going to be the best for you? Its worth time to learn a little about the methods the AI uses to analyze and use technical data. Look at the code as it works in open markets. Patience is good. Its not a race though at times it does run.

To see some of the codes I have, search in my history. See where I started. I can always appreciate a suggestion to write another version.

Welcome and Good Luck.
 
? Best Ai to build /modify Thinkscript indicators?
I cant write code and dont have time to learn.
I've tried a few. What works best?
AI is just a bucket of data and it's not about the best AI for code as it is How good are you at articulating your ideas into a complete road map. Without a narrow and detailed narrative of what you want the AI to build you will spend a ton of time rewriting and probably ending up with junk. You will need to deliver to the AI a complete description of your final product along with the exact measures and timeframes and boundaries. You must lay out how you want your outcome to be structured along with what you do not want. Your final product at start is a blank piece of paper and AI is a 64 color box of crayons, it is up to you to put what you want on the paper, ---sometimes asking AI to start you off with a basic script of what you are looking for (giving you a paint by numbers beginning) and go from there if you are not well versed with the makeup and strategies of technical indicators. The big point, AI is not the idea, AI is the execution.

Here is a quick example of a potential start request:
  • “Build a lower study consisting of histogram and or line plots or both, for medium time frame duration swing trading on MTF capable charts, using price participation logic. I want current-state labels in plain English, a normalized companion line that stays visually readable and in scale, and a final synthesis label that identifies whether participation confirms price, conflicts with price, or is improving. Do not use vague labels, do not collapse scale, and do not rely on clouds if they create compile issues. Ask me any questions before starting.”
 
? Best Ai to build /modify Thinkscript indicators?
I cant write code and dont have time to learn.
I've tried a few. What works best?
After inputting the above request to AI it asked me 13 questions and after answering and submitting to the AI this is the code it mad (I centered it around SPY)

How I’d read it

Best long setup sequence​

On SPY, the cleaner long sequence is:
  • participation oscillator stops falling
  • yellow early-up dot appears
  • histogram flips positive
  • companion line turns up
  • structure shifts from mixed to bull
  • green up arrow appears
That sequence says:
  • internals improved first
  • then price structure caught up
  • then the move became more trustworthy

Weak bounce / tactical only sequence​

If you get:
  • structure still bear or mixed
  • oscillator turns up
  • histogram improves
  • early dot prints
  • but no confirmed bull alignment
that is usually:
  • bounce potential
  • early repair
  • not yet a clean swing continuation state
That’s the kind of nuance we asked for.

Warning sequence​

If structure still says bull but:
  • oscillator drops below zero
  • histogram weakens
  • labels shift to conflict
that means:
  • price still looks okay on surface
  • participation is no longer backing it
  • next few bars are more vulnerable to stall, fade, or failed continuation

Code:
declare lower;

input price = close;
input fastEMALength = 8;
input slowEMALength = 21;
input structureLookback = 20;
input volumeLength = 20;
input partFastLength = 5;
input partSlowLength = 13;
input normalizeLength = 50;
input signalLength = 5;
input showZeroLine = yes;
input showMarkers = yes;
input showStretchMarkers = yes;
input stretchLength = 20;
input stretchTrigger = 1.5;

def na = Double.NaN;

# -----------------------------
# PRICE STRUCTURE MODULE
# -----------------------------
def fastEMAValue = ExpAverage(price, fastEMALength);
def slowEMAValue = ExpAverage(price, slowEMALength);
def fastEMASlope = fastEMAValue - fastEMAValue[1];

def highestRange = Highest(high, structureLookback);
def lowestRange = Lowest(low, structureLookback);
def structureMid = (highestRange + lowestRange) / 2;

def structureScore =
    (if fastEMAValue > slowEMAValue then 1 else -1) +
    (if fastEMASlope > 0 then 1 else -1) +
    (if price > structureMid then 1 else -1);

def structureBull = structureScore >= 2;
def structureBear = structureScore <= -2;
def structureMixed = !structureBull and !structureBear;

# -----------------------------
# VOLUME PARTICIPATION MODULE
# price change weighted by relative volume
# -----------------------------
def avgVolumeValue = Average(volume, volumeLength);
def relativeVolume = if avgVolumeValue > 0 then volume / avgVolumeValue else 1;

def priceDelta = price - price[1];
def weightedDelta = priceDelta * relativeVolume;

def partFastValue = ExpAverage(weightedDelta, partFastLength);
def partSlowValue = ExpAverage(weightedDelta, partSlowLength);

def rawParticipationOsc = partFastValue - partSlowValue;

def oscMean = Average(rawParticipationOsc, normalizeLength);
def oscStDev = StDev(rawParticipationOsc, normalizeLength);

def participationOsc =
    if oscStDev > 0
    then (rawParticipationOsc - oscMean) / oscStDev
    else 0;

def companionSignal = ExpAverage(participationOsc, signalLength);
def participationHist = participationOsc - companionSignal;

# -----------------------------
# PARTICIPATION STATES
# -----------------------------
def partPositive = participationOsc > 0;
def partNegative = participationOsc < 0;

def partRising = participationOsc > participationOsc[1];
def partFalling = participationOsc < participationOsc[1];

def earlyUpTurn =
    participationOsc > participationOsc[1] and
    participationOsc[1] <= participationOsc[2] and
    participationHist > 0 and
    !structureBull;

def earlyDownTurn =
    participationOsc < participationOsc[1] and
    participationOsc[1] >= participationOsc[2] and
    participationHist < 0 and
    !structureBear;

def confirmedUp =
    structureBull and
    participationOsc > 0 and
    companionSignal > 0 and
    participationHist > 0;

def confirmedDown =
    structureBear and
    participationOsc < 0 and
    companionSignal < 0 and
    participationHist < 0;

# -----------------------------
# SYNTHESIS LOGIC
# explicit precedence
# -----------------------------
def bullConfirmed = confirmedUp;
def bearConfirmed = confirmedDown;

def bullConflict =
    structureBull and
    partNegative;

def bearConflict =
    structureBear and
    partPositive;

def improvingBeforePrice =
    !structureBull and
    partPositive and
    partRising and
    participationHist > 0;

def weakeningBeforePrice =
    !structureBear and
    partNegative and
    partFalling and
    participationHist < 0;

def chopRisk =
    structureMixed or
    (structureBull and partNegative and participationHist >= 0) or
    (structureBear and partPositive and participationHist <= 0);

def nextBarsUpBias =
    bullConfirmed or
    (structureBull and partRising) or
    improvingBeforePrice;

def nextBarsDownBias =
    bearConfirmed or
    (structureBear and partFalling) or
    weakeningBeforePrice;

# -----------------------------
# STRETCH / DEVIATION MODULE
# -----------------------------
def stretchBasis = Average(price, stretchLength);
def stretchStDev = StDev(price, stretchLength);
def stretchZ =
    if stretchStDev > 0
    then (price - stretchBasis) / stretchStDev
    else 0;

def stretchHigh = stretchZ > stretchTrigger;
def stretchLow = stretchZ < -stretchTrigger;

# -----------------------------
# PLOTS
# -----------------------------
plot ZeroLine = if showZeroLine then 0 else na;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);

plot ParticipationLine = participationOsc;
ParticipationLine.SetLineWeight(2);
ParticipationLine.AssignValueColor(
    if participationOsc >= 0 and partRising then Color.GREEN
    else if participationOsc >= 0 then Color.DARK_GREEN
    else if participationOsc < 0 and partFalling then Color.RED
    else Color.DARK_RED
);

plot CompanionLine = companionSignal;
CompanionLine.SetDefaultColor(Color.CYAN);
CompanionLine.SetLineWeight(2);

plot Hist = participationHist;
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.SetLineWeight(3);
Hist.AssignValueColor(
    if participationHist > 0 and participationHist > participationHist[1] then Color.UPTICK
    else if participationHist > 0 then Color.GREEN
    else if participationHist < 0 and participationHist < participationHist[1] then Color.DOWNTICK
    else Color.RED
);

# -----------------------------
# EARLY / LATE MARKERS
# -----------------------------
plot EarlyUpDot = if showMarkers and earlyUpTurn then participationOsc else na;
EarlyUpDot.SetPaintingStrategy(PaintingStrategy.POINTS);
EarlyUpDot.SetDefaultColor(Color.YELLOW);
EarlyUpDot.SetLineWeight(3);

plot EarlyDownDot = if showMarkers and earlyDownTurn then participationOsc else na;
EarlyDownDot.SetPaintingStrategy(PaintingStrategy.POINTS);
EarlyDownDot.SetDefaultColor(Color.ORANGE);
EarlyDownDot.SetLineWeight(3);

plot LateUpArrow = if showMarkers and bullConfirmed then participationOsc else na;
LateUpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LateUpArrow.SetDefaultColor(Color.GREEN);
LateUpArrow.SetLineWeight(2);

plot LateDownArrow = if showMarkers and bearConfirmed then participationOsc else na;
LateDownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
LateDownArrow.SetDefaultColor(Color.RED);
LateDownArrow.SetLineWeight(2);

# -----------------------------
# STRETCH MARKERS
# -----------------------------
plot StretchHighDot = if showStretchMarkers and stretchHigh and partFalling then participationOsc else na;
StretchHighDot.SetPaintingStrategy(PaintingStrategy.POINTS);
StretchHighDot.SetDefaultColor(Color.MAGENTA);
StretchHighDot.SetLineWeight(2);

plot StretchLowDot = if showStretchMarkers and stretchLow and partRising then participationOsc else na;
StretchLowDot.SetPaintingStrategy(PaintingStrategy.POINTS);
StretchLowDot.SetDefaultColor(Color.CYAN);
StretchLowDot.SetLineWeight(2);

# -----------------------------
# LABELS
# -----------------------------
AddLabel(
    yes,
    if structureBull then "Structure: Bull"
    else if structureBear then "Structure: Bear"
    else "Structure: Mixed",
    if structureBull then Color.GREEN
    else if structureBear then Color.RED
    else Color.GRAY
);

AddLabel(
    yes,
    if partPositive and partRising then "Participation: Positive and Rising"
    else if partPositive then "Participation: Positive but Slowing"
    else if partNegative and partFalling then "Participation: Negative and Falling"
    else if partNegative then "Participation: Negative but Improving"
    else "Participation: Flat",
    if partPositive and partRising then Color.GREEN
    else if partPositive then Color.DARK_GREEN
    else if partNegative and partFalling then Color.RED
    else if partNegative then Color.ORANGE
    else Color.GRAY
);

AddLabel(
    yes,
    if bullConfirmed then "Synthesis: Participation Confirms Price"
    else if bearConfirmed then "Synthesis: Participation Confirms Downside"
    else if bullConflict then "Synthesis: Bull Structure, Participation Not Confirming"
    else if bearConflict then "Synthesis: Bear Structure, Participation Improving"
    else if improvingBeforePrice then "Synthesis: Participation Improving Before Price"
    else if weakeningBeforePrice then "Synthesis: Participation Weakening Before Price"
    else "Synthesis: Mixed or Transitional",
    if bullConfirmed then Color.GREEN
    else if bearConfirmed then Color.RED
    else if improvingBeforePrice then Color.CYAN
    else if weakeningBeforePrice then Color.MAGENTA
    else Color.YELLOW
);

AddLabel(
    yes,
    if nextBarsUpBias and !nextBarsDownBias then "Next Few Bars: Up Bias"
    else if nextBarsDownBias and !nextBarsUpBias then "Next Few Bars: Down Bias"
    else if chopRisk then "Next Few Bars: Stall or Chop Risk"
    else "Next Few Bars: Balanced",
    if nextBarsUpBias and !nextBarsDownBias then Color.GREEN
    else if nextBarsDownBias and !nextBarsUpBias then Color.RED
    else Color.GRAY
);

 
After inputting the above request to AI,On SPY, participation is no longer backing the next few bars... !
2026-07-20-TOS_CHARTSB.png

# -----------------------------
# VOLUME PARTICIPATION MODULE
# price change weighted by relative volume
# -----------------------------
def avgVolumeValue = Average(volume, volumeLength);
def relativeVolume = if avgVolumeValue > 0 then volume / avgVolumeValue else 1;

def priceDelta = price - price[1];
def weightedDelta = priceDelta * relativeVolume;

def partFastValue = ExpAverage(weightedDelta, partFastLength);
def partSlowValue = ExpAverage(weightedDelta, partSlowLength);

def rawParticipationOsc = partFastValue - partSlowValue;

def oscMean = Average(rawParticipationOsc, normalizeLength);
def oscStDev = StDev(rawParticipationOsc, normalizeLength);

def participationOsc =
if oscStDev > 0
then (rawParticipationOsc - oscMean) / oscStDev
else 0;

def companionSignal = ExpAverage(participationOsc, signalLength);
def participationHist = participationOsc - companionSignal;

# -----------------------------
# PARTICIPATION STATES
# -----------------------------
def partPositive = participationOsc > 0;
def partNegative = participationOsc < 0;

def partRising = participationOsc > participationOsc[1];
def partFalling = participationOsc < participationOsc[1];

def earlyUpTurn =
participationOsc > participationOsc[1] and
participationOsc[1] <= participationOsc[2] and
participationHist > 0 and
!structureBull;

def earlyDownTurn =
participationOsc < participationOsc[1] and
participationOsc[1] >= participationOsc[2] and
participationHist < 0 and
!structureBear;

def confirmedUp =
structureBull and
participationOsc > 0 and
companionSignal > 0 and
participationHist > 0;

def confirmedDown =
structureBear and
participationOsc < 0 and
companionSignal < 0 and
participationHist < 0;

# -----------------------------
# SYNTHESIS LOGIC
# explicit precedence
# -----------------------------
def bullConfirmed = confirmedUp;
def bearConfirmed = confirmedDown;

def bullConflict =
structureBull and
partNegative;

def bearConflict =
structureBear and
partPositive;

def improvingBeforePrice =
!structureBull and
partPositive and
partRising and
participationHist > 0;

def weakeningBeforePrice =
!structureBear and
partNegative and
partFalling and
participationHist < 0;

def chopRisk =
structureMixed or
(structureBull and partNegative and participationHist >= 0) or
(structureBear and partPositive and participationHist <= 0);

def nextBarsUpBias =
bullConfirmed or
(structureBull and partRising) or
improvingBeforePrice;

def nextBarsDownBias =
bearConfirmed or
(structureBear and partFalling) or
weakeningBeforePrice;

# -----------------------------
# STRETCH / DEVIATION MODULE
# -----------------------------
def stretchBasis = Average(price, stretchLength);
def stretchStDev = StDev(price, stretchLength);
def stretchZ =
if stretchStDev > 0
then (price - stretchBasis) / stretchStDev
else 0;

def stretchHigh = stretchZ > stretchTrigger;
def stretchLow = stretchZ < -stretchTrigger;

# -----------------------------
# PLOTS
# -----------------------------
plot ZeroLine = if showZeroLine then 0 else na;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);

plot ParticipationLine = participationOsc;
ParticipationLine.SetLineWeight(2);
ParticipationLine.AssignValueColor(
if participationOsc >= 0 and partRising then Color.GREEN
else if participationOsc >= 0 then Color.DARK_GREEN
else if participationOsc < 0 and partFalling then Color.RED
else Color.DARK_RED
);

plot CompanionLine = companionSignal;
CompanionLine.SetDefaultColor(Color.CYAN);
CompanionLine.SetLineWeight(2);

plot Hist = participationHist;
Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Hist.SetLineWeight(3);
Hist.AssignValueColor(
if participationHist > 0 and participationHist > participationHist[1] then Color.UPTICK
else if participationHist > 0 then Color.GREEN
else if participationHist < 0 and participationHist < participationHist[1] then Color.DOWNTICK
else Color.RED
);

# -----------------------------
# EARLY / LATE MARKERS
# -----------------------------
plot EarlyUpDot = if showMarkers and earlyUpTurn then participationOsc else na;
EarlyUpDot.SetPaintingStrategy(PaintingStrategy.POINTS);
EarlyUpDot.SetDefaultColor(Color.YELLOW);
EarlyUpDot.SetLineWeight(3);

plot EarlyDownDot = if showMarkers and earlyDownTurn then participationOsc else na;
EarlyDownDot.SetPaintingStrategy(PaintingStrategy.POINTS);
EarlyDownDot.SetDefaultColor(Color.ORANGE);
EarlyDownDot.SetLineWeight(3);

plot LateUpArrow = if showMarkers and bullConfirmed then participationOsc else na;
LateUpArrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
LateUpArrow.SetDefaultColor(Color.GREEN);
LateUpArrow.SetLineWeight(2);

plot LateDownArrow = if showMarkers and bearConfirmed then participationOsc else na;
LateDownArrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
LateDownArrow.SetDefaultColor(Color.RED);
LateDownArrow.SetLineWeight(2);

# -----------------------------
# STRETCH MARKERS
# -----------------------------
plot StretchHighDot = if showStretchMarkers and stretchHigh and partFalling then participationOsc else na;
StretchHighDot.SetPaintingStrategy(PaintingStrategy.POINTS);
StretchHighDot.SetDefaultColor(Color.MAGENTA);
StretchHighDot.SetLineWeight(2);

plot StretchLowDot = if showStretchMarkers and stretchLow and partRising then participationOsc else na;
StretchLowDot.SetPaintingStrategy(PaintingStrategy.POINTS);
StretchLowDot.SetDefaultColor(Color.CYAN);
StretchLowDot.SetLineWeight(2);

# -----------------------------
# LABELS
# -----------------------------
AddLabel(
yes,
if structureBull then "Structure: Bull"
else if structureBear then "Structure: Bear"
else "Structure: Mixed",
if structureBull then Color.GREEN
else if structureBear then Color.RED
else Color.GRAY
);

AddLabel(
yes,
if partPositive and partRising then "Participation: Positive and Rising"
else if partPositive then "Participation: Positive but Slowing"
else if partNegative and partFalling then "Participation: Negative and Falling"
else if partNegative then "Participation: Negative but Improving"
else "Participation: Flat",
if partPositive and partRising then Color.GREEN
else if partPositive then Color.DARK_GREEN
else if partNegative and partFalling then Color.RED
else if partNegative then Color.ORANGE
else Color.GRAY
);

AddLabel(
yes,
if bullConfirmed then "Synthesis: Participation Confirms Price"
else if bearConfirmed then "Synthesis: Participation Confirms Downside"
else if bullConflict then "Synthesis: Bull Structure, Participation Not Confirming"
else if bearConflict then "Synthesis: Bear Structure, Participation Improving"
else if improvingBeforePrice then "Synthesis: Participation Improving Before Price"
else if weakeningBeforePrice then "Synthesis: Participation Weakening Before Price"
else "Synthesis: Mixed or Transitional",
if bullConfirmed then Color.GREEN
else if bearConfirmed then Color.RED
else if improvingBeforePrice then Color.CYAN
else if weakeningBeforePrice then Color.MAGENTA
else Color.YELLOW
);

AddLabel(
yes,
if nextBarsUpBias and !nextBarsDownBias then "Next Few Bars: Up Bias"
else if nextBarsDownBias and !nextBarsUpBias then "Next Few Bars: Down Bias"
else if chopRisk then "Next Few Bars: Stall or Chop Risk"
else "Next Few Bars: Balanced",
if nextBarsUpBias and !nextBarsDownBias then Color.GREEN
else if nextBarsDownBias and !nextBarsUpBias then Color.RED
else Color.GRAY
);[/CODE]

different but true
 

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