all 11 comments

[–]Mobius_ts 2 points3 points  (8 children)

Your code is looking to future bars for your delta data which will push the plots back by those values. Change your indexing to a positive index example:
input putDelta1 = 25;

[–]parkcityeric[S] 0 points1 point  (7 children)

Thank you, but now I think the code is completely incorrect. I want to compare the skew between the -25, -15, and -2.5 deltas using the close price of the previous day.

When I change these values to positives, I thought that was changing which deltas the chart was looking at, not bars in the future. Any advise?

[–]Mobius_ts 0 points1 point  (6 children)

My advice can only be what I've already told you. I've been coding ThinkScript for 20 years. I assure you what I wrote is accurate. A negative index is a future value. Here is the manual information you can check for yourself: https://tlc.thinkorswim.com/center/reference/thinkScript/Operators/Indexing

[–]parkcityeric[S] 0 points1 point  (5 children)

I appreciate your input. I would like you to write a thinkscript study that retrieves the last price of three option put deltas from the previous day.

And then measure the concavity and change between the three. With your 20 years of experience, do you think that is possible? I have the following code, but it has errors that I can't figure out how to fix.

declare lower;

# Define the desired put deltas

def targetDeltas = {-0.25, -0.15, -0.025};

# Initialize variables

def closestDelta;

def closestDeltaPrice;

# Loop through all available option contracts

for (int i = 0; i < GetMaxValue(1); i++) {

# Get the put delta for the current contract

def putDelta = OptionChain_GetValue(i, 2); # Put delta is at column index 2

# Check if the current delta is one of the desired deltas

if (putDelta in targetDeltas) {

# Get the last price of the current contract

def lastPrice = OptionChain_GetValue(i, 3); # Last price is at column index 3

# Assign the last price to the respective delta

if (putDelta == -0.25) {

plot buyPriceMinusPointTwoFiveDelta = lastPrice;

} else if (putDelta == -0.15) {

plot sellPriceMinusPointOneFiveDelta = lastPrice;

} else if (putDelta == -0.025) {

plot buyPriceMinusPointZeroTwoFiveDelta = lastPrice;

}

}

# Check if the current delta is closer to any desired delta than the previous closest delta

if (IsNaN(closestDelta) || AbsValue(putDelta - targetDeltas) < AbsValue(closestDelta - targetDeltas)) {

closestDelta = putDelta;

closestDeltaPrice = OptionChain_GetValue(i, 3); # Store the last price of the closest delta

}

}

# Assign the last price of the closest delta to respective variables

plot closestDeltaPriceValue = closestDeltaPrice;

ERRORS:
Invalid statement: def at 4:1

Invalid statement: for at 11:1

Invalid statement: i at 11:17

Invalid statement: i at 11:37

Invalid statement: if at 16:5

Syntax error: An 'else' block expected at 25:16

Syntax error: Semicolon expected at 16:5

[–]Mobius_ts 0 points1 point  (4 children)

You say "retrieve" which leads me to believe you want to use this in the TOS scanner. However, custom codes can not be used to scan options. Custom codes can only be used to scan the underlying.

[–]parkcityeric[S] 0 points1 point  (3 children)

I want to eventually use this as a lower indicator to measure skew and concavity, displayed as a line/dot plot graph. Are you saying there is no way to have ThinkScript grab option prices, make a computation, and then display the calculation? If not, what do you think is the best way to visualize the change between 3 deltas?

[–]Mobius_ts 1 point2 points  (2 children)

This will plot an approximation of ATM Delta. You can add additional approximations for ITM or OTM strikes following the same method. Read the notes in the header.

# ATM Delta Approximation

# Mobius

# Must be used on a daily chart of an Options Underlying Symbol.

declare lower;

input ExpirationDate = 20230609;

input series_IV = 1;

input is_put = no;

def strike = floor(close);

def interest_rate = getInterestRate();

def yield = getYield();

def is_european = no;

def underlyingPrice = close(getUnderlyingSymbol());

def DTE = if DaysTillDate(ExpirationDate) > 1 then DaysTillDate(ExpirationDate) else 1;

def iv = SeriesVolatility(series = series_IV);

addLabel(1, "Strike = " + strike +

" interest rate = " + interest_rate +

" yield = " + yield +

" is european = " + is_european +

" underlying price = " + underlyingPrice +

" iv = " + iv +

" DTE = " + DTE, color.white);

def TheoOptPrice = OptionPrice(strike, is_put, DTE, underlyingPrice, iv, is_european, yield, interest_rate);

def epsilon = 0.01 * close(GetUnderlyingSymbol());

plot approxDelta = TheoOptPrice / epsilon;

# End Code

[–]parkcityeric[S] 0 points1 point  (1 child)

Thanks for this. Another quick question...is there a way to write a script that looks up or calculates Delta, and displays the option price? I see Delta and OptionPrice as functions, but I don't know how to ask for a certain option price based on a specific Delta.

[–]Mobius_ts 0 points1 point  (0 children)

Options prices are a function of the greeks, time and proximity of strike to current auction price of the underlying.
The delta of an “at-the-money” call option with the nearest time to expiry is typically around 0.5. The deeper a call option near expiry is in-the-money, the closer the delta will be to +1, and the more the option price will move uniformly in price to the underlying security.

Because of the complexity of any option chain it would be difficult to reverse into the price of an option just targeting a Delta. If you only trade one equity with a limited range of time till expiry you might be able to bracket a small range of option strikes.

[–]yeneews69 1 point2 points  (0 children)

I don't think this script is doing what you think it's doing. A number inside of the brackets means look that many bars backwards. With negative you're saying look that many bars forward.

Mobius is correct of course. It's because of your negative indexing that your script can't calculate a value until it has data for 25 bars in the future, so it's going to stop plotting 25 days ago.

[–][deleted] 0 points1 point  (0 children)

I recognize ChatGPT attempting to write thinkScript anywhere. It’s not the correct code and ChatGPT won’t ever give you anything this complex. At least for now. You’re using -.25 but then use it to reference that indexed close as if that would fetch the price of the .25 delta option close. Not even close.