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:
Build a scan tab, each separately:

1. VOULME greater than>2 times the previous day

2. VOULME greater than>2 times the previous five days

3. VOULME greater than>2 times the previous quarter

Then on the SEARCH RESULT (in Scan tab or WATCHLIST tab) make EACH CODE appear as green background if meet the condition. Pink background if NOT meet the condition.

Code:
# Volume greater than 2 times the previous day
input multiple = 2;

def volCondition1 = volume > 2 * volume[1];
AddLabel(yes, if volCondition1 then "Volume > 2x Prev Day" else "", if volCondition1 then color.black else color.white);

# Volume greater than 2 times the previous five days
def volCondition2 = volume > 2 * average(volume, 5);
AddLabel(yes, if volCondition2 then "Volume > 2x Prev 5 Days" else "", if volCondition2 then color.black else color.white);

# Volume greater than 2 times the previous quarter
def volCondition3 = volume > 2 * average(volume, 63); # Assuming 63 trading days in a quarter
AddLabel(yes, if volCondition3 then "Volume > 2x Prev Quarter" else "", if volCondition3 then color.black else color.white);

# Background color based on condition
AssignBackgroundColor(if volCondition1 or volCondition2 or volCondition3 then color.green else color.pink);

Guys, have this code, but how to use this code to scan each of the condition, separately?
 
Last edited by a moderator:
CAN SOMEONE FIX THIS ERROR CODE
# Example Trading Strategy with Consolidation and Breakout Detection

declare lower;

# Inputs
input atrLength = 14;
input consolidationMultiplier = 1.5;
input breakoutMultiplier = 2.0;
input riskPerTrade = 1.0; # Risk percentage per trade

# Average True Range (ATR) for volatility measurement
def atr = ATR(atrLength);

# Calculate consolidation and breakout levels
def consolidationLevel = consolidationMultiplier * atr;
def breakoutLevel = breakoutMultiplier * atr;

# Calculate risk per trade in dollars
def capital = GetLastEquity(); # Use GetLastEquity to get the account's net liquidating value
def riskAmount = capital * (riskPerTrade / 100);

# Calculate position size based on risk and distance to stop loss
def positionSize = if (atr != 0) then Round(riskAmount / atr, 0) else 1;

# Market state detection
def isConsolidating = atr <= consolidationLevel;
def isBreakingOut = atr > breakoutLevel;

# Entry conditions
def longEntry = close > high[1] and isBreakingOut;
def shortEntry = close < low[1] and isBreakingOut;

# Exit conditions
def longExit = close < low[1] or isConsolidating;
def shortExit = close > high[1] or isConsolidating;

# Plotting signals on chart
plot BuySignal = longEntry;
plot SellSignal = shortEntry;
plot CoverSignal = longExit;
plot ShortSignal = shortExit;

# Visualization
BuySignal.SetDefaultColor(Color.GREEN);
SellSignal.SetDefaultColor(Color.RED);
CoverSignal.SetDefaultColor(Color.GREEN);
ShortSignal.SetDefaultColor(Color.RED);
 
Last edited by a moderator:
CAN SOMEONE FIX THIS ERROR CODE
# Example Trading Strategy with Consolidation and Breakout Detection

declare lower;

# Inputs
input atrLength = 14;
input consolidationMultiplier = 1.5;
input breakoutMultiplier = 2.0;
input riskPerTrade = 1.0; # Risk percentage per trade

# Average True Range (ATR) for volatility measurement
def atr = ATR(atrLength);

# Calculate consolidation and breakout levels
def consolidationLevel = consolidationMultiplier * atr;
def breakoutLevel = breakoutMultiplier * atr;

# Calculate risk per trade in dollars
def capital = GetLastEquity(); # Use GetLastEquity to get the account's net liquidating value
def riskAmount = capital * (riskPerTrade / 100);

# Calculate position size based on risk and distance to stop loss
def positionSize = if (atr != 0) then Round(riskAmount / atr, 0) else 1;

# Market state detection
def isConsolidating = atr <= consolidationLevel;
def isBreakingOut = atr > breakoutLevel;

# Entry conditions
def longEntry = close > high[1] and isBreakingOut;
def shortEntry = close < low[1] and isBreakingOut;

# Exit conditions
def longExit = close < low[1] or isConsolidating;
def shortExit = close > high[1] or isConsolidating;

# Plotting signals on chart
plot BuySignal = longEntry;
plot SellSignal = shortEntry;
plot CoverSignal = longExit;
plot ShortSignal = shortExit;

# Visualization
BuySignal.SetDefaultColor(Color.GREEN);
SellSignal.SetDefaultColor(Color.RED);
CoverSignal.SetDefaultColor(Color.GREEN);
ShortSignal.SetDefaultColor(Color.RED);

reply to #203

change capital formula to what i think you want
def capital = AccountNetLiq();

https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/AccountNetLiq

Code:
#chat203_fix

#https://usethinkscript.com/threads/chatgpt-bard-other-ai-scripts-which-cant-be-used-in-thinkorswim.13822/page-11#post-136776

#Tonievanu  #203
#CAN SOMEONE FIX THIS ERROR CODE
# Example Trading Strategy with Consolidation and Breakout Detection

declare lower;

# Inputs
input atrLength = 14;
input consolidationMultiplier = 1.5;
input breakoutMultiplier = 2.0;
input riskPerTrade = 1.0; # Risk percentage per trade

# Average True Range (ATR) for volatility measurement
def atr = ATR(atrLength);

# Calculate consolidation and breakout levels
def consolidationLevel = consolidationMultiplier * atr;
def breakoutLevel = breakoutMultiplier * atr;

# Calculate risk per trade in dollars
#def capital = GetLastEquity(); # Use GetLastEquity to get the account's net liquidating value
def capital = AccountNetLiq();

def riskAmount = capital * (riskPerTrade / 100);

# Calculate position size based on risk and distance to stop loss
def positionSize = if (atr != 0) then Round(riskAmount / atr, 0) else 1;

# Market state detection
def isConsolidating = atr <= consolidationLevel;
def isBreakingOut = atr > breakoutLevel;

# Entry conditions
def longEntry = close > high[1] and isBreakingOut;
def shortEntry = close < low[1] and isBreakingOut;

# Exit conditions
def longExit = close < low[1] or isConsolidating;
def shortExit = close > high[1] or isConsolidating;

# Plotting signals on chart
plot BuySignal = longEntry;
plot SellSignal = shortEntry;
plot CoverSignal = longExit;
plot ShortSignal = shortExit;

# Visualization
BuySignal.SetDefaultColor(Color.GREEN);
SellSignal.SetDefaultColor(Color.RED);
CoverSignal.SetDefaultColor(Color.GREEN);
ShortSignal.SetDefaultColor(Color.RED);


addchartbubble(0, 0,
capital
, color.yellow, yes);
#
 
halcyonguy , The time code is not working correctly with Gold Futures, what could it be?

reply to 201 , 192
https://usethinkscript.com/threads/...used-in-thinkorswim.13822/page-10#post-134251

you didn't say anything about futures in your post.
it seems like RegularTradingStart(GetYYYYMMDD()) doesn't read the correct value with futures. i'm not sure why, i don't trade futures. i loaded the built in futures watchlist, and looked at some symbols. turn on extended hours.
i added this to put a colored bubble at the start and end of the trading period. it doesn't seem to work.
it does work with normal stocks, 9;30 to 4pm

Code:
def start = gettime() == RegularTradingStart(GetYYYYMMDD()) + 1;
def end = gettime() == RegularTradingend(GetYYYYMMDD()) + 1;

addchartbubble(1, low,
start + " S\n" +
end + " E"
, (if start then color.green else if end then color.red else color.gray), 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
212 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