Assuming the ITM, ATM, and OTM options update automatically when price moves from one whole dollar amount to another then this should be perfect. Ill give you an example of what i was attempting to ask for. If SPY is priced at 470.40 then the ITM call is 470 and the ITM put is 471 which would display in my labels. But if SPY price drops to 469.30 the new ITM call is 469 and new ITM put is 470. In my current set up i have to manually change the option strike price from 470 to 469 for the calls and then 471 to 470 for the puts. From what I can tell this does automatically update the strike prices. Im not going to pretend to be a coder but i attempted a few changes. 1st off my pc runs pitiful so i dropped the 2 OTM prices off so less data has to be calculated. Secondly i added dynamic colors to the labels, green if price is up on calls and down on puts, so essentially you want to see 4 green for long scalps or 4 red for short scalps. And lastly i added a relative volume threshhold of 1.5 based off of a 20 bar average. Dark green and dark red for volume spikes. Based off the coding in some scenerios the volume spike color may flash the wrong color. For instance if the RVOL threshhold is met and price is increasing but lower than the previous bar close at the time of the threshhold hold being met price would flash dark red until price moved above the previous bar close. Should be evident which way price is moving live trading if it occurs and the important piece of info(the RVOL spike) doesnt get overlooked. As i was typing this I was thinking to add a feature to where the three black boxes change color if SPY hits a RVOL threshhold. So my question to you now is one, does the way a script is coded effect its performance, So could 2 coders have the same output such as the average of 10 stocks but one script perform quicker and more efficient due to how the script was coded. If thats true can you consolidate the "averageVolume" and "relativeVolume" "0-3" declarations so it runs smoother. 2nd question is pertaining to the relative volume function. Can you make it not calculate a relative volume bar in the next bars calculation? so on a one minute chart, if at 12:21 there is a RVOL bar, the calculation for the next bar(12:22) will still be based on the average of 12:00-12:20(since we are using a 20 bar average). And have it reset once there is not at least 2 RVOL bars in a row. The idea of this is to not miss sustained volume because of a RVOL bar running the average too high. Lastly whats your opinion?(by that i mean change or add whatever if you think it will make it more efficient. Thanks for the help. Here is the code:
input expirationDate = 20240217;
input length = 20;
AddLabel(1, " ", Color.BLACK);
#-------------------
def ATMcall = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL));
def Up = ATMcall > ATMcall[1];
def averageVolume = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMcall"), length);
def relativeVolume = volume(symbol = "ATMcall") / averageVolume;
AddLabel(1, "ATMCALL: " + ATMcall + Round(relativeVolume, 2),
if Up then
if relativeVolume >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume then Color.DARK_RED else Color.RED);
def ITMcall = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
def Up1 = ITMcall > ITMcall[1];
def averageVolume1 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMcall"), length);
def relativeVolume1 = volume(symbol = "ITMcall") / averageVolume1;
AddLabel(1, "ITMCALL: " + ITMcall + Round(relativeVolume1, 2),
if Up1 then
if relativeVolume1 >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume1 then Color.DARK_RED else Color.RED);
#-------------------
AddLabel(1, " ", Color.BLACK);
#-------------------
def ITMput = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)));
def Up3 = ITMput > ITMput[1];
def averageVolume3 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMput"), length);
def relativeVolume3 = volume(symbol = "ITMput") / averageVolume3;
AddLabel(1, "ITMCALL: " + ITMput + Round(relativeVolume3, 2),
if Up3 then
if relativeVolume3 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume3 then Color.DARK_GREEN else Color.GREEN);
def ATMput = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT));
def Up2 = ATMput > ATMput[1];
def averageVolume2 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMput"), length);
def relativeVolume2 = volume(symbol = "ATMput") / averageVolume2;
AddLabel(1, "ITMCALL: " + ATMput + Round(relativeVolume2, 2),
if Up2 then
if relativeVolume2 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume2 then Color.DARK_GREEN else Color.GREEN);
#-------------------
AddLabel(1, " ", Color.BLACK);
I changed the 3 black boxes to yellow and have them changing to dark yellow if a RVOL of 1.5 hits based of a 20 bar ma. We have the stop light package now!
#otm_options
input expirationDate = 20240217;
input length = 20;
def averageVolume4 = MovingAverage(AverageType.SIMPLE, volume(symbol = "SPY"), length);
def relativeVolume4 = volume(symbol = "SPY") / averageVolume4;
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
#-------------------
#CreateColor(153, 153, 0)
def ATMcall = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL));
def Up = ATMcall > ATMcall[1];
def averageVolume = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMcall"), length);
def relativeVolume = volume(symbol = "ATMcall") / averageVolume;
AddLabel(1, "ATMCALL: " + ATMcall + Round(relativeVolume, 2),
if Up then
if relativeVolume >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume then Color.DARK_RED else Color.RED);
def ITMcall = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
def Up1 = ITMcall > ITMcall[1];
def averageVolume1 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMcall"), length);
def relativeVolume1 = volume(symbol = "ITMcall") / averageVolume1;
AddLabel(1, "ITMCALL: " + ITMcall + Round(relativeVolume1, 2),
if Up1 then
if relativeVolume1 >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume1 then Color.DARK_RED else Color.RED);
#-------------------
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
#-------------------
def ITMput = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)));
def Up3 = ITMput > ITMput[1];
def averageVolume3 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMput"), length);
def relativeVolume3 = volume(symbol = "ITMput") / averageVolume3;
AddLabel(1, "ITMCALL: " + ITMput + Round(relativeVolume3, 2),
if Up3 then
if relativeVolume3 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume3 then Color.DARK_GREEN else Color.GREEN);
def ATMput = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT));
def Up2 = ATMput > ATMput[1];
def averageVolume2 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMput"), length);
def relativeVolume2 = volume(symbol = "ATMput") / averageVolume2;
AddLabel(1, "ITMCALL: " + ATMput + Round(relativeVolume2, 2),
if Up2 then
if relativeVolume2 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume2 then Color.DARK_GREEN else Color.GREEN);
#-------------------
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
I changed the 3 black boxes to yellow and have them changing to dark yellow if a RVOL of 1.5 hits based of a 20 bar ma. We have the stop light package now!
#otm_options
input expirationDate = 20240217;
input length = 20;
def averageVolume4 = MovingAverage(AverageType.SIMPLE, volume(symbol = "SPY"), length);
def relativeVolume4 = volume(symbol = "SPY") / averageVolume4;
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
#-------------------
#CreateColor(153, 153, 0)
def ATMcall = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL));
def Up = ATMcall > ATMcall[1];
def averageVolume = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMcall"), length);
def relativeVolume = volume(symbol = "ATMcall") / averageVolume;
AddLabel(1, "ATMCALL: " + ATMcall + Round(relativeVolume, 2),
if Up then
if relativeVolume >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume then Color.DARK_RED else Color.RED);
def ITMcall = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
def Up1 = ITMcall > ITMcall[1];
def averageVolume1 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMcall"), length);
def relativeVolume1 = volume(symbol = "ITMcall") / averageVolume1;
AddLabel(1, "ITMCALL: " + ITMcall + Round(relativeVolume1, 2),
if Up1 then
if relativeVolume1 >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume1 then Color.DARK_RED else Color.RED);
#-------------------
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
#-------------------
def ITMput = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)));
def Up3 = ITMput > ITMput[1];
def averageVolume3 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMput"), length);
def relativeVolume3 = volume(symbol = "ITMput") / averageVolume3;
AddLabel(1, "ITMCALL: " + ITMput + Round(relativeVolume3, 2),
if Up3 then
if relativeVolume3 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume3 then Color.DARK_GREEN else Color.GREEN);
def ATMput = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT));
def Up2 = ATMput > ATMput[1];
def averageVolume2 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMput"), length);
def relativeVolume2 = volume(symbol = "ATMput") / averageVolume2;
AddLabel(1, "ITMCALL: " + ATMput + Round(relativeVolume2, 2),
if Up2 then
if relativeVolume2 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume2 then Color.DARK_GREEN else Color.GREEN);
#-------------------
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
Added two dark yellow boxes on the outside to make it easier to tell when spy hits RVOL threshhold.
input expirationDate = 20240217;
input length = 20;
def averageVolume4 = MovingAverage(AverageType.SIMPLE, volume(symbol = "SPY"), length);
def relativeVolume4 = volume(symbol = "SPY") / averageVolume4;
addlabel(1, " ", CreateColor(102, 102, 0));
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
#-------------------
#CreateColor(153, 153, 0)
def ATMcall = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL));
def Up = ATMcall > ATMcall[1];
def averageVolume = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMcall"), length);
def relativeVolume = volume(symbol = "ATMcall") / averageVolume;
AddLabel(1, "ATMCALL: " + ATMcall + Round(relativeVolume, 2),
if Up then
if relativeVolume >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume then Color.DARK_RED else Color.RED);
def ITMcall = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
def Up1 = ITMcall > ITMcall[1];
def averageVolume1 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMcall"), length);
def relativeVolume1 = volume(symbol = "ITMcall") / averageVolume1;
AddLabel(1, "ITMCALL: " + ITMcall + Round(relativeVolume1, 2),
if Up1 then
if relativeVolume1 >= 1.5 then Color.DARK_GREEN else Color.GREEN
else
if relativeVolume1 then Color.DARK_RED else Color.RED);
#-------------------
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
#-------------------
def ITMput = close(GetNextITMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT)));
def Up3 = ITMput > ITMput[1];
def averageVolume3 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ITMput"), length);
def relativeVolume3 = volume(symbol = "ITMput") / averageVolume3;
AddLabel(1, "ITMCALL: " + ITMput + Round(relativeVolume3, 2),
if Up3 then
if relativeVolume3 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume3 then Color.DARK_GREEN else Color.GREEN);
def ATMput = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.PUT));
def Up2 = ATMput > ATMput[1];
def averageVolume2 = MovingAverage(AverageType.SIMPLE, volume(symbol = "ATMput"), length);
def relativeVolume2 = volume(symbol = "ATMput") / averageVolume2;
AddLabel(1, "ITMCALL: " + ATMput + Round(relativeVolume2, 2),
if Up2 then
if relativeVolume2 >= 1.5 then Color.DARK_RED else Color.RED
else
if relativeVolume2 then Color.DARK_GREEN else Color.GREEN);
#-------------------
AddLabel(1, " ", if relativeVolume4 >= 1.5 then CreateColor(102, 102, 0) else Color.YELLOW);
addlabel(1, " ", CreateColor(102, 102, 0));
reply to 205
i am not sure what you are asking for.
you mention prices, but the variable names have 'strike' in them.
here is a basic study to display 6 option prices, to start with.
3 calls and 3 puts, OTM(purple) ATM(yellow) ITM(cyan)
look at this and come up with new statements/questions.
it doesn't do anything with rounding to dollars.
it just displays option prices, for the symbol on the chart.
Code:
#chat205_near_callput_labels_00d
#https://usethinkscript.com/threads/chatgpt-bard-other-ai-scripts-which-cant-be-used-in-thinkorswim.13822/page-11#post-136835
# post #205
#input symbol = "SPY";
# Get the SPY market price
#def spyMarketPrice = close(symbol = symbol);
#call (ITM) strike price < price
#put (ITM) strike price > price
#call (OTM) strike price > price
#put (OTM) strike price < price
#otm_options
input expirationDate = 20240217;
addlabel(1, " ", color.black);
#-------------------
addlabel(1, "ITM call", color.cyan);
addlabel(1, GetNextiTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)), color.cyan);
def itm1call = close(GetNextiTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
addlabel(1, itm1call, color.cyan);
addlabel(1, "ATM call", color.yellow);
addlabel(1, GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL), color.yellow);
def ATMcall = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL));
addlabel(1, atmcall, color.yellow);
addlabel(1, "OTM call", color.magenta);
addlabel(1, GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)), color.magenta);
def otm1call = close(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.CALL)));
addlabel(1, otm1call, color.magenta);
#-------------------
addlabel(1, " ", color.black);
#-------------------
addlabel(1, "OTM put", color.magenta);
addlabel(1, GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.put)), color.magenta);
def otm1put = close(GetNextOTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.put)));
addlabel(1, otm1put, color.magenta);
addlabel(1, "ATM put", color.yellow);
addlabel(1, GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.put), color.yellow);
def ATMput = close(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.put));
addlabel(1, atmput, color.yellow);
addlabel(1, "ITM put", color.cyan);
addlabel(1, GetNextiTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.put)), color.cyan);
def itm1put = close(GetNextiTMOption(GetATMOption(GetUnderlyingSymbol(), expirationDate, OptionClass.put)));
addlabel(1, itm1put, color.cyan);
#-------------------
addlabel(1, " ", color.black);
#
I tried it out and it worked for a second then quit working. Couldnt get it to work properly after that. I dont think its the coding though i think someone may have hacked my TOS or its glitched to some degree because when i was making the modifications mentioned in the other replies the colors started changing on their own from yellow to dark yellow after i loaded it onto a chart to make sure the coding loaded properly. I saw it happen and thought i was seeing things(this is what gave me the idea to put two more dark yellow boxes on the outside to compare the colors. It did do it again, I thought it was weird but thought nothing of it until this morning when your coding only worked for a second then quit. Has this happened to you before or something similar?