//@version=6 indicator("Quad Witching Dates by @bitcoinfundmgr on x", overlay=true) // Function to check if a date is the third Friday of the month isThirdFriday(barTime) => yearValue = year(barTime) monthValue = month(barTime) dayOfMonthValue = dayofmonth(barTime) dayOfWeekValue = dayofweek(barTime) // Check if it's a Friday (6 = Friday in Pine Script) isFriday = dayOfWeekValue == 6 // Check if it's the third Friday (between 15th and 21st) isInThirdWeek = dayOfMonthValue >= 15 and dayOfMonthValue <= 21 isFriday and isInThirdWeek // Function to check if current month is a quad witching month isQuadWitchingMonth(barTime) => currentMonthValue = month(barTime) // Quad witching months: March (3), June (6), September (9), December (12) currentMonthValue == 3 or currentMonthValue == 6 or currentMonthValue == 9 or currentMonthValue == 12 // Check if current bar is on a quad witching date isQuadWitching = isThirdFriday(time) and isQuadWitchingMonth(time) // Input for line color lineColor = input.color(color.red, "Line Color", group="Appearance") lineWidth = input.int(1, "Line Width", minval=1, maxval=4, group="Appearance") lineStyle = input.string("solid", "Line Style", options=["solid", "dashed", "dotted"], group="Appearance") // Convert line style string to Pine Script line style getLineStyle(style) => style == "solid" ? line.style_solid : style == "dashed" ? line.style_dashed : line.style_dotted // Draw vertical line on quad witching dates if isQuadWitching line.new(x1=bar_index, y1=low[1] * 0.95, x2=bar_index, y2=high[1] * 1.05, color=lineColor, width=lineWidth, style=getLineStyle(lineStyle), extend=extend.both) // Optional: Add label to identify quad witching dates showLabels = input.bool(true, "Show Labels", group="Labels") labelPosition = input.string("bottom", "Label Position", options=["top", "bottom"], group="Labels") if isQuadWitching and showLabels labelY = labelPosition == "top" ? high[1] * 1.02 : low[1] * 0.98 label.new(x=bar_index, y=labelY, text="QW", color=lineColor, style=labelPosition == "top" ? label.style_label_down : label.style_label_up, size=size.small, textcolor=color.white) // Display next quad witching date showNextDate = input.bool(true, "Show Next Quad Witching Date", group="Display") tablePosition = input.string("top_right", "Table Position", options=["top_left", "top_center", "top_right", "middle_left", "middle_center", "middle_right", "bottom_left", "bottom_center", "bottom_right"], group="Display") // Create table for displaying next quad witching date var table infoTable = table.new(tablePosition, 1, 1) if barstate.islast and showNextDate currentTimeValue = time currentYearValue = year(currentTimeValue) currentMonthValue = month(currentTimeValue) currentDayValue = dayofmonth(currentTimeValue) // Calculate next quad witching month nextMonthValue = 0 nextYearValue = currentYearValue if currentMonthValue < 3 nextMonthValue := 3 else if currentMonthValue < 6 nextMonthValue := 6 else if currentMonthValue < 9 nextMonthValue := 9 else if currentMonthValue < 12 nextMonthValue := 12 else nextMonthValue := 3 nextYearValue := currentYearValue + 1 // Find third Friday of next quad witching month firstDayTimestamp = timestamp(nextYearValue, nextMonthValue, 1, 0, 0) firstDayOfWeekValue = dayofweek(firstDayTimestamp) // Calculate date of third Friday daysUntilFridayValue = (6 - firstDayOfWeekValue + 7) % 7 if daysUntilFridayValue == 0 daysUntilFridayValue := 7 thirdFridayDate = 1 + daysUntilFridayValue + 14 // Check if we've already passed the quad witching date this month if currentMonthValue == nextMonthValue and currentDayValue > thirdFridayDate if nextMonthValue == 12 nextMonthValue := 3 nextYearValue := nextYearValue + 1 else if nextMonthValue == 3 nextMonthValue := 6 else if nextMonthValue == 6 nextMonthValue := 9 else nextMonthValue := 12 // Recalculate third Friday for the new month firstDayTimestamp := timestamp(nextYearValue, nextMonthValue, 1, 0, 0) firstDayOfWeekValue := dayofweek(firstDayTimestamp) daysUntilFridayValue := (6 - firstDayOfWeekValue + 7) % 7 if daysUntilFridayValue == 0 daysUntilFridayValue := 7 thirdFridayDate := 1 + daysUntilFridayValue + 14 nextQWDate = str.format("{0}-{1,number,00}-{2,number,00}", nextYearValue, nextMonthValue, thirdFridayDate) // Update table table.cell(infoTable, 0, 0, "Next QW: " + nextQWDate, bgcolor=color.new(color.black, 80), text_color=color.white, text_size=size.small)