Good afternoon @tomsk @SleepyZ I hope you are doing well, As I mentioned before, I am not a coder and I am grateful for the help we receive in this community. I am looking for an Automatic Fibo indicator for Options. The closest thing is the indicator in Post # 1. I don't know if it would be possible to modify the indicator code in Post # 1 https://usethinkscript.com/threads/auto-fib-fibonacci- levels-indicator-for-thinkorswim.14/, to use it in option charts, I have attached screenshoots of an SPX call option with the TOS Fibo tool and with the Auto Fibo Levels indicator, the problem is that the indicator takes the lowest price on the chart (even if I select only 1 day) and as seen in the screenshoot, the low that the indicator took was $0.90 which is from the previous day, being an intraday call option the lowest point should be zero as is plotted on the graph with the TOS tool. ( And also if it were possible to have the option to activate on/off the coefficient and separately the price and to be able to select separately whether the coefficient and/or the price is shown on the left or right, I ask about that option because if it had open 4 options contracts the space to see the bubbles with the coefficients and price would be very limited. In my search for a Fibo indicator for options I saw an indicator in Post #350 https://usethinkscript.com/threads/...vels-indicator-for-thinkorswim.14/post-127643 that had the coefficients with the same colors as the drawn lines that could help to better differentiate the levels. And if you could add the 70.5% and 90% levels to the indicator, again thank you very much for your valuable help.
In the case of a 0 DTE option, this indicator should take anchor 1 (zero) starting at 9:30 am. And if you need the option to see the movement of the contract price in the week as shown in screenshoot 5, you can select the number of days.
[Edit: See Post 372 https://usethinkscript.com/threads/...vels-indicator-for-thinkorswim.14/post-137860 for final code for OPTIONS ONLY autofibs]
Here is a repost of a reply to your need of some adjustments.
Since I do not work with options, I was not able to test the code beyond what you posted. However, this hopefully fixes it so that the plots only use the last day's data.
Code:# Auto Fib V1.4 # tomsk # 11.19.2019 # Automatically draws fibonacci retracements using the highest price and lowest price # from the current view and timeframe. # # Fibonacci retracements use horizontal lines to indicate areas of support or resistance # at the key Fibonacci levels before it continues in the original direction. These levels # are created by drawing a trendline between two extreme points and then dividing the # vertical distance by the key Fibonacci ratios of: 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100%. # CHANGE LOG # # V1.0 - 12.18.2018 - BenTen - Initial release of Auto Fib, created by Ryan Hendricks # V1.1 - 11.15.2019 - theelderwand - As script was difficult to read, made the following enhancements # Expands to right # Doesn't expand to left # Custom colors for Fibonacci bars (0.618 is GOLD color) # Custom line weights # Code is modularized so you can add extra plots as needed # V1.2 - 11.15.2019 - tomsk - Added an input selector for the colors of the label. You # can select from any of the colors listed - red, orange, # green, etc and bubbles for all the fib retracements will # utilize that color. # V1.3 - 11.19.2019 - tomsk - Modified the AddChartBubbles to be displayed on the right # side of the chart. Please ensure that you increase the # expansion area to that the bubbles have room to be displayed # Chart Settings > Time Axis > Expansion Area # V1.4 - 20240203 - Sleepyz - Modified to work for Options for only the last day. There the # low was defaulted to 0 as requested by the requestor. 2 fibs added #hint Price: Price used in the alerts on crossing retracement lines. <b>(Default is Close)</b> #hint coefficient_0: Retracement Line 0: Retracement from the highest high to the lowest low.<b>(Default is 0%)</b> #hint Coefficient_1: Retracement Line 1: Retracement from the highest high to the lowest low.<b>(Default is 23.6%)</b> #hint Coefficient_2: Retracement Line 2: Retracement from the highest high to the lowest low.<b>(Default is 38.2%)</b> #hint Coefficient_3: Retracement Line 3: Retracement from the highest high to the lowest low.<b>(Default is 50%)</b> #hint Coefficient_4: Retracement Line 4: Retracement from the highest high to the lowest low.<b>(Default is 61.8%)</b> #hint Coefficient_5: Retracement Line 5: Retracement from the highest high to the lowest low.<b>(Default is 78.6%)</b> #hint Coefficient_6: Retracement Line 6: Retracement from the highest high to the lowest low.<b>(Default is 100%)</b> #wizard input: Price #wizard text: Inputs: Price: #wizard input: coefficient_0 #wizard text: coefficient_0: #wizard input: Coefficient_1 #wizard text: Coefficient_1: #wizard input: Coefficient_2 #wizard text: Coefficient_2: #wizard input: Coefficient_3 #wizard text: Coefficient_3: #wizard input: Coefficient_4 #wizard text: Coefficient_4: #wizard input: Coefficient_5 #wizard text: Coefficient_5: #wizard input: Coefficient_6 #wizard text: Coefficient_6: input price = close; input high = high; input low = low; input coefficient_0 = 0.000; input coefficient_1 = .236; input Coefficient_2 = .382; input Coefficient_3 = .500; input Coefficient_4 = .618; input Coefficient_5 = .786; input Coefficient_6 = 1.000; input Coefficient_7 = .705; input Coefficient_8 = .900; input LabelColor = {default "MAGENTA", "CYAN", "PINK", "LIGHT_GRAY", "ORANGE", "RED", "GREEN", "GRAY", "WHITE"}; input n = 3; def n1 = n + 1; def lastdayhigh = if getday()>getlastday() then double.nan else if getday()==getlastday() then high else if high> lastdayhigh[1] then high else double.nan; def lastdaylow = CompoundValue(1, if getday()>getlastday() then double.nan else if getday()==getlastday() then 0 else if getday() != getday()[1] then low else if low < lastdaylow[1] then low else lastdaylow[1], low); def a = highestall(lastdayhigh); def b = lowestall(lastdaylow); def b1 = if b==0 and getday()==getlastday() then barnumber() else double.nan; def barnumber = BarNumber(); def c = if high == a then barnumber else Double.NaN; def d = if b!=0 and low == b then barnumber else if b==0 then b1 else Double.NaN; rec highnumber = CompoundValue(1, if IsNaN(c) then highnumber[1] else c, c); def highnumberall = HighestAll(highnumber); rec lownumber = CompoundValue(1, if IsNaN(d) then lownumber[1] else d, d); def lownumberall = LowestAll(lownumber); def upward = highnumberall > lownumberall; def downward = highnumberall < lownumberall; def x = AbsValue(lownumberall - highnumberall ); def slope = (a - b) / x; def slopelow = (b - a) / x; def day = GetDay(); def month = GetMonth(); def year = GetYear(); def lastDay = GetLastDay(); def lastmonth = GetLastMonth(); def lastyear = GetLastYear(); def isToday = If(day == lastDay and month == lastmonth and year == lastyear, 1, 0); def istodaybarnumber = HighestAll(if isToday then barnumber else Double.NaN); def line = b + (slope * (barnumber - lownumber)); def linelow = a + (slopelow * (barnumber - highnumber)); def currentlinelow = if barnumber <= lownumberall then linelow else Double.NaN; def currentline = if barnumber <= highnumberall then line else Double.NaN; plot FibFan = if downward then currentlinelow else if upward then currentline else Double.NaN; FibFan.SetStyle(Curve.SHORT_DASH); FibFan.AssignValueColor(Color.RED); FibFan.HideBubble(); def range = a - b; def value0 = range * coefficient_0; def value1 = range * coefficient_1; def value2 = range * Coefficient_2; def value3 = range * Coefficient_3; def value4 = range * Coefficient_4; def value5 = range * Coefficient_5; def value6 = range * Coefficient_6; def value7 = range * Coefficient_7; def value8 = range * Coefficient_8; def condition1 = downward and barnumber >= highnumberall; def condition2 = upward and barnumber >= lownumberall; plot Retracement0 = if condition1 then HighestAll(b + value0) else if condition2 then HighestAll(a - value0) else Double.NaN; plot Retracement1 = if condition1 then HighestAll(b + value1) else if condition2 then HighestAll(a - value1) else Double.NaN; plot Retracement2 = if condition1 then HighestAll(b + value2) else if condition2 then HighestAll(a - value2) else Double.NaN; plot Retracement3 = if condition1 then HighestAll(b + value3) else if condition2 then HighestAll(a - value3) else Double.NaN; plot Retracement4 = if condition1 then HighestAll(b + value4) else if condition2 then HighestAll(a - value4) else Double.NaN; plot Retracement5 = if condition1 then HighestAll(b + value5) else if condition2 then HighestAll(a - value5) else Double.NaN; plot Retracement6 = if condition1 then HighestAll(b + value6) else if condition2 then HighestAll(a - value6) else Double.NaN; plot Retracement7 = if condition1 then HighestAll(b + value7) else if condition2 then HighestAll(a - value7) else Double.NaN; plot Retracement8 = if condition1 then HighestAll(b + value8) else if condition2 then HighestAll(a - value8) else Double.NaN; #Retracement0.AssignValueColor(CreateColor(255, 255, 255)); Retracement0.SetLineWeight(4); Retracement0.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement0, Concat( (coefficient_0 * 100), "% ") + astext(retracement0), retracement0.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement0, Concat( (coefficient_0 * 100), "% ") + astext(retracement0), retracement0.takevalueColor(), yes); #Retracement1.AssignValueColor(CreateColor(173, 216, 230)); Retracement1.SetLineWeight(2); Retracement1.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement1, Concat( (coefficient_1 * 100), "% ") + astext(retracement1), retracement1.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement1, Concat( (coefficient_1 * 100), "% ") + astext(retracement1), retracement1.takevalueColor(), yes); #Retracement2.AssignValueColor(CreateColor(0, 197, 49)); Retracement2.SetLineWeight(2); Retracement2.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement2, Concat( (Coefficient_2 * 100), "% ") + astext(retracement2), retracement2.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement2, Concat( (Coefficient_2 * 100), "% ") + astext(retracement2), retracement2.takevalueColor(), yes); #Retracement3.AssignValueColor(CreateColor(255, 64, 64)); Retracement3.SetLineWeight(3); Retracement3.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement3, Concat( (Coefficient_3 * 100), "% ") + astext(retracement3), retracement3.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement3, Concat( (Coefficient_3 * 100), "% ") + astext(retracement3), retracement3.takevalueColor(), yes); #Retracement4.AssignValueColor(CreateColor(255, 215, 0)); Retracement4.SetLineWeight(5); Retracement4.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement4, Concat( (Coefficient_4 * 100), "% ") + astext(retracement4), retracement4.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement4, Concat( (Coefficient_4 * 100), "% ") + astext(retracement4), retracement4.takevalueColor(), yes); #Retracement5.AssignValueColor(CreateColor(0, 255, 255)); Retracement5.SetLineWeight(2); Retracement5.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement5, Concat( (Coefficient_5 * 100), "% ") + astext(retracement5), retracement5.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement5, Concat( (Coefficient_5 * 100), "% ") + astext(retracement5), retracement5.takevalueColor(), yes); #Retracement6.AssignValueColor(CreateColor(255, 255, 255)); Retracement6.SetLineWeight(4); Retracement6.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement6, Concat( (Coefficient_6 * 100), "% ") + astext(retracement6), retracement6.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement6, Concat( (Coefficient_6 * 100), "% ") + astext(retracement6), retracement6.takevalueColor(), yes); #Retracement7.AssignValueColor(CreateColor(255, 255, 255)); Retracement7.SetLineWeight(4); Retracement7.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement7, Concat( (Coefficient_7 * 100), "% ") + astext(retracement7), retracement7.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement7, Concat( (Coefficient_7 * 100), "% ") + astext(retracement7), retracement7.takevalueColor(), yes); #Retracement8.AssignValueColor(CreateColor(255, 255, 255)); Retracement8.SetLineWeight(4); Retracement8.HideBubble(); AddChartBubble((downward and close[n1]) and IsNaN(close[n]), Retracement8, Concat( (Coefficient_8 * 100), "% ") + astext(retracement8), retracement8.takevalueColor(), yes); AddChartBubble((upward and close[n1]) and IsNaN(close[n]), Retracement8, Concat( (Coefficient_8 * 100), "% ") + astext(retracement8), retracement8.takevalueColor(), yes); Alert((price crosses below Retracement0) , "Price crosses below Retracement Line 0"); Alert((price crosses above Retracement0) , "Price crosses above Retracement Line 0"); Alert((price crosses below Retracement1) , "Price crosses below Retracement Line 1"); Alert((price crosses above Retracement1) , "Price crosses above Retracement Line 1"); Alert((price crosses below Retracement2) , "Price crosses below Retracement Line 2"); Alert((price crosses above Retracement2) , "Price crosses above Retracement Line 2"); Alert((price crosses below Retracement3) , "Price crosses below Retracement Line 3"); Alert((price crosses above Retracement3) , "Price crosses above Retracement Line 3"); Alert((price crosses below Retracement4) , "Price crosses below Retracement Line 4"); Alert((price crosses above Retracement4) , "Price crosses above Retracement Line 4"); Alert((price crosses below Retracement5) , "Price crosses below Retracement Line 5"); Alert((price crosses above Retracement5) , "Price crosses above Retracement Line 5"); Alert((price crosses below Retracement6) , "Price crosses below Retracement Line 6"); Alert((price crosses above Retracement6) , "Price crosses above Retracement Line 6"); # End Auto Fib v1.4
Last edited: