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:
I need help with this script Iget an error

input aggregationPeriod = AggregationPeriod.DAY;
input showVolume = yes;
input showOpenInterest = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def oi = open_interest;

def isPeriodRolled = CompoundValue(1, (GetAggregationPeriod() <> GetAggregationPeriod()[1]), yes);

def volumeSum;
def oiSum;

if (isPeriodRolled) {
volumeSum = v;
oiSum = oi;
} else {
volumeSum = volumeSum[1] + v;
oiSum = oiSum[1] + oi;
}

def label = "OI: " + oiSum + "\n";
label = label + "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%\n";
label = label + "Vol: " + volumeSum;

AddLabel(yes, label, Color.WHITE);

plot openInterest = showOpenInterest;
openInterest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
openInterest.SetDefaultColor(Color.ORANGE);

def pcRatio = showVolume(PutVolume() / CallVolume())/
Double.NaN;

def volume = showVolume; (volumesum); Double.NaN;


AddCloud(volume, pcRatio, Color.GREEN, Color.RED);
 
I need help with this script Iget an error

input aggregationPeriod = AggregationPeriod.DAY;
input showVolume = yes;
input showOpenInterest = yes;

def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def oi = open_interest;

def isPeriodRolled = CompoundValue(1, (GetAggregationPeriod() <> GetAggregationPeriod()[1]), yes);

def volumeSum;
def oiSum;

if (isPeriodRolled) {
volumeSum = v;
oiSum = oi;
} else {
volumeSum = volumeSum[1] + v;
oiSum = oiSum[1] + oi;
}

def label = "OI: " + oiSum + "\n";
label = label + "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%\n";
label = label + "Vol: " + volumeSum;

AddLabel(yes, label, Color.WHITE);

plot openInterest = showOpenInterest;
openInterest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
openInterest.SetDefaultColor(Color.ORANGE);

def pcRatio = showVolume(PutVolume() / CallVolume())/
Double.NaN;

def volume = showVolume; (volumesum); Double.NaN;


AddCloud(volume, pcRatio, Color.GREEN, Color.RED);


reply to post62

you didn't explain what you are trying to do with this study, and almost every line is wrong, so i'm not going to guess at its purpose, and create a new study.
i will guess that you want a put call ratio thing, and show you this link, that might have something relevent.
https://usethinkscript.com/threads/put-call-ratio-pcr-indicator-for-thinkorswim.606/

-------------------------

i'll repeat this again, it is highly unlikely that chatgpt will create a working thinkscript study. it just doesn't know the language.

-------------------

when i load your study, it shows just 1 error, with this line,

def volume = showVolume; (volumesum); Double.NaN;

but there are many errors. thinkscript is funny that way, sometimes it only shows 1 or 2 errors at a time. when they get fixed, more errors will show up.

i'm guessing it should be a if then statement, like this,

def volume = if showVolume then volumesum else Double.NaN;


after fixing that one, there are 5+ errors.

def isPeriodRolled = CompoundValue(1, (GetAggregationPeriod() <> GetAggregationPeriod()[1]), yes);

several things wrong here,
..don't use offset on GetAggregationPeriod()[1]
..the agg period isn't going to change, so comparing it to itself on a previous bar will be the same.
....i'm guessing this was supposed to determine a new day?


these 3 lines are wrong.

def label = "OI: " + oiSum + "\n";
label = label + "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%\n";
label = label + "Vol: " + volumeSum;
AddLabel(yes, label, Color.WHITE);

can't assign text with a def.
can't create a text string and assign to a variable. have to use the text formula within addlabel().
can't use the same variable more than once.
can't use \n within a label. doesn't do anything. labels are all on one line. if \n is used in a bubble, then it starts a new line.

here are those lines as 3 labels,
AddLabel(yes, "OI: " + oiSum , Color.WHITE);
AddLabel(yes, "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%", Color.WHITE);
AddLabel(yes, "Vol: " + volumeSum, Color.WHITE);

but one line still has an error because PutVolume() and CallVolume() are not valid.
they are not built in functions, they are not defined as a script, or not defined as variables.
so i can't create a working study.


this is wrong and probably should be a if then
def pcRatio = showVolume(PutVolume() / CallVolume()) / Double.NaN;

def pcRatio = if showVolume then (PutVolume / CallVolume) else Double.NaN;

but it has errors because PutVolume() and CallVolume() are not valid.


too many unknowns and errors to fix.
 
Hello.
Zero coding experience here, just fetching indicators from ChatGPT. I continue to run into this problem, and no matter how much ChatGPT troubleshoots itself, it cannot fix the issue. I am trying to create an indicator that plots a red down arrow on top of a candle when Polarized Fractal Efficiency is greater than 80, and RSI is less than 75.

It seems to have no problem coding the RSI part, but when I introduce the Polarized Fractal Efficiency part, it begins creating code with errors. Here is the transcript.

Me: Using thinkscript, create an indicator that places a down red arrow above the candle when RSI is less than 75

ChatGPT:

# Define input parameters
input length = 14;
input oversold = 30;
input overbought = 70;

# Calculate RSI
def NetChgAvg = MovingAverage(AverageType.EXPONENTIAL, close - close[1], length);
def TotChgAvg = MovingAverage(AverageType.EXPONENTIAL, AbsValue(close - close[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

# Define conditions for arrow
def arrow_condition = RSI < 75;

# Plot arrow
plot Arrow = if arrow_condition then high + 1 else Double.NaN;
Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Arrow.SetLineWeight(1);
Arrow.AssignValueColor(if arrow_condition then Color.RED else Color.GRAY);

This script first calculates the RSI based on the input length and overbought/oversold levels. It then defines a condition for when the arrow should be plotted (in this case, when RSI is less than 75). Finally, it plots a down red arrow above the candle when the condition is met. You can adjust the input parameters to customize the script to your liking.

Me: Now add to it, that Polarized Fractal Efficiency must be greater than 80


ChatGPT:

declare lower;

input length = 10;

def pfe = TotalSum((2 * length - 1) * AbsValue(close - close[1]) / (length * TotalSum(AbsValue(close - close[1]), length)), length) * 100;

plot RSI_condition = RSI() < 75;
plot PFE_condition = pfe > 80;

plot arrow = if RSI_condition and PFE_condition then high + 2 else Double.NaN;
arrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);

Note that pfe is defined as a variable using the same formula as before. The RSI() function is used to check if the RSI is less than 75. Both conditions are then used to plot the arrow above the candle if they are met.

These are the errors that came up:
1 params expected but 2 found while calling totalsum at 7:97
1 params expected but 2 found while calling totalsum at 7:30
1 params expected but 2 found while calling totalsum at 7:97
1 params expected but 2 found while calling totalsum at 7:30

ChatGPT:
It seems like there is an issue with the TotalSum() function. The error message says that it is expecting only one parameter but it found two. This usually happens when the function is being passed more arguments than it should. Please double-check that the TotalSum() function is being passed only one argument.

Here's the updated script for the indicator:

declare lower;

input length = 10;

def rsi = reference RSI(length = 14);

plot arrow = if rsi < 75 and TotalSum((2 * length - 1) * AbsValue(close - close[1]) / (length * TotalSum(AbsValue(close - close[1]), length)), length) * 100 > 80 then high + 2 else Double.NaN;

arrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);

This new code it generated also didn't work. It seems to have continuous trouble with that "TotalSum" line. Of course, I know nothing of what this means and would appreciate any help. Thanks guys!
 
Hello.
Zero coding experience here, just fetching indicators from ChatGPT. I continue to run into this problem, and no matter how much ChatGPT troubleshoots itself, it cannot fix the issue. I am trying to create an indicator that plots a red down arrow on top of a candle when Polarized Fractal Efficiency is greater than 80, and RSI is less than 75.

It seems to have no problem coding the RSI part, but when I introduce the Polarized Fractal Efficiency part, it begins creating code with errors. Here is the transcript.

Me: Using thinkscript, create an indicator that places a down red arrow above the candle when RSI is less than 75

ChatGPT:

# Define input parameters
input length = 14;
input oversold = 30;
input overbought = 70;

# Calculate RSI
def NetChgAvg = MovingAverage(AverageType.EXPONENTIAL, close - close[1], length);
def TotChgAvg = MovingAverage(AverageType.EXPONENTIAL, AbsValue(close - close[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);

# Define conditions for arrow
def arrow_condition = RSI < 75;

# Plot arrow
plot Arrow = if arrow_condition then high + 1 else Double.NaN;
Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Arrow.SetLineWeight(1);
Arrow.AssignValueColor(if arrow_condition then Color.RED else Color.GRAY);

This script first calculates the RSI based on the input length and overbought/oversold levels. It then defines a condition for when the arrow should be plotted (in this case, when RSI is less than 75). Finally, it plots a down red arrow above the candle when the condition is met. You can adjust the input parameters to customize the script to your liking.

Me: Now add to it, that Polarized Fractal Efficiency must be greater than 80


ChatGPT:

declare lower;

input length = 10;

def pfe = TotalSum((2 * length - 1) * AbsValue(close - close[1]) / (length * TotalSum(AbsValue(close - close[1]), length)), length) * 100;

plot RSI_condition = RSI() < 75;
plot PFE_condition = pfe > 80;

plot arrow = if RSI_condition and PFE_condition then high + 2 else Double.NaN;
arrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);

Note that pfe is defined as a variable using the same formula as before. The RSI() function is used to check if the RSI is less than 75. Both conditions are then used to plot the arrow above the candle if they are met.

These are the errors that came up:
1 params expected but 2 found while calling totalsum at 7:97
1 params expected but 2 found while calling totalsum at 7:30
1 params expected but 2 found while calling totalsum at 7:97
1 params expected but 2 found while calling totalsum at 7:30

ChatGPT:
It seems like there is an issue with the TotalSum() function. The error message says that it is expecting only one parameter but it found two. This usually happens when the function is being passed more arguments than it should. Please double-check that the TotalSum() function is being passed only one argument.

Here's the updated script for the indicator:

declare lower;

input length = 10;

def rsi = reference RSI(length = 14);

plot arrow = if rsi < 75 and TotalSum((2 * length - 1) * AbsValue(close - close[1]) / (length * TotalSum(AbsValue(close - close[1]), length)), length) * 100 > 80 then high + 2 else Double.NaN;

arrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);

This new code it generated also didn't work. It seems to have continuous trouble with that "TotalSum" line. Of course, I know nothing of what this means and would appreciate any help. Thanks guys!

reply to #64
hello and welcome

if you are trying to create a study, research it and find out what the formulas are.
look up pfe and post a link about it and the formulas it should use.

even if you don't know a language, you can compare formulas, and look them up on the online manual.

the totalsum() formula has absvalue().
totalsum() has 1 parameter. it does not have a length
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/TotalSum
absvalue has only 1 parameter, not 2. not a length.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Math---Trig/AbsValue

i removed the lengths, but don't know if the formula is correct. probably not as it draws arrows on all the bars.

-----------------------------

first version of code
not correct ( just no errors)

Code:
#chat_totalsum_ver1

#https://usethinkscript.com/threads/chatgpt-and-totalsum-errors.15021/

#Me: Using thinkscript, create an indicator that,
#  places a down red arrow above the candle,
#  when RSI is less than 75

#ChatGPT:

# Define input parameters
# rsi----------------------------
input rsilen = 14;
input oversold = 30;
input overbought = 70;
def NetChgAvg = MovingAverage(AverageType.EXPONENTIAL, close - close[1], rsilen);
def TotChgAvg = MovingAverage(AverageType.EXPONENTIAL, AbsValue(close - close[1]), rsilen);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
#--------------------------------

input rsinum = 75;
# Define conditions for arrow
def rsi_cond = RSI < rsinum;

# Plot arrow
#plot Arrow = if arrow_condition then high + 1 else Double.NaN;
#Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#Arrow.SetLineWeight(1);
#Arrow.AssignValueColor(if arrow_condition then Color.RED else Color.GRAY);

#This script first calculates the RSI based on the input length and overbought/oversold levels. It then defines a condition for when the arrow should be plotted (in this case, when RSI is less than 75). Finally, it plots a down red arrow above the candle when the condition is met. You can adjust the input parameters to customize the script to your liking.

#Me: Now add to it, that Polarized Fractal Efficiency must be greater than 80

#ChatGPT:
#declare lower;

input pfelen = 10;
input pfenum = 80;

#def pfe = TotalSum((2 * pfelen - 1) * AbsValue(close - close[1]) / (pfelen * TotalSum(AbsValue(close - close[1]), length)), length) * 100;
def pfe = TotalSum((2 * pfelen - 1) * AbsValue(close - close[1]) / (pfelen * TotalSum(AbsValue(close - close[1]) ))) * 100;
def pfe_cond = pfe > pfenum;


plot arrow = if RSI_cond and PFE_cond then high * (1+0.002) else Double.NaN;
arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);

#Note that pfe is defined as a variable using the same formula as before. The RSI() function is used to check if the RSI is less than 75. Both conditions are then used to plot the arrow above the candle if they are met.

input test1 = no;
addchartbubble(test1,low,
round(rsi,0) + "  rsi\n" +
round(pfe,0) + "  pfe"
, color.yellow, no);
#
 
Last edited:
Need correct code

# Volume Profile Order Flow Cumulative Delta and Imbalance Indicator with Arrows

input vpRange = 10; # Volume Profile range
input imbalanceThreshold = 500; # Order flow imbalance threshold

def vp = VolumeProfile("startNewProfile" = yes, "onExpansion" = no, "numberOfProfiles" = vpRange);
def delta = close - close[1];
def cumDelta = Sum(delta, vpRange);
def imbalance = cumDelta > imbalanceThreshold ? 1 : cumDelta < -imbalanceThreshold ? -1 : 0;

# Draw arrows for potential reversal and breakout points
AddChartBubble(imbalance > 0 and close < vp.lowestPrice, vp.lowestPrice, "Buy", Color.Green, yes);
AddChartBubble(imbalance < 0 and close > vp.highestPrice, vp.highestPrice, "Sell", Color.Red, yes);
AddChartBubble(close[1] < vp.highestPrice and close > vp.highestPrice, vp.highestPrice, "Buy Breakout", Color.Green, no);
AddChartBubble(close[1] > vp.lowestPrice and close < vp.lowestPrice, vp.lowestPrice, "Sell Breakout", Color.Red, no);
 
Last edited by a moderator:
Need correct code

Code:
# Technical and Fundamental Breakout Scanner on Daily Bar

# Inputs
input technicalBreakoutThreshold = 2.0; # Technical breakout threshold
input fundamentalBreakoutThreshold = 5.0; # Fundamental breakout threshold
input technicalIndicators = {default "ADX", "ATR", "Bollinger Bands", "MACD", "RSI", "Stochastic", "Volume Average"}; # Technical indicators to use
input movingAverageType = {default Simple, Exponential}; # Moving average type
input movingAverageLength = 20; # Moving average length
input movingAveragePrice = {default close, high, low, open, median}; # Moving average price

# Technical indicators
def adx = DMI(14).ADX;
def atr = ATR(14);
def upperBB = BollingerBands().UpperBand;
def lowerBB = BollingerBands().LowerBand;
def macd = MACD();
def rsi = RSI();
def stochastic = StochasticFull();
def volumeAvg = Average(volume, 20);

# Fundamental indicators
def marketCap = Fundamental(FundamentalType.MARKETCAP);
def revenue = Fundamental(FundamentalType.REVENUE);
def grossProfitMargin = Fundamental(FundamentalType.GROSSPROFITMARGIN);
def netProfitMargin = Fundamental(FundamentalType.NETPROFITMARGIN);
def eps = Fundamental(FundamentalType.EARNINGS);

# Technical breakout criteria
def technicalBreakout =
if "ADX" in technicalIndicators and adx > technicalBreakoutThreshold then 1 else 0 +
if "ATR" in technicalIndicators and close > close[1] + (atr * technicalBreakoutThreshold) then 1 else 0 +
if "Bollinger Bands" in technicalIndicators and close > upperBB then 1 else if close < lowerBB then -1 else 0 +
if "MACD" in technicalIndicators and macd > 0 then 1 else if macd < 0 then -1 else 0 +
if "RSI" in technicalIndicators and rsi > 50 then 1 else if rsi < 50 then -1 else 0 +
if "Stochastic" in technicalIndicators and stochastic > 80 then 1 else if stochastic < 20 then -1 else 0 +
if "Volume Average" in technicalIndicators and volume > volumeAvg * technicalBreakoutThreshold then 1 else 0;

# Fundamental breakout criteria
def fundamentalBreakout =
if marketCap > 0 and revenue > 0 and grossProfitMargin > 0 and netProfitMargin > 0 and eps > 0 and
marketCap > marketCap[1] * fundamentalBreakoutThreshold and
revenue > revenue[1] * fundamentalBreakoutThreshold and
grossProfitMargin > grossProfitMargin[1] * fundamentalBreakoutThreshold and
netProfitMargin > netProfitMargin[1] * fundamentalBreakoutThreshold and
eps > eps[1] * fundamentalBreakoutThreshold then 1 else 0;

# Moving average criteria
def aboveMovingAverage = close > MovingAverage(movingAverageType, movingAverageLength, movingAveragePrice);

# Criteria for breakout
def breakoutCriteria = technicalBreakout + fundamentalBreakout + (aboveMovingAverage ? 1 : 0);

# Scan for stocks that meet the breakout criteria
def stocks =
if breakoutCriteria > 0 and close > 5 and volume > 500000 then 1 else 0;
 
# Filter
 
Last edited by a moderator:
Need correct code

# Volume Profile Order Flow Cumulative Delta and Imbalance Indicator with Arrows

input vpRange = 10; # Volume Profile range
input imbalanceThreshold = 500; # Order flow imbalance threshold

def vp = VolumeProfile("startNewProfile" = yes, "onExpansion" = no, "numberOfProfiles" = vpRange);
def delta = close - close[1];
def cumDelta = Sum(delta, vpRange);
def imbalance = cumDelta > imbalanceThreshold ? 1 : cumDelta < -imbalanceThreshold ? -1 : 0;

# Draw arrows for potential reversal and breakout points
AddChartBubble(imbalance > 0 and close < vp.lowestPrice, vp.lowestPrice, "Buy", Color.Green, yes);
AddChartBubble(imbalance < 0 and close > vp.highestPrice, vp.highestPrice, "Sell", Color.Red, yes);
AddChartBubble(close[1] < vp.highestPrice and close > vp.highestPrice, vp.highestPrice, "Buy Breakout", Color.Green, no);
AddChartBubble(close[1] > vp.lowestPrice and close < vp.lowestPrice, vp.lowestPrice, "Sell Breakout", Color.Red, no);

reply to post67
if you are going to ask strangers for help , please type a lot more than 'need correct code'
if you can't take the time to explain what you are trying to do, why should others try to guess and help?


i don't use volumeprofile code to often, so i'm not familiar with all the parameters/variables used in the study.
i got rid of the errors, but it doesn't draw anything. so it's probably missing several things.

maybe after you elaborate, someone can take this to the next step and possibly working.

Code:
# chat_profile1

# https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-122933
# post67


# Volume Profile Order Flow Cumulative Delta and Imbalance Indicator with Arrows

input vpRange = 10; # Volume Profile range
input imbalanceThreshold = 500; # Order flow imbalance threshold

#def vp = VolumeProfile("startNewProfile" = yes, "onExpansion" = no, "numberOfProfiles" = vpRange);
profile vp = VolumeProfile("startNewProfile" = yes, "onExpansion" = no, "numberOfProfiles" = vpRange);
def delta = close - close[1];
def cumDelta = Sum(delta, vpRange);
#def imbalance = cumDelta > imbalanceThreshold ? 1 : cumDelta < -imbalanceThreshold ? -1 : 0;
def imbalance = if cumDelta > imbalanceThreshold then 1 else if cumDelta < -imbalanceThreshold then -1 else 0;

def phi = if isnan(vp.gethighest()) then phi[1] else vp.gethighest();
def plo = if isnan(vp.getlowest()) then plo[1] else vp.getlowest();


#vp.show(globalColor("Profile"), if showPointOfControl then globalColor("Point Of Control") else color.current, if showValueArea then globalColor("Value Area") else color.current, opacity);
vp.show(globalColor("Profile"), color.current, color.current);


# Draw arrows for potential reversal and breakout points
AddChartBubble(imbalance > 0 and close < plo, plo, "Buy", Color.Green, yes);
AddChartBubble(imbalance < 0 and close > phi, phi, "Sell", Color.Red, yes);
AddChartBubble(close[1] < phi and close > phi, phi, "Buy Breakout", Color.Green, no);
AddChartBubble(close[1] > plo and close < plo, plo, "Sell Breakout", Color.Red, no);
#
 
This is the code ChatGPD gave me. It does not work though. I asked to do it many many times different ways but could not get it to work. Any help would be amazing! All of these versions gave errors

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;

def lastPrice = close[1];
def color;

if (close > lastPrice) {
color = uptickColor; } else if (close < lastPrice) {
color = downtickColor; } else {
color = neutralColor; }

AddLabel(yes, "Bid: " + Round(bid, 2), color);


Also this was a version..

# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color = if bidPrice > lastPrice then uptickColor else if bidPrice < lastPrice then downtickColor else neutralColor;

# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), if color == uptickColor then uptickColor else if color == downtickColor then downtickColor else neutralColor);

Also

# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color;
if bidPrice > lastPrice {
color = uptickColor;
} else if bidPrice < lastPrice {
color = downtickColor;
} else {
color = neutralColor;
}

# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), color);
 
This is the code ChatGPD gave me. It does not work though. I asked to do it many many times different ways but could not get it to work. Any help would be amazing! All of these versions gave errors

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;

def lastPrice = close[1];
def color;

if (close > lastPrice) {
color = uptickColor; } else if (close < lastPrice) {
color = downtickColor; } else {
color = neutralColor; }

AddLabel(yes, "Bid: " + Round(bid, 2), color);


Also this was a version..

# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color = if bidPrice > lastPrice then uptickColor else if bidPrice < lastPrice then downtickColor else neutralColor;

# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), if color == uptickColor then uptickColor else if color == downtickColor then downtickColor else neutralColor);

Also

# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color;
if bidPrice > lastPrice {
color = uptickColor;
} else if bidPrice < lastPrice {
color = downtickColor;
} else {
color = neutralColor;
}

# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), color);

reply to post70
do what?
you didn't tell us what 'it' is.
edit your post and add a sentence describing what you are trying to do.
 
Last edited:
Hello,

Here are the words used to generate the ChatGBT script:
"THINKORSWIM SCRIPT SUPPLY AND DEMAND"


And here is ChatGBT's response to the above words:
"Here's an example script in ThinkScript that can help you identify areas of supply and demand:"
This script calculates and plots supply and demand zones on the chart based on the previous high and low prices within a certain length and deviation range. Supply zones are indicated by a magenta dashed line, while demand zones are indicated by a green dashed line.

You can customize the input length and deviation to fit your trading style and preferences. Additionally, you can combine this script with volume profile indicators to further refine your analysis of supply and demand zones.

Maybe this might help develop a better more concise script for supply and demand...


Code:
# Supply and Demand Zone Indicator
#Created by ChatGBT by asking it "THINKORSWIM SCRIPT SUPPLY AND DEMAND."


input length = 10;
input deviation = 1.5;

def priceHigh = high;
def priceLow = low;

def priceMedian = (priceHigh + priceLow) / 2;

def priceDeviation = deviation * stdev(priceMedian, length);

def supplyZone = if priceHigh[1] >= highest(priceHigh, length)[1] and
                   priceLow[1] >= highest(priceLow, length)[1] - priceDeviation[1]
                   then 1 else 0;

def demandZone = if priceLow[1] <= lowest(priceLow, length)[1] and
                   priceHigh[1] <= lowest(priceHigh, length)[1] + priceDeviation[1]
                   then 1 else 0;

plot supplyZoneLine = if supplyZone then highest(priceLow, length) - priceDeviation else Double.NaN;
supplyZoneLine.SetStyle(curve.short_DASH);
supplyZoneLine.SetLineWeight(2);
supplyZoneLine.SetDefaultColor(Color.MAGENTA);

plot demandZoneLine = if demandZone then lowest(priceHigh, length) + priceDeviation else Double.NaN;
demandZoneLine.SetStyle(curve.short_DASH);
demandZoneLine.SetLineWeight(2);
demandZoneLine.SetDefaultColor(Color.GREEN);


Image:
 
Last edited by a moderator:
Hello,

Here are the words used to generate the ChatGBT script:



And here is ChatGBT's response to the above words:



Maybe this might help develop a better more concise script for supply and demand...


Code:
# Supply and Demand Zone Indicator
#Created by ChatGBT by asking it "THINKORSWIM SCRIPT SUPPLY AND DEMAND."


input length = 10;
input deviation = 1.5;

def priceHigh = high;
def priceLow = low;

def priceMedian = (priceHigh + priceLow) / 2;

def priceDeviation = deviation * stdev(priceMedian, length);

def supplyZone = if priceHigh[1] >= highest(priceHigh, length)[1] and
                   priceLow[1] >= highest(priceLow, length)[1] - priceDeviation[1]
                   then 1 else 0;

def demandZone = if priceLow[1] <= lowest(priceLow, length)[1] and
                   priceHigh[1] <= lowest(priceHigh, length)[1] + priceDeviation[1]
                   then 1 else 0;

plot supplyZoneLine = if supplyZone then highest(priceLow, length) - priceDeviation else Double.NaN;
supplyZoneLine.SetStyle(curve.short_DASH);
supplyZoneLine.SetLineWeight(2);
supplyZoneLine.SetDefaultColor(Color.MAGENTA);

plot demandZoneLine = if demandZone then lowest(priceHigh, length) + priceDeviation else Double.NaN;
demandZoneLine.SetStyle(curve.short_DASH);
demandZoneLine.SetLineWeight(2);
demandZoneLine.SetDefaultColor(Color.GREEN);


don't need to reinvent the wheel.
instead of asking for what already exists, try searching for it.

supply and demand
https://usethinkscript.com/search/1141026/?q=supply+and+demand&o=date

----------------------------

i modified the code in post72,
to draw clouds,
at the highest and lowest points of supply, demand plots


Code:
# chat72_supply_demand_01

# https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-124012
#post72

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

input length = 10;
input deviation = 1.5;

def priceHigh = high;
def priceLow = low;

def priceMedian = (priceHigh + priceLow) / 2;

def priceDeviation = deviation * stdev(priceMedian, length);

def supplyZone = if priceHigh[1] >= highest(priceHigh, length)[1] and
priceLow[1] >= highest(priceLow, length)[1] - priceDeviation[1]
then 1 else 0;

def demandZone = if priceLow[1] <= lowest(priceLow, length)[1] and
priceHigh[1] <= lowest(priceHigh, length)[1] + priceDeviation[1]
then 1 else 0;

def sz = highest(priceLow, length) - priceDeviation;
def dz = lowest(priceHigh, length) + priceDeviation;

plot supplyZoneLine = if supplyZone then sz else Double.NaN;
supplyZoneLine.SetStyle(curve.short_DASH);
supplyZoneLine.SetLineWeight(2);
supplyZoneLine.SetDefaultColor(Color.MAGENTA);

plot demandZoneLine = if demandZone then dz else Double.NaN;
demandZoneLine.SetStyle(curve.short_DASH);
demandZoneLine.SetLineWeight(2);
demandZoneLine.SetDefaultColor(Color.GREEN);

#---------------------------------
# supply zones

def big = 99999;
def w = 50;
def supplytop;
def supplybot;
if bn == 1 then {
 supplytop = 0;
 supplybot = 0;
} else if !supplyzone[1] and supplyzone[0] and supplyzone[-1] then {
# first supplyzone of several...
 supplytop = fold i1 = 0 to w
  with p1
  while getvalue(supplyzone, -i1)
  do max(p1, getvalue(sz, -i1));

 supplybot = fold i2 = 0 to w
  with p2 = big
  while getvalue(supplyzone, -i2)
  do min(p2, getvalue(sz, -i2));
} else {
 supplytop = supplytop[1];
 supplybot = supplybot[1];
}


plot zstop = if isnan(close) or supplytop == 0 then na else if supplytop > 0 then supplytop else na;
zstop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zstop.SetDefaultColor(Color.gray);
zstop.setlineweight(1);
zstop.hidebubble();

plot zsbot = if isnan(close) or supplybot == 0 then na else if supplybot > 0 then supplybot else na;
zsbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zsbot.SetDefaultColor(Color.gray);
zsbot.setlineweight(1);
zsbot.hidebubble();


def stop = if isnan(close) then na else if bn >= 1 then zstop else 0;
def sbot = if isnan(close) then na else if bn >= 1 then zsbot else 0;

addcloud(stop, sbot , color.magenta);


#---------------------------------
# demand zones

