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
# 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);
#
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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);
#chat79_fvg_mtf
#https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-123506
#theYaniac
#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;
AddLabel(1, "+FVG " + consecutivePositiveGaps, Color.YELLOW);
AddLabel(1, "-FVG " + consecutiveNegativeGaps , Color.YELLOW);
#AddChartBubble(isPositiveGap, low3, positiveGapLabel, Color.GREEN, no);
#AddChartBubble(isNegativeGap, high3, negativeGapLabel, Color.RED, no);
AddChartBubble(isPositiveGap, low3, consecutivePositiveGaps, Color.GREEN, no);
AddChartBubble(isNegativeGap, high3, consecutiveNegativeGaps, Color.RED, no);
#AddVerticalLine(isPositiveGap, low3, high1, Color.GREEN, Curve.SHORT_DASH);
#AddVerticalLine(isNegativeGap, high3, low1, Color.RED, Curve.SHORT_DASH);
# AddVerticalLine ( visible, text, color, stroke);
AddVerticalLine(isPositiveGap, high1, Color.GREEN, Curve.SHORT_DASH);
AddVerticalLine(isNegativeGap, low1, Color.RED, Curve.SHORT_DASH);
#AddCloud(isPositiveGap, low3, high1, Color.GREEN, Color.LIGHT_GRAY);
#AddCloud(isNegativeGap, high3, low1, Color.RED, Color.LIGHT_GRAY);
AddCloud(isPositiveGap, low3, Color.GREEN, Color.LIGHT_GRAY);
AddCloud(isNegativeGap, high3, Color.RED, Color.LIGHT_GRAY);
#
ChatGPT works. Way better than bard. Chat works best when given think script examples in my opinion but it can create code that is accepted by the software just doesnt actually do anything or at least I cant get it to.@JoeDV You already got access to Google Bard? That was quick. I'm still on the waiting list, haha.
How is it compare to ChatGPT when it comes to thinkScripting?
Whats the trick asking questions to the AI so it doesnt "wander" with the code language?
Ive tried: Using thinkscript create .... but it still uses code that doesnt work??
there is no trick,
it
doesn't
work
it
doesn't
understand
thinkscript
it
will
not
create
a
functional
complicated
study
if you want a study, learn the language and create it.
ChatGPT seems to be getting better by the day. But no it cant create complex code like you guys. I feed it your code and it uses it to create what I need. I Don't know how considering it claims it doesn't use think script. But it works. 10 years away from anything useful? I suppose you're protecting your position, but it's obvious this will certainly hurt some jobs. This is probably the toy version of what the military has and I doubt we will ever see that. It took decades for us to see this. Anyway great website here always useful.just my opinion.
i think we are a decade away from having anything useful.
it does seem odd, that chatgpt, a program, written by programmers, does poorly at creating programs, while being able to create literature....
there is no trick,
it
doesn't
work
it
doesn't
understand
thinkscript
it
will
not
create
a
functional
complicated
study
if you want a study, learn the language and create it.
1. The amazing contributors of the forum provide their expertise gratis; they have "no position" to protect.ChatGPT seems to be getting better by the day. But no it cant create complex code like you guys. I feed it your code and it uses it to create what I need. I Don't know how considering it claims it doesn't use think script. But it works. 10 years away from anything useful? I suppose you're protecting your position, but it's obvious this will certainly hurt some jobs. This is probably the toy version of what the military has and I doubt we will ever see that. It took decades for us to see this. Anyway great website here always useful.
I'm trying to use chatgpt to code because I'm illiterate basically when it comes to coding. But If i can get this going that would be amazing and I'll post my VSA code that is working really well. I'm trying to get a tradingview indicator by lonesomeblue consolidation box live to convert:
The script is also capable of identifying three potential directions that the price may move after breaking out of the consolidation zone. These directions are:
If the price bounces off the median price line, the script labels the trend direction it will be going with momentum or breaking out. The same goes for when the price does not reverse outside the consolidation box.
- Moving outside the consolidation zone above or below the high or low of the consolidation box area and then reversing back the entire distance of the box in the opposite direction.
- Moving outside the consolidation zone and continuing to go up with a lot of momentum.
- Reversing to the median price point after going up and then coming down.
input prd = 10;
input conslen = 5;
input paintcons = yes;
input zonecol = color.blue;
def hb_ = highestbars(prd) == 0 ? high : Double.NaN;
def lb_ = lowestbars(prd) == 0 ? low : Double.NaN;
def dir = 0;
def zz = Double.NaN;
def pp = Double.NaN;
dir = if (hb_ and !isNaN(lb_)) then 1
else if (lb_ and !isNaN(hb_)) then -1
else dir;
if (hb_ and lb_) {
if (dir == 1) {
zz = hb_;
} else {
zz = lb_;
}
} else {
zz = if (hb_) then hb_
else if (lb_) then lb_
else Double.NaN;
}
def condhigh = if (dir == 1) then highest(conslen) else Double.NaN;
def condlow = if (dir == -1) then lowest(conslen) else Double.NaN;
def consArea = if (paintcons) then zonecol else color.white;
AddCloud(condhigh, condlow, consArea);
def breakoutup = if high > condhigh and low > condlow then yes else no;
def breakoutdown = if low < condlow and high < condhigh then yes else no;
def upmomentum = if high > condhigh and low <= condhigh then yes else no;
def downmomentum = if low < condlow and high >= condlow then yes else no;
Alert(breakoutup, "Breakout Up", Alert.BAR, Sound.Ding);
Alert(breakoutdown, "Breakout Down", Alert.BAR, Sound.Ding);
Alert(upmomentum, "Up Momentum", Alert.BAR, Sound.Chimes);
Alert(downmomentum, "Down Momentum", Alert.BAR, Sound.Chimes);
that's great if it can provide something useful for your project.ChatGPT seems to be getting better by the day. But no it cant create complex code like you guys. I feed it your code and it uses it to create what I need. I Don't know how considering it claims it doesn't use think script. But it works. 10 years away from anything useful? I suppose you're protecting your position, but it's obvious this will certainly hurt some jobs. This is probably the toy version of what the military has and I doubt we will ever see that. It took decades for us to see this. Anyway great website here always useful.
I meant protecting position is the sense you would feel more passionate about the coding and this field, more so than a person like me. Not necessarily monetarily. I feel it's extracting more info to be used for its own gain of course. It's helping me learn code I would say. One other oddity is sometimes it takes many reiterations of a code before its gets the solution, feeding it the thinkscript errors so it can correct. But sometimes I can request literally in layman's terms what I want to accomplish and it creates it right off the bat without any problems. I also believe the AI is narrative based but can be manipulated to provide an answer in keeping with ones own thinking. It will say one thing but then after interaction with it you can prove your point with its passed answers and cause a correction in its own conclusions. I dont believe at all it thinks. It's garbage in garbage out. This may be stating the obvious, but the whole sentient concept exists IMO for a future where they can blame AI for whatever engineered crisis they have coming next.that's great if it can provide something useful for your project.
i agree, new technology always seems to shift the job market, usually to something more automated related.
my beef with it is, people who don't know any thinkscript are asking it to generate a code, and expect it to work, and it doesn't. i think a tool shouldn't exist until it works.
i have no position to protect. i'm just a guy, doing a hobby. i have random pockets of free time, that i like to use to volunteer on this site, to help out others.
I posted another reply to @halcyonguy before I read this one.1. The amazing contributors of the forum provide their expertise gratis; they have "no position" to protect.
2. Historically, technology advances create more, albeit different opportunities.
3. chatGPT will reach a point in the future, where it will be able to create complex scripts.
It will be a matter of garbage-in-garbage-out. Just like on this forum; we and chatGPT will only be able to provide good detailed studies when we are given good detailed specifications.
4. The best ThinkScript sites on the internet are not about the scripts. The good sites provide the support for the scripts and education in their use in trading. So chatGPT will be providing more scripts which will provide opportunity for more discussion which grows the whole ThinkScript community.
@halcyonguy's point is that chatGPT is NOT there yet.
Besides the issues with chatGPT current shortcomings,
90% of the members submitting the chatGPT scripts here; not only do not provide good detailed specifications; they provide no specifications.
This results in frustrations on the part of the members and the contributors.
This is typical. chatGPT still has many growing pains ahead.
I told Chat GPT to create a thinkscript for me. I entered it on thinkorswim but Its not working. I do not know how to code. Any help will be appreciated.
The message that I receive at the bottom of the screen
No such function: scan at 28:1
No Such function: scan at 28:1
Incompatible parameter: scanCriteria at 25:5
# Scan for stocks that are about to breakout
input length = 20; # Lookback period for the breakout
input threshold = 0.9; # Minimum breakout threshold
def priceHigh = high;
def priceLow = low;
def priceClose = close;
def highestHigh = Highest(priceHigh, length);
def lowestLow = Lowest(priceLow, length);
def priceRange = highestHigh - lowestLow;
def breakoutLevel = priceClose + (priceRange * threshold);
def isBreakout = priceClose > breakoutLevel;
def futureHigh = Highest(priceHigh[1], length);
def futureLow = Lowest(priceLow[1], length);
def futureRange = futureHigh - futureLow;
def breakoutLevelFuture = priceClose[1] + (futureRange * threshold);
def isFutureBreakout = priceClose[1] > breakoutLevelFuture;
# Criteria for the scan
def scanCriteria = isFutureBreakout and !isBreakout;
# Output the scan results
scan(scanCriteria);
Thanks for the input. It totally helped.hello and welcome,
when asking strangers for help,
describe the problem, what is the question? what are you trying to do?
where do you want to see something?
chart, list, scan,...
what do you want to see?
----------
when posting code,
paste it in a code window.
click on </> in the header.
------
my guess
change last line, from this
scan(scanCriteria);
to this
plot z = scanCriteria;
hello and welcome,
when asking strangers for help,
describe the problem, what is the question? what are you trying to do?
where do you want to see something?
chart, list, scan,...
what do you want to see?
----------
when posting code,
paste it in a code window.
click on </> in the header.
------
my guess
change last line, from this
scan(scanCriteria);
to this
plot z = scanCriteria;
reply to 98I have another thinkscript assistance. It is scan to identify intraday breakouts. The error message that I receive is "No Such function: scan at 20:1" and "No such variable: stock at 20:75". Here is the thinkscript posted below
# Intraday Breakout Scan
# Define input parameters
input priceType = close;
input timeFrame = AggregationPeriod.FIVE_MIN;
input lookBack = 20;
input percentThreshold = 1;
# Calculate the high and low prices for the lookback period
def highPrice = highest(priceType, lookBack);
def lowPrice = lowest(priceType, lookBack);
# Calculate the percent change from the low to the high price
def percentChange = ((highPrice - lowPrice) / lowPrice) * 100;
# Define the scan criteria
def scanCriteria = percentChange >= percentThreshold;
# Run the scan and display the results
scan(scanCriteria, "Intraday Breakout " + percentThreshold + "%", stock = stock);
# Define the input variables
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input emaPeriod = 9;
input rsiPeriod = 14;
input vwapLength = 20;
# Define the MACD line
def MACDLine = MACD(fastLength, slowLength, MACDLength).Diff;
# Define the MACD signal line
def SignalLine = MACD(fastLength, slowLength, MACDLength).Avg;
# Define the MACD histogram
def Histogram = MACDLine - SignalLine;
# Define the 9EMA
def EMA9 = ExpAverage(close, emaPeriod);
# Define the RSI
input rsiPeriod = 14;
def RSIValue = RSI(close, rsiPeriod);
# Define the aggregation period for VWAP
def AggregationPeriod = AggregationPeriod.DAY;
# Define the VWAP
def VWAPValue = VWAP;
# Define the CCI
input cciPeriod = 14;
def CCIValue = CCI(cciPeriod);
# Define the trend direction
def Trend = if close > EMA9 then 1 else if close < EMA9 then -1 else 0;
# Initialize the trend change flag
def TrendChanged = 0;
# Determine if the trend has changed
def TrendChanged = if Trend != Trend[1] then 1 else 0;
# Define the conditions for a buy signal
def BuySignal = MACDLine > SignalLine and Histogram > 0 and close > EMA9 and RSIValue > 50 and close > VWAPValue and CCIValue > 0;
# Define the conditions for a sell signal
def SellSignal = MACDLine < SignalLine and Histogram < 0 and close < EMA9 and RSIValue < 50 and close < VWAPValue and CCIValue < 0;
# Determine if a signal should be generated
def Signal = if BuySignal and Trend > 0 and TrendChanged == 1 then 1 else if SellSignal and Trend < 0 and TrendChanged == 1 then -1 else 0;
# Update the trend direction
def NewTrend = if Signal == 1 then 1 else if Signal == -1 then -1 else Trend;
Trend = NewTrend;
# Determine if the trend has changed
def TrendChanged = if highest(Trend, TrendPeriod) != lowest(Trend, TrendPeriod) then 1 else 0;
# Reset the trend change flag
if Trend == Trend[1] {
TrendChanged := 0;
}
# Plot a green arrow for a buy signal and a red arrow for a sell signal
plot BuySignalArrow = if Signal == 1 then low - 5 else Double.NaN;
BuySignalArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
BuySignalArrow.SetDefaultColor(Color.GREEN);
plot SellSignalArrow = if Signal == -1 then high + 5 else Double.NaN;
SellSignalArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
SellSignalArrow.SetDefaultColor(Color.RED);
Start a new thread and receive assistance from our community.
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.
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.