Price Difference At Expiration
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dcgraham7

//@version=5
indicator(title="Price Difference At Expiration", shorttitle="exp-diff")
interval = input.int(10, "interval (days)")
maxRange = input.float(200, "buffer")
drawMonday = input.bool(true, "Monday")
drawTuesday = input.bool(false, "Tuesday")
drawWednesday = input.bool(true, "Wednesday")
drawThursday = input.bool(false, "Thursday")
drawFriday = input.bool(true, "Friday")
day = dayofweek(time_close(timeframe.period))

// decide if we want to draw this bar
bool shouldDraw = true
if day == 2 and drawMonday == false
    shouldDraw := false
else if day == 3 and drawTuesday == false
    shouldDraw := false
else if day == 4 and drawWednesday == false
    shouldDraw := false
else if day == 5 and drawThursday == false
    shouldDraw := false
else if day == 6 and drawFriday == false
    shouldDraw := false

dayLetter = if day == 2
    "M"
else if day == 3
    "T"
else if day == 4
    "W"
else if day == 5
    "Th"
else
    "F"

change = shouldDraw ? close - close[interval] : 0
isOver = math.abs(change) >= maxRange
barColor = isOver ? color.red : color.gray

plot(change, color=barColor, style=plot.style_histogram, linewidth=4)



if shouldDraw and isOver
    label.new(bar_index, na, dayLetter)