#def big = 99999;
#def w = 50;
def demandtop;
def demandbot;
if bn == 1 then {
 demandtop = 0;
 demandbot = 0;
} else if !demandzone[1] and demandzone[0] and demandzone[-1] then {
# first demandzone of several...
 demandtop = fold i3 = 0 to w
  with p3
  while getvalue(demandzone, -i3)
  do max(p3, getvalue(dz, -i3));

 demandbot = fold i4 = 0 to w
  with p4 = big
  while getvalue(demandzone, -i4)
  do min(p4, getvalue(dz, -i4));
} else {
 demandtop = demandtop[1];
 demandbot = demandbot[1];
}


plot zdtop = if isnan(close) or demandtop == 0 then na else if demandtop > 0 then demandtop else na;
zdtop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdtop.SetDefaultColor(Color.gray);
zdtop.setlineweight(1);
zdtop.hidebubble();

plot zdbot = if isnan(close) or demandbot == 0 then na else if demandbot > 0 then demandbot else na;
zdbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdbot.SetDefaultColor(Color.gray);
zdbot.setlineweight(1);
zdbot.hidebubble();


def dtop = if isnan(close) then na else if bn >= 1 then zdtop else 0;
def dbot = if isnan(close) then na else if bn >= 1 then zdbot else 0;

addcloud(dtop, dbot , color.green);

#---------------------------------
# test stuff

addchartbubble(0, low,
 supplytop + "\n" +
 supplybot + "\n" +
 demandtop + "\n" +
 demandbot
, color.yellow, no);



# supplyzone   demandzone

# find values of 1 , 2+ more in a row
addchartbubble(0, low*0.99,
supplyzone + "\n" +
demandzone
, color.yellow, no);
#

clouds , at highest and lowest points of supply, demand plots
QNL6NHz.jpg
 
Last edited:
This is the code ChatGPD gave me. It does not work though. I asked to do it many many times different ways but could not get it to work. Any help would be amazing! All of these versions gave errors

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;

def lastPrice = close[1];
def color;

if (close > lastPrice) {
color = uptickColor; } else if (close < lastPrice) {
color = downtickColor; } else {
color = neutralColor; }

AddLabel(yes, "Bid: " + Round(bid, 2), color);


Also this was a version..

# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color = if bidPrice > lastPrice then uptickColor else if bidPrice < lastPrice then downtickColor else neutralColor;

# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), if color == uptickColor then uptickColor else if color == downtickColor then downtickColor else neutralColor);

Also

# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);

# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color;
if bidPrice > lastPrice {
color = uptickColor;
} else if bidPrice < lastPrice {
color = downtickColor;
} else {
color = neutralColor;
}

# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), color);

reply to post70

can't assign colors to a variable
you didn't assign a variable bid. i changed it to lastclose

Code:
def lastPrice = close[1];
AddLabel(yes, "last price: " + Round(lastprice, 2), 
(if (close > lastPrice) then Color.GREEN
else if (close < lastPrice) then Color.RED
else  Color.GRAY));
#
 
I am trying to create an indicator that will place clouds at a price level when the stochastic D period is oversold/overbought and the 50 EMA is above or below the 200 EMA. I keep getting an invalid statement error. I used ChatGpt to write this as I do not know how to code. Can one of you genius coders help me to fix the code? Thanks in advance.

Invalid statement: AddCloud at 24:1
Invalid statement: AddCloud at 25:1

Code:
# TOS Indicator for Stochastic and Moving Average Clouds

input length = 14;
input kPeriod = 3;
input dPeriod = 3;
input overbought = 80;
input oversold = 20;
input cloudExtension = 20;

def StochasticD = StochasticFullD(length, kPeriod, dPeriod);

def ma50 = ExpAverage(close, 50);
def ma200 = ExpAverage(close, 200);

def isOverbought = StochasticD > overbought and ma200 < ma50;
def isOversold = StochasticD < oversold and ma50 < ma200;

plot OB = if isOverbought then ma200 else Double.NaN;
plot OS = if isOversold then ma50 else Double.NaN;

OB.SetDefaultColor(Color.LIGHT_RED);
OS.SetDefaultColor(Color.LIGHT_GREEN);

AddCloud(if isOverbought then ma200 else Double.NaN, ma200, Color.LIGHT_RED, Color.LIGHT_RED).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_RED).SetHiding(cloudExtension, cloudExtension);
AddCloud(if isOversold then ma50 else Double.NaN, ma50, Color.LIGHT_GREEN, Color.LIGHT_GREEN).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_GREEN).SetHiding(cloudExtension, cloudExtension);

AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.CURRENT);
 
I am trying to create an indicator that will place clouds at a price level when the stochastic D period is oversold/overbought and the 50 EMA is above or below the 200 EMA. I keep getting an invalid statement error. I used ChatGpt to write this as I do not know how to code. Can one of you genius coders help me to fix the code? Thanks in advance.

Invalid statement: AddCloud at 24:1
Invalid statement: AddCloud at 25:1

Code:
# TOS Indicator for Stochastic and Moving Average Clouds

input length = 14;
input kPeriod = 3;
input dPeriod = 3;
input overbought = 80;
input oversold = 20;
input cloudExtension = 20;

def StochasticD = StochasticFullD(length, kPeriod, dPeriod);

def ma50 = ExpAverage(close, 50);
def ma200 = ExpAverage(close, 200);

def isOverbought = StochasticD > overbought and ma200 < ma50;
def isOversold = StochasticD < oversold and ma50 < ma200;

plot OB = if isOverbought then ma200 else Double.NaN;
plot OS = if isOversold then ma50 else Double.NaN;

OB.SetDefaultColor(Color.LIGHT_RED);
OS.SetDefaultColor(Color.LIGHT_GREEN);

AddCloud(if isOverbought then ma200 else Double.NaN, ma200, Color.LIGHT_RED, Color.LIGHT_RED).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_RED).SetHiding(cloudExtension, cloudExtension);
AddCloud(if isOversold then ma50 else Double.NaN, ma50, Color.LIGHT_GREEN, Color.LIGHT_GREEN).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_GREEN).SetHiding(cloudExtension, cloudExtension);

AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.CURRENT);


reply to post75
( @MerryDay , these is no post 75, but 2 - post 76's ?)

just because a stoch value is high, doesn't mean price will drop.

several things wrong in original code.
look through code below to see working code.


this is wrong. StochasticFullD is not a valid function name
def StochasticD = StochasticFullD(length, kPeriod, dPeriod);
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/StochasticFull


these formulas would only plot tiny segments of average lines, not complete lines
plot ob =
plot os =


AddCloud()'s had same number for top and bottom... so nothing was plotted
addcloud()'s has bad code appended to the end of them

i changed default candle color to gray, so colored candles will be easy to see

Code:
# chat76_stoch_00

#https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-123384
#Bob007  #76

#I am trying to create an indicator that will place clouds at a price level when the stochastic D period is oversold/overbought and the 50 EMA is above or below the 200 EMA. I keep getting an invalid statement error. I used ChatGpt to write this as I do not know how to code. Can one of you genius coders help me to fix the code? Thanks in advance.

# TOS Indicator for Stochastic and Moving Average Clouds

input length = 14;
input kPeriod = 3;
input dPeriod = 3;
input overbought = 80;
input oversold = 20;
input cloudExtension = 20;

#def StochasticD = StochasticFullD(length, kPeriod, dPeriod);
def StochasticD = StochasticFull(length, kPeriod, dPeriod).fulld;

def ma50 = ExpAverage(close, 50);
def ma200 = ExpAverage(close, 200);

def isOverbought = StochasticD > overbought and ma200 < ma50;
def isOversold = StochasticD < oversold and ma50 < ma200;

#plot OB = if isOverbought then ma200 else Double.NaN;
#plot OS = if isOversold then ma50 else Double.NaN;
#OB.SetDefaultColor(Color.LIGHT_RED);
#OS.SetDefaultColor(Color.LIGHT_GREEN);

# change it so all of average lines are drawn
plot OB = ma200;
plot OS = ma50;
ob.AssignValueColor(if isOverbought then color.magenta else color.dark_gray);
os.AssignValueColor(if isOversold then color.green else color.dark_gray);
ob.setlineweight(2);
os.setlineweight(2);

#AddCloud(if isOverbought then ma200 else Double.NaN, ma200, Color.LIGHT_RED, Color.LIGHT_RED).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_RED).SetHiding(cloudExtension, cloudExtension);

#AddCloud(if isOversold then ma50 else Double.NaN, ma50, Color.LIGHT_GREEN, Color.LIGHT_GREEN).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_GREEN).SetHiding(cloudExtension, cloudExtension);

AddCloud((if isOverbought then ma200 else Double.NaN), ma50, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud((if isOversold then ma50 else Double.NaN), ma200, Color.LIGHT_GREEN, color.LIGHT_GREEN);

#AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.CURRENT);
AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.gray);

#

YXAJoH6.jpg
 
I am trying to write a simple script to pull the price of a specific option using thinkscript but I am running into an error I am not sure how to get around. Any help?

# Define the option symbol and expiration date
def symbol = "CMG";
def expirationDate = 20230505;

# Define the strike price
def strikePrice = 1500;

# Get the current option price
optionPrice = close(symbol = symbol, period = "DAY", optionType = OptionType.CALL, expirationdate = expirationDate, strike = strikePrice);


And then I also wanted the live stock price for the same symbol and was using:

# Get the current stock price
def stockPrice = close(symbol);

but this is returning errors as well.

any help?

Thank you
 
I'm trying to fix the errors I get but unfortunately I failed. Thank you!!!

input length = 233;
input showLevels = yes;
input showLabels = yes;

def wave = ElliottWave(length);

# Plot waves and labels
plot waveCount = wave;

def wave = if !IsNaN(close) then
if !IsNaN(wave[-1]) and wave[-1] != 0 then
if wave[-1] > 0 and close < low[-1] then wave[-1] + 1
else if wave[-1] < 0 and close > high[-1] then wave[-1] - 1
else wave[-1]
else 0
else Double.NaN;

plot waveCount = if !IsNaN(wave) and showLabels then wave else Double.NaN;

if showLabels then {
if wave > wave[1] then {
waveCount.SetDefaultColor(Color.GREEN);
} else {
waveCount.SetDefaultColor(Color.RED);
}
AddLabel(yes, "Wave " + wave, if wave > wave[1] then Color.GREEN else Color.RED);
}


def lowValue = Lowest(low, length);
def highValue = Highest(high, length);

def retracementLevels = (highValue - lowValue) *
(0.236, 0.382, 0.5, 0.618, 0.786, 1.0, 1.236, 1.382, 1.618);

plot retracement = if showLevels then retracementLevels else Double.NaN;

if showLevels then {
retracement.SetDefaultColor(Color.LIGHT_GRAY);
AddChartBubble(high, 0.236, "23.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.382, "38.2%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.5, "50%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.618, "61.8%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.786, "78.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.0, "100%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.236, "123.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.382, "138.2%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.618, "161.8%", Color.LIGHT_GRAY, no);
}
 
I have tried to write a script that counts Fair Value Gaps on whatever time frame the aggregation period is set to. The code is returning a few errors and I can't seem to figure out how to get rid of the errors. Any help or guidance woiuld be greatly appreciated. The code is posted below with my notes for each section:

#ThinkScript for FVG label to count like a sequence counter
#Counts consecutive positive or negative, when the direction changes the previous direction resets to zero
#There are still errors in this code that I am trying to chase down

# Inputs default at daily chart
#For 1 minute chart change to timeframe = AggregationPeriod.MIN
#For 5 minute chart change to timeframe = AggregationPeriod.FIVE_MIN
#For 1 day chart change to timeframe = AggregationPeriod.DAY

input timeframe = AggregationPeriod.MIN;
input fairValue = 0.0;

# Calculate Fair Value Gap
def high1 = high(period = timeframe)[1];
def low1 = low(period = timeframe)[1];
def high3 = high(period = timeframe)[3];
def low3 = low(period = timeframe)[3];
def fairValueGap = if high1 < low3 then 1 else if low1 > high3 then -1 else 0;

# Track Consecutive Positive and Negative Gaps
def consecutivePositiveGaps = if fairValueGap == 1 then Max(1, consecutivePositiveGaps[1] + 1) else 0;
def consecutiveNegativeGaps = if fairValueGap == -1 then Max(1, consecutiveNegativeGaps[1] + 1) else 0;

# Plot Rectangle and Label with Sequence Counter
def isPositiveGap = fairValueGap == 1;
def isNegativeGap = fairValueGap == -1;
def positiveGapLabel = "+FVG " + consecutivePositiveGaps;
def negativeGapLabel = "-FVG " + consecutiveNegativeGaps;
AddChartBubble(isPositiveGap, low3, positiveGapLabel, Color.GREEN, no);
AddChartBubble(isNegativeGap, high3, negativeGapLabel, Color.RED, no);
AddVerticalLine(isPositiveGap, low3, high1, Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(isNegativeGap, high3, low1, Color.RED, Curve.SHORT_DASH);
AddCloud(isPositiveGap, low3, high1, Color.GREEN, Color.LIGHT_GRAY);
AddCloud(isNegativeGap, high3, low1, Color.RED, Color.LIGHT_GRAY);
 
I'm trying to fix the errors I get but unfortunately I failed. Thank you!!!

input length = 233;
input showLevels = yes;
input showLabels = yes;

def wave = ElliottWave(length);

# Plot waves and labels
plot waveCount = wave;

def wave = if !IsNaN(close) then
if !IsNaN(wave[-1]) and wave[-1] != 0 then
if wave[-1] > 0 and close < low[-1] then wave[-1] + 1
else if wave[-1] < 0 and close > high[-1] then wave[-1] - 1
else wave[-1]
else 0
else Double.NaN;

plot waveCount = if !IsNaN(wave) and showLabels then wave else Double.NaN;

if showLabels then {
if wave > wave[1] then {
waveCount.SetDefaultColor(Color.GREEN);
} else {
waveCount.SetDefaultColor(Color.RED);
}
AddLabel(yes, "Wave " + wave, if wave > wave[1] then Color.GREEN else Color.RED);
}


def lowValue = Lowest(low, length);
def highValue = Highest(high, length);

def retracementLevels = (highValue - lowValue) *
(0.236, 0.382, 0.5, 0.618, 0.786, 1.0, 1.236, 1.382, 1.618);

plot retracement = if showLevels then retracementLevels else Double.NaN;

if showLevels then {
retracement.SetDefaultColor(Color.LIGHT_GRAY);
AddChartBubble(high, 0.236, "23.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.382, "38.2%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.5, "50%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.618, "61.8%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.786, "78.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.0, "100%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.236, "123.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.382, "138.2%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.618, "161.8%", Color.LIGHT_GRAY, no);
}

reply to post78

i don't think there is an elliot wave study anywhere on the site.
there is an oscilator that is built in and some mods to it here,
https://usethinkscript.com/threads/elliot-wave-indicator-for-thinkorswim.1110/

so, i don't think your request is possible, ( not for free anyway , as it would take many hours to code something)


there are several errors,

no such function - elliotwave() , so right off the bat, it's not fixable.
def wave = ElliottWave(length);

can't set colors/outputs within an if then. can only set a number.

can't multiply by an array of numbers.
 
I am trying to write a simple script to pull the price of a specific option using thinkscript but I am running into an error I am not sure how to get around. Any help?

# Define the option symbol and expiration date
def symbol = "CMG";
def expirationDate = 20230505;

# Define the strike price
def strikePrice = 1500;

# Get the current option price
optionPrice = close(symbol = symbol, period = "DAY", optionType = OptionType.CALL, expirationdate = expirationDate, strike = strikePrice);


And then I also wanted the live stock price for the same symbol and was using:

# Get the current stock price
def stockPrice = close(symbol);

but this is returning errors as well.

any help?

Thank you

reply to post77

hello,
you 'get around' errors by looking up functions in the manual and seeing if they exist and seeing what the valid parameters are.


close has 3 parameters. no option related ones.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals/close


try using this one
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Option-Related/OptionPrice
OptionPrice ( strike, isPut, daysToExpiration, underlyingPrice, Volatility, isEuropean, yield, interestRate);


i threw this together to generate a number. you can research and take it from here.

i used a constant for the days (7) to expire. so it should work for today.
you can experiment with date functions and come up with a formula to use in its place.

i used a simple version for implied volitility. there is a longer formula in the example for optionprice()


Code:
# chat77_option_price

#https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-123458
#post77
#degenjay

#I am trying to write a simple script to pull the price of a specific option using thinkscript but I am running into an error I am not sure how to get around. Any help?

# Define the option symbol and expiration date
input symbol = "CMG";
def expirationDate = 20230505;

# Define the strike price
def strikePrice = 1500;

# Get the current option price
#optionPrice = close(symbol = symbol, period = "DAY", optionType = OptionType.CALL, expirationdate = expirationDate, strike = strikePrice);

def iv = imp_volatility(symbol);

#try using this one
#https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Option-Related/OptionPrice
def op = OptionPrice( strike = strikePrice , isPut = no, daysToExpiration = 7, underlyingPrice = close(symbol), Volatility = iv, isEuropean = no);
#, yield,  interestRate);  


addlabel(1, " ", color.black);
addlabel(1, "stock " + symbol, color.yellow);
addlabel(1, "option price " + op, color.yellow);


#-------------------------
#And then I also wanted the live stock price for the same symbol and was using:

# Get the current stock price
def stockPrice = close(symbol);

addlabel(1, "stock price " + stockprice, color.yellow);
#
 
Last edited:

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