Good day!! I hope this post finds you well. I was looking to find out if its possible to creat a script that adds up Two options Theta one in the money and second out of money and divide it by two, and that to be done for calls and puts separately and plot it on chart two lines. Something like in the picture. Thank you!!!
I have this from ChatGPT but it doesn't post anything
# Define the input parameters
input showLabels = yes; # Show option labels on the chart
# Calculate Theta for each option
def callTheta = if close(symbol="SPY") > close then Theta() else double.nan;
def putTheta = if close(symbol="SPY") < close then Theta() else double.nan;
# Update cumulative values
def sumCallTheta = sumCallTheta + callTheta;
def countCall = countCall + 1;
def sumPutTheta = sumPutTheta + putTheta;
def countPut = countPut + 1;
# Calculate average gamma for calls and puts
def avgCallTheta = if countCall != 0 then sumCallTheta / countCall else double.nan;
def avgPutTheta = if countPut != 0 then sumPutTheta / countPut else double.nan;
# Plot the average gamma values on the chart
plot AvgCallTheta_Line = avgCallTheta;
plot AvgPutTheta_Line = avgPutTheta;
# Customize the appearance of the lines
AvgCallTheta_Line.SetDefaultColor(color.green);
AvgPutTheta_Line.SetDefaultColor(color.blue);
# Display option labels on the chart if specified
AddLabel(showLabels, "Avg Call Gamma: " + avgCallTheta, color.green);
AddLabel(showLabels, "Avg Put Gamma: " + avgPutTheta, color.blue);
I have this from ChatGPT but it doesn't post anything
# Define the input parameters
input showLabels = yes; # Show option labels on the chart
# Calculate Theta for each option
def callTheta = if close(symbol="SPY") > close then Theta() else double.nan;
def putTheta = if close(symbol="SPY") < close then Theta() else double.nan;
# Update cumulative values
def sumCallTheta = sumCallTheta + callTheta;
def countCall = countCall + 1;
def sumPutTheta = sumPutTheta + putTheta;
def countPut = countPut + 1;
# Calculate average gamma for calls and puts
def avgCallTheta = if countCall != 0 then sumCallTheta / countCall else double.nan;
def avgPutTheta = if countPut != 0 then sumPutTheta / countPut else double.nan;
# Plot the average gamma values on the chart
plot AvgCallTheta_Line = avgCallTheta;
plot AvgPutTheta_Line = avgPutTheta;
# Customize the appearance of the lines
AvgCallTheta_Line.SetDefaultColor(color.green);
AvgPutTheta_Line.SetDefaultColor(color.blue);
# Display option labels on the chart if specified
AddLabel(showLabels, "Avg Call Gamma: " + avgCallTheta, color.green);
AddLabel(showLabels, "Avg Put Gamma: " + avgPutTheta, color.blue);
Attachments
Last edited: