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:
View attachment 23893
Entry buy signals triggered by HMA 10 20 cross up and both with positive slope up.

This is confirmed by MACD above signal line and both at or above the zero line.
Signals remain bullish as long as stock continues up,
10/20 HMA's are green and up, and MACD is going up and remains above signal and zero line.
Heikin-Ashi candles used here for green is entry Exit or short entry is tirggered by HMA's with 20 over 10 period, and confirmed by MACD below signal line, (downward slope of both lines), Helkin-Ashi red candle confirms red arrow down and exit of the trade or short entry.

Here is the script per ChatGPT to produce this:
Code:
# Pseudo-code for Buy and Sell signals based on your conditions

# Calculate HMA
def HMA(price, period):
# Calculate Hull Moving Average for the given period
return hull_moving_average(price, period)

# MACD Calculation
def MACD(price, fast_period, slow_period, signal_period):
# Calculate MACD line and Signal line
macd_line = macd(price, fast_period, slow_period)
signal_line = signal(macd_line, signal_period)
return macd_line, signal_line

# Determine Entry Signal (Buy)
def check_entry(price, hma_10, hma_20, macd_line, signal_line):
# Check if HMA 10 crosses above HMA 20 with positive slope for both HMAs
if hma_10 > hma_20 and is_positive_slope(hma_10) and is_positive_slope(hma_20):
# Check if MACD is above the signal line and both are above zero line
if macd_line > signal_line and macd_line > 0 and signal_line > 0:
# Check if Heikin-Ashi candle is green (bullish)
if is_heikin_ashi_green():
return "Buy Signal - Green Arrow"
return None

# Determine Exit Signal (Sell)
def check_exit(price, hma_10, hma_20, macd_line, signal_line):
# Check if HMA 20 crosses above HMA 10 with negative slope for both HMAs
if hma_20 > hma_10 and is_negative_slope(hma_20) and is_negative_slope(hma_10):
# Check if MACD is below the signal line and both are sloping downward
if macd_line < signal_line and macd_line < 0 and signal_line < 0:
# Check if Heikin-Ashi candle is red (bearish)
if is_heikin_ashi_red():
return "Sell Signal - Red Arrow"
return None

reply to 352

here is something to experiment with
it plots arrows when all the average and macd signals happen.
the problem with looking for several signals on the same bar, is that they rarely will all happen.

if you want to look for several signals happening within x bars of the average line crossing, that will be another study.


Code:
#macd_hull_ashi_signals

#https://usethinkscript.com/threads/macd-and-hull-ma-indicators-for-signals.20391/
#MACD and Hull MA indicators for signals
#Dr. Dave  1/20
#1

# buy signals,
#   HMA 10 20 cross up and both with positive slope up.
#   This is confirmed by MACD above signal line and both at or above the zero line.

# Signals remain bullish as long as stock continues up, 10/20 HMA's are green and up, and MACD is going up and remains above signal and zero line. Heikin-Ashi candles used here for green is entry Exit or short entry is tirggered by HMA's with 20 over 10 period, and confirmed by MACD below signal line, (downward slope of both lines), Helkin-Ashi red candle confirms red arrow down and exit of the trade or short entry.

#Here is the script per ChatGPT to produce this:



# Pseudo-code for Buy and Sell signals based on your conditions

# Calculate HMA
#def HMA(price, period):
# Calculate Hull Moving Average for the given period
#return hull_moving_average(price, period)

# MACD Calculation
#def MACD(price, fast_period, slow_period, signal_period):
# Calculate MACD line and Signal line
#macd_line = macd(price, fast_period, slow_period)
#signal_line = signal(macd_line, signal_period)
#return macd_line, signal_line

# Determine Entry Signal (Buy)
#def check_entry(price, hma_10, hma_20, macd_line, signal_line):
# Check if HMA 10 crosses above HMA 20 with positive slope for both HMAs
#if hma_10 > hma_20 and is_positive_slope(hma_10) and is_positive_slope(hma_20):
# Check if MACD is above the signal line and both are above zero line
#if macd_line > signal_line and macd_line > 0 and signal_line > 0:
# Check if Heikin-Ashi candle is green (bullish)
#if is_heikin_ashi_green():
#return "Buy Signal - Green Arrow"
#return None

# Determine Exit Signal (Sell)
#def check_exit(price, hma_10, hma_20, macd_line, signal_line):
# Check if HMA 20 crosses above HMA 10 with negative slope for both HMAs
#if hma_20 > hma_10 and is_negative_slope(hma_20) and is_negative_slope(hma_10):
# Check if MACD is below the signal line and both are sloping downward
#if macd_line < signal_line and macd_line < 0 and signal_line < 0:
# Check if Heikin-Ashi candle is red (bearish)
#if is_heikin_ashi_red():
#return "Sell Signal - Red Arrow"
#return None







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

def na = double.nan;
def bn = barnumber();

#-------------------
# avgs
#https://toslc.thinkorswim.com/center/reference/thinkScript/Constants/AverageType
#input avg1_type = AverageType.Simple;
#input avg1_type = AverageType.exponential;
#input avg1_type = AverageType.hull;
#input avg1_type = AverageType.weighted;
#input avg1_type = AverageType.wilders;

def data = close;
def stk_up = data > data[1];
def stk_dwn = data < data[1];


input avg1_type = AverageType.hull;
input avg1_length = 10;
def avg1 = MovingAverage(avg1_type, data, avg1_length );

input avg2_type = AverageType.hull;
input avg2_length = 20;
def avg2 = MovingAverage(avg2_type, data, avg2_length );

# long -  HMA 10 20 cross up and both with positive slope up.
# crossing averages is the driver
def xup = avg1 crosses above avg2;
def xdwn = avg1 crosses below avg2;

def avg1_slope_up = avg1 > avg1[1];
def avg1_slope_dwn = avg1 < avg1[1];
def avg2_slope_up = avg2 > avg2[1];
def avg2_slope_dwn = avg2 < avg2[1];


input show_avg_lines = yes;
plot zavg1 = if show_avg_lines then avg1 else na;
plot zavg2 = if show_avg_lines then avg2 else na;
zavg1.SetDefaultColor(Color.cyan);
zavg1.setlineweight(1);
zavg1.hidebubble();
zavg2.SetDefaultColor(Color.yellow);
zavg2.setlineweight(1);
zavg2.hidebubble();

def avg_long_enter = xup and avg1_slope_up and avg2_slope_up;
def avg_short_enter = xdwn and avg1_slope_dwn and avg2_slope_dwn;


#-------------------
# macd
#declare lower;
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input showBreakoutSignals = no;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def Diff = Value - Avg;
def ZeroLine = 0;
def UpSignal = if Diff crosses above ZeroLine then ZeroLine else Double.NaN;
def DownSignal = if Diff crosses below ZeroLine then ZeroLine else Double.NaN;


# long - MACD above signal line and both at or above the zero line.  value > avg
def m_valueup = value > avg;
def m_value_above0 = value >= 0;
# short - MACD below signal line and both at or below the zero line.  value < avg
def m_valuedwn = value < avg;
def m_value_below0 = value <= 0;

def macd_long_enter = m_valueup and m_value_above0;
def macd_short_enter = m_valuedwn and m_value_below0;


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

# arrows for entering trade .  green up for long , green down for short
input show_avg_enter = yes;
plot zavg_le = show_avg_enter and avg_long_enter and macd_long_enter;
#zavg_le.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_up);
zavg_le.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_UP);
zavg_le.SetDefaultColor(Color.cyan);
zavg_le.setlineweight(2);
zavg_le.hidebubble();

plot zavg_se = show_avg_enter and avg_short_enter and macd_short_enter;
#zavg_se.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_down);
zavg_se.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_down);
zavg_se.SetDefaultColor(Color.yellow);
zavg_se.setlineweight(2);
zavg_se.hidebubble();
#
 

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

Copied and pasted after removing the intro that wasn't strategy code. It did change the color of my HMA and gave me a few up arrows and one down arrow on my chart, but nothing that was terribly productive.
 
Copied and pasted after removing the intro that wasn't strategy code. It did change the color of my HMA and gave me a few up arrows and one down arrow on my chart, but nothing that was terribly productive.
Correct. Moving averages and oscillators are good for reviewing trend, ranges, and spans.
Not so much for entry or exit signals.

Read more:
https://usethinkscript.com/threads/lagging-indicator-accuracy-in-thinkorswim.15624/
https://usethinkscript.com/threads/how-to-read-an-oscillator-in-thinkorswim.11497/
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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