wick CE; plot candle wick and tail midpoint lines
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © twingall
//

//@version=5
indicator("wick CE", overlay = true, max_bars_back = 5000,  max_lines_count = 500)
showWickCE=input.bool(true, 'wick CE', tooltip = "CE = consequent encroachment\n\nThe mid-point line of the wick or the tail")
mult = input.int(1, "Minimum Wick Size", minval = 0, tooltip = "Minimum wick size based on multiples of the chart symbol's mintick value.\n\nToggle on this checkbox to show the symbol's mintick value in the top right corner.\n\nIncrease this number to filter out smaller wicks.", inline = '1')
showMintick = input.bool(false, "show Symbol's Mintick Value", inline = '1')
showBodyMT=input.bool(false, 'body MT', inline ='2', tooltip = "MT = Mean Threshold\n\nThe mid-point line of the candle body")
MTcolor = input.color(color.blue, '| color:', inline ='2')
show75pctRetrace = input.bool(false, "75% retrace", inline ='3')
show25pctRetrace = input.bool(false, "25% retrace", inline ='3')
_75pctCol = input.color(color.red, "| color", inline ='3', tooltip = "For example, a 75% retrace:\n\nrepresents a 75% retrace up into the high to low range (if bearish candle)\n\n..or a 75% retrace down into the low to high range (if it was a bullish candle)")
lookback = input.int(20, "bars back", inline = '1', group = 'lookback')
showCurrentBar=input.bool(true, 'show current bar', inline = '1', group = 'lookback')
inputLinestyle = input.string('dotted', "line style", options = ['dashed','solid', 'dotted','arrow left'], inline = '2', group = 'line formatting')
lineColor = input.color(color.new(color.purple, 15),'color', inline = '2', group = 'line formatting')
lineWidth = input.int(1, "width", minval =1, maxval =6,  inline = '2', group = 'line formatting')
linestyle= inputLinestyle=='dashed'?line.style_dashed:inputLinestyle=='solid'? line.style_solid:inputLinestyle=='dotted'?line.style_dotted:inputLinestyle=='arrow left'?line.style_arrow_left:na
extendBars=input.int(0, 'extend lines by X bars', group = 'line formatting')

isBull = close>=open?1:0
bodyHigh = close>=open?close:open
bodyLow = close>=open?open:close

wickCE = showWickCE and high-bodyHigh > mult*syminfo.mintick? bodyHigh+((high-bodyHigh)/2):na 
tailCE=  showWickCE and bodyLow-low > mult*syminfo.mintick?  bodyLow-((bodyLow-low)/2):na  
bodyMT = showBodyMT?(isBull?open+(close-open)/2:close+(open-close)/2):na
_75pctLvl = show75pctRetrace?(isBull?low+((high-low)/4):high-((high-low)/4)):na
_25pctLvl = show25pctRetrace?(isBull?high-((high-low)/4):low+((high-low)/4)):na

if bar_index+(lookback-1) >= last_bar_index
    line.new(bar_index-1, wickCE[1], bar_index+extendBars, wickCE[1], color=lineColor, style = linestyle)
    line.new(bar_index-1, tailCE[1], bar_index+extendBars, tailCE[1], color=lineColor, style = linestyle)
    line.new(bar_index-1, bodyMT[1], bar_index+extendBars, bodyMT[1], color=MTcolor, style = linestyle)
    line.new(bar_index-1, _75pctLvl[1], bar_index+extendBars, _75pctLvl[1], color=_75pctCol, style = linestyle)
    line.new(bar_index-1, _25pctLvl[1], bar_index+extendBars, _25pctLvl[1], color=_75pctCol, style = linestyle)
if barstate.islast and showCurrentBar
    line.new(bar_index, wickCE, bar_index+2, wickCE, color=lineColor, style = linestyle)
    line.new(bar_index, tailCE, bar_index+2, tailCE, color=lineColor, style = linestyle)
    line.new(bar_index, _75pctLvl, bar_index+2, _75pctLvl, color=_75pctCol, style = linestyle)
    line.new(bar_index, _25pctLvl, bar_index+2, _25pctLvl, color=_75pctCol, style = linestyle)

var table Table = table.new(position.top_right, 4,4, bgcolor = color.yellow)
if showMintick
    table.cell(Table, 0,0, "mintick = " +str.tostring (syminfo.mintick))