Logarithmic Volume Profile
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SwingSystems

//@version=5
indicator("My script", overlay=true, max_lines_count = 500)

//  will use the figure below as the index, so LBP of 252 - 1 = 251. 251 to endCandle of 0 is 252 candles
LBP = input.int(252, "VP primary lookback period", 10, 1000, 
 tooltip="The volume of bars within this period will all be given the same weight") - 1
useSecondaryPeriod = input.bool(title="", defval=true, inline = "02")
LBPA = input.int(252, "VP secondary (additional) lookback period", 0, 1000, inline = "02", 
 tooltip="Tick to add an additional secondary period, where the impact of secondary bars tapers to nothing from the end to the the start of that period. The volume of the last bar in the secondary period will be weighted the same as bars in the primary period, but this will taper to a weighting of 0 at the start of the period")
NOR = input.int(65, "VP number of rows", 2, 200)
WOI = input.int(128, "VP width of indicator left", minval=50, inline = "05", 
 tooltip="The larger this number the more accurate (due to rounding the location on x-axis of the lines to the nearest bar)")
applyLeftCol1 = input.color(#040042FF, "", inline = "05")
applyLeftCol2 = input.color(#55005EFF, "", inline = "05")
showRightIndic = input.bool(true, "VP show bull bear to right?", inline = "06")
bearColor1 = input.color(#FF0015FF, "", inline = "06")
bullColor1 = input.color(#00FF08FF, "", inline = "06")
OFLC = input.int(10, "VP offset from last candle",  tooltip="Larger values move indicator to the right")
VPLW = input.int(4, "VP line width", inline = "08")
yBordersOn = input.bool(title="Show ranges", defval=false, inline = "08")
yBordersColor = input.color(#00000018, "", inline = "08")

averageOpenToOpenChangePC = 0.0
numberInAverageOpenToOpenChangePC = 0
xx = 0
while xx <= 200
    if barstate.isfirst != true
        averageOpenToOpenChangePC := averageOpenToOpenChangePC + math.abs((1 / ohlc4[1]) * ohlc4)
        numberInAverageOpenToOpenChangePC := numberInAverageOpenToOpenChangePC + 1
    xx += 1
    
candleCount = 0
if barstate.isfirst != true
    candleCount := candleCount[1] + 1

if barstate.islast == true
    if (LBP > candleCount)
        LBP := candleCount
        LBPA := 0
    else if (LBPA + LBP > candleCount)
        LBPA := candleCount - LBP

thisAverageOpenToOpenChangePC = math.abs(1 - (averageOpenToOpenChangePC / numberInAverageOpenToOpenChangePC))
//if barstate.islast
//    label.new(bar_index + 1, close, str.tostring(thisAverageOpenToOpenChangePC))

ha_open = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
ha_high = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
ha_low = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
ha_close = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
ha_ohlc4 = (ha_open + ha_close + ha_low + ha_high) / 4

graph_ma(_type, _src, _period) =>
    _src2 = close
    if (_src == "open")
        _src2 := open
    else if (_src == "close")
        _src2 := close
    else if (_src == "high")
        _src2 := high
    else if (_src == "low")
        _src2 := low
    else if (_src == "ohlc4")
        _src2 := ohlc4
    else if (_src == "hl2")
        _src2 := hl2
    else if (_src == "hlc3")
        _src2 := hlc3
    else if (_src == "hlcc4")
        _src2 := hlcc4
    else if (_src == "Heikin-Ashi-Close")
        _src2 := ha_close
    else if (_src == "Heikin-Ashi-OHLC4")
        _src2 := ha_ohlc4
    
    _return = (_type == "SMA")      ?     ta.sma(_src2, _period) :
              (_type == "EMA")      ?     ta.ema(_src2, _period) :
              (_type == "WMA")      ?     ta.wma(_src2, _period) :
              (_type == "SMMA")     ?     ta.rma(_src2, _period) :
              (_type == "HMA")      ?     ta.hma(_src2, _period) :
              (_type == "RMA")      ?     ta.rma(_src2, _period) :
              (_type == "ALMA")      ?     ta.alma(_src2, _period, 0.5, 10) :
              (_type == "VWMA")      ?     ta.vwma(_src2, _period) :
              (_type == "VWAP")      ?     ta.vwap(_src2) :
              (_type == "SWMA")     ?    ta.swma(_src2) :
              0.0 // In doubt, return zero
    _return
    
    
ma101Plot = input.bool(false, "", inline = "09", group = "Other indicators")
ma101Type = input.string(title="", defval="EMA", options=["SMA", "EMA", "WMA", "SMMA", "HMA", "SWMA", "RMA", "ALMA", "VWMA", "VWAP"], inline = "09", group = "Other indicators", tooltip="For ALMA, offset=0.5, sigma=10 and floor=false. RMA and SMMA are the same thing")
ma101Source = input.string(title="", defval="Heikin-Ashi-Close", options=["open", "close", "high", "low", "ohlc4", "hl2", "hlc3", "hlcc4", "Heikin-Ashi-Close", "Heikin-Ashi-OHLC4"], inline = "09", group = "Other indicators")
ma101Value = input.int(100, "", minval=2,  inline = "09", group = "Other indicators")
ma101Color = input.color(#00FBFF19, "", inline = "09", group = "Other indicators")
if (ma101Plot == false)
    ma101Color := #00000000
ma101 = graph_ma(ma101Type, ma101Source, ma101Value)
///ma101SmoothVal = input.int(0, "", minval=0,  inline = "09", group = "Other indicators")
///ma101Smooth = ma101
///if ma101SmoothVal >= 2
///    ma101Smooth := ta.sma(ma101, ma101SmoothVal)
plot(ma101, color=ma101Color, style=plot.style_areabr)

ma102Plot = input.bool(true, "", inline = "10", group = "Other indicators")
ma102Type = input.string(title="", defval="SMA", options=["SMA", "EMA", "WMA", "SMMA", "HMA", "SWMA", "RMA", "ALMA", "VWMA", "VWAP"], inline = "10", group = "Other indicators", tooltip="For ALMA, offset=0.5, sigma=10 and floor=false. RMA and SMMA are the same thing")
ma102Source = input.string(title="", defval="close", options=["open", "close", "high", "low", "ohlc4", "hl2", "hlc3", "hlcc4", "Heikin-Ashi-Close", "Heikin-Ashi-OHLC4"], inline = "10", group = "Other indicators")
ma102Value = input.int(200, "", minval=2,  inline = "10", group = "Other indicators")
ma102Color = input.color(#0011FFFF, "", inline = "10", group = "Other indicators")
if (ma102Plot == false)
    ma102Color := #00000000
ma102 = graph_ma(ma102Type, ma102Source, ma102Value)
plot(ma102, color=ma102Color)

ma103Plot = input.bool(true, "", inline = "11", group = "Other indicators")
ma103Type = input.string(title="", defval="EMA", options=["SMA", "EMA", "WMA", "SMMA", "HMA", "SWMA", "RMA", "ALMA", "VWMA", "VWAP"], inline = "11", group = "Other indicators", tooltip="For ALMA, offset=0.5, sigma=10 and floor=false. RMA and SMMA are the same thing")
ma103Source = input.string(title="", defval="close", options=["open", "close", "high", "low", "ohlc4", "hl2", "hlc3", "hlcc4", "Heikin-Ashi-Close", "Heikin-Ashi-OHLC4"], inline = "11", group = "Other indicators")
ma103Value = input.int(50, "", minval=2,  inline = "11", group = "Other indicators")
ma103Color = input.color(#00FBFF54, "", inline = "11", group = "Other indicators")
if (ma103Plot == false)
    ma103Color := #00000000
ma103 = graph_ma(ma103Type, ma103Source, ma103Value)
plot(ma103, color=ma103Color)

ma104Plot = input.bool(true, "", inline = "12", group = "Other indicators")
ma104Type = input.string(title="", defval="EMA", options=["SMA", "EMA", "WMA", "SMMA", "HMA", "SWMA", "RMA", "ALMA", "VWMA", "VWAP"], inline = "12", group = "Other indicators", tooltip="For ALMA, offset=0.5, sigma=10 and floor=false. RMA and SMMA are the same thing")
ma104Source = input.string(title="", defval="close", options=["open", "close", "high", "low", "ohlc4", "hl2", "hlc3", "hlcc4", "Heikin-Ashi-Close", "Heikin-Ashi-OHLC4"], inline = "12", group = "Other indicators")
ma104Value = input.int(100, "", minval=2,  inline = "12", group = "Other indicators")
ma104Color = input.color(#00AAFF68, "", inline = "12", group = "Other indicators")
if (ma104Plot == false)
    ma104Color := #00000000
ma104 = graph_ma(ma104Type, ma104Source, ma104Value)
plot(ma104, color=ma104Color)

ma105Plot = input.bool(true, "", inline = "13", group = "Other indicators")
ma105Type = input.string(title="", defval="EMA", options=["SMA", "EMA", "WMA", "SMMA", "HMA", "SWMA", "RMA", "ALMA", "VWMA", "VWAP"], inline = "13", group = "Other indicators", tooltip="For ALMA, offset=0.5, sigma=10 and floor=false. RMA and SMMA are the same thing")
ma105Source = input.string(title="", defval="close", options=["open", "close", "high", "low", "ohlc4", "hl2", "hlc3", "hlcc4", "Heikin-Ashi-Close", "Heikin-Ashi-OHLC4"], inline = "13", group = "Other indicators")
ma105Value = input.int(146, "", minval=2,  inline = "13", group = "Other indicators")
ma105Color = input.color(#0091FFCC, "", inline = "13", group = "Other indicators")
if (ma105Plot == false)
    ma105Color := #00000000
ma105 = graph_ma(ma105Type, ma105Source, ma105Value)
plot(ma105, color=ma105Color)


plotMACloud = input.bool(false, "5MA Cloud", inline = "14", group = "Other indicators")
MACloudLongValue = input.int(100, "", minval=80, step=10, inline = "14", group = "Other indicators")
MACloudType = input.string(title="", defval="WMA", options=["SMA", "EMA", "WMA", "SMMA", "HMA", "SWMA", "RMA", "ALMA", "VWMA", "VWAP"], inline = "14", group = "Other indicators", tooltip="For ALMA, offset=0.5, sigma=10 and floor=false. RMA and SMMA are the same thing")
MACloudSource = input.string(title="", defval="ohlc4", options=["open", "close", "high", "low", "ohlc4", "hl2", "hlc3", "hlcc4", "Heikin-Ashi-Close", "Heikin-Ashi-OHLC4"], inline = "14", group = "Other indicators")
MACloudChannel = input.bool(false)
MACloudChannelCol = input.color(#00000018, "", inline = "15", group = "Other indicators")
MACloudChannelMultiplier = input.float(6.0, "", minval=0.0, step=0.1, inline = "15", group = "Other indicators")

MACloud1 = graph_ma(MACloudType, MACloudSource, math.round(MACloudLongValue))
MACloud2 = graph_ma(MACloudType, MACloudSource, math.round(MACloudLongValue * 0.9))
MACloud3 = graph_ma(MACloudType, MACloudSource, math.round(MACloudLongValue * 0.8))
MACloud4 = graph_ma(MACloudType, MACloudSource, math.round(MACloudLongValue * 0.7))
MACloud5 = graph_ma(MACloudType, MACloudSource, math.round(MACloudLongValue * 0.6))
numberGoingUp = 0
if (MACloud1 > MACloud1[1])
    numberGoingUp := numberGoingUp + 1
if (MACloud2 > MACloud2[1])
    numberGoingUp := numberGoingUp + 1
if (MACloud3 > MACloud3[1])
    numberGoingUp := numberGoingUp + 1
if (MACloud4 > MACloud4[1])
    numberGoingUp := numberGoingUp + 1
if (MACloud5 > MACloud5[1])
    numberGoingUp := numberGoingUp + 1
MACloudMax = math.max(MACloud1,MACloud2,MACloud3,MACloud4,MACloud5)
MACloudMin = math.min(MACloud1,MACloud2,MACloud3,MACloud4,MACloud5)
fillTrans = 90
fillBorderTrans = 70
fillCol = color.rgb(0, 0, 0, fillTrans)
fillBorder = color.rgb(0, 0, 0, fillBorderTrans)
if numberGoingUp == 5
    fillCol := color.rgb(0, 255, 0, fillTrans)
    fillBorder := color.rgb(0, 255, 0, fillBorderTrans)
if numberGoingUp == 4
    fillCol := color.rgb(102, 255, 0, fillTrans)
    fillBorder := color.rgb(102, 255, 0, fillBorderTrans)
if numberGoingUp == 3
    fillCol := color.rgb(204, 255, 0, fillTrans)
    fillBorder := color.rgb(204, 255, 0, fillBorderTrans)
if numberGoingUp == 2
    fillCol := color.rgb(255, 204, 0, fillTrans)
    fillBorder := color.rgb(255, 204, 0, fillBorderTrans)
if numberGoingUp == 1
    fillCol := color.rgb(255, 102, 0, fillTrans)
    fillBorder := color.rgb(255, 102, 0, fillBorderTrans)
if numberGoingUp == 0
    fillCol := color.rgb(255, 0, 0, fillTrans)
    fillBorder := color.rgb(255, 0, 0, fillBorderTrans)
if (plotMACloud == false)
    fillCol := #00000000
    fillBorder := #00000000
    channelCol = #00000000
MACloudMaxLine = plot(MACloudMax, color=fillBorder)
MACloudMinLine = plot(MACloudMin, color=fillBorder)
fill(MACloudMaxLine,MACloudMinLine,fillCol)
atrToUse = ta.atr(100)
MACloudForChannel = (MACloudMax + MACloudMin) / 2

atrOffset = atrToUse * MACloudChannelMultiplier
if MACloudChannel == false
    MACloudChannelCol := #00000000
    atrOffset := 0

plot(MACloudForChannel + atrOffset, color=MACloudChannelCol)
plot(MACloudForChannel - atrOffset, color=MACloudChannelCol)
///plot(MACloudForChannel + atrToUse * 10, color=MACloudChannelCol)
///plot(MACloudForChannel - atrToUse * 10, color=MACloudChannelCol)






//smoothed30wkEMA1 = ta.wma(ohlc4, 200)
//plot(smoothed30wkEMA1, color=#FF9500FF)
//smoothed30wkEMA2 = ta.wma(ohlc4, 150)
//plot(smoothed30wkEMA2)
//smoothed30wkEMA3 = ta.wma(ohlc4, 100)
//plot(smoothed30wkEMA3, color=#27003DFF)




/////numberAbove = 0
/////totalOutOfPlace = 0
/////thisOutOfPlace = 0
/////jTempVal = 0.0
/////iTempVal = 0.0
////////var int[] maArray = array.from(200,198,196,194,192,190,188,186,184,182)
/////var int[] maArray = array.from(100,120,140,160,180)
///////maArray = [ta.wma(ohlc4, 200),ta.wma(ohlc4, 190),ta.wma(ohlc4, 180),ta.wma(ohlc4, 170),ta.wma(ohlc4, 160),ta.wma(ohlc4, 150),ta.wma(ohlc4, 140),ta.wma(ohlc4, 130),ta.wma(ohlc4, 120),ta.wma(ohlc4, 110)]
/////possibleOutcomesSum = 0
/////modifier = -2
/////a = array.size(maArray)
/////while a <= array.size(maArray)
/////    possibleOutcomesSum := possibleOutcomesSum + a
/////    if a == 1
/////        possibleOutcomesSum := possibleOutcomesSum + 1
/////    if (a < 1.5)
/////        modifier := +2
/////    a := a + (modifier)
/////if barstate.islast == true
/////    label.new(bar_index[0], high, str.tostring(possibleOutcomesSum))
/////
/////for i = 0 to array.size(maArray) - 1
/////    numberAbove := 0
/////    for j = 0 to array.size(maArray) - 1
/////        jTempVal := ta.wma(ohlc4, array.get(maArray, j))
/////        iTempVal := ta.wma(ohlc4, array.get(maArray, i))
/////        if jTempVal > iTempVal
/////            numberAbove := numberAbove + 1
/////    if i == numberAbove
/////        thisOutOfPlace := 0
/////    else if i > numberAbove
/////        thisOutOfPlace := i - numberAbove
/////    else
/////        thisOutOfPlace := numberAbove - i
/////    totalOutOfPlace := totalOutOfPlace + thisOutOfPlace
/////topLine = 0.0
/////bottomLine = 100000000.0
/////for k = 0 to array.size(maArray) - 1
/////    if ta.wma(ohlc4, array.get(maArray, k)) > topLine
/////        topLine := ta.wma(ohlc4, array.get(maArray, k))
/////    if ta.wma(ohlc4, array.get(maArray, k)) < bottomLine
/////        bottomLine := ta.wma(ohlc4, array.get(maArray, k))
/////halfMaxOutOfPlace = possibleOutcomesSum / 2
/////top1 = plot(topLine, color=#00000019)
/////bot1 = plot(bottomLine, color=#00000019)
/////ribbonColor = color.rgb(0.0, 255.0, 0.0, 90)
/////if (totalOutOfPlace < halfMaxOutOfPlace)
/////    ribbonColor := color.rgb((255.0 / halfMaxOutOfPlace) * totalOutOfPlace, 255.0, 0.0, 90)
/////if (totalOutOfPlace == halfMaxOutOfPlace)
/////    ribbonColor := color.rgb(255.0, 255.0, 0.0, 90)
/////minus25 = totalOutOfPlace - 25
/////minus25Fig = (255.0 / 25.0) * minus25
/////minus25Fig := math.abs(minus25Fig - 255)
/////if (minus25Fig < 0.0)
/////    minus25Fig := 0.0
/////if (minus25Fig > 255.0)
/////    minus25Fig := 255.0 
/////if (totalOutOfPlace > halfMaxOutOfPlace)
/////    ribbonColor := color.rgb(255.0, minus25Fig, 0.0, 90)
/////fill(top1, bot1, ribbonColor)









/// endCandle = input.int(0, "End at candle # (0 = last candle)... doesn't work yet", 0, 0)
endCandle = 0
startCandle = endCandle + LBP + LBPA

if (useSecondaryPeriod == false)
    LBPA := 0

highestPriceInRange = ta.highest(high, LBP + 1 + LBPA)
lowestPriceInRange = ta.lowest(low, LBP + 1 + LBPA)
///atr1 = ta.atr(LBP)

thisVolume1 = 0.0
thisVolumeBear = 0.0
thisVolumeBull = 0.0
largestVol = 0.0
volWeight = 0.0
    
logBase = math.pow((highestPriceInRange / lowestPriceInRange), 1.0 / NOR)

leftCol1 = #004CFFFF

if (barstate.islast == true)
///    dt = time - time[1]
    largestVol := 0.0
    //  ascertain what percentage of candle in each range
    i = 1.0
    rangeStart = lowestPriceInRange
    rangeEnd = lowestPriceInRange * logBase
    candleHeight = 0.0
    pcCandleInThisRange = 0.0
    while i <= NOR
        thisVolume1 := 0.0
        j = startCandle
        candleHeight := 0.0
        pcCandleInThisRange := 0.0
        while j >= endCandle
            //  calculate percentage of that candle in this range and add that % of volume to thisVolume1
            pcCandleInThisRange := 0.0
            candleHeight := high[j] - low[j]

            if (rangeStart <= low[j] and rangeEnd >= high[j])
                pcCandleInThisRange := 1
            else if (rangeStart <= low[j] and rangeEnd >= low[j] and rangeEnd <= high[j])
                pcCandleInThisRange := (1 / candleHeight) * (rangeEnd - low[j])
            else if (rangeStart >= low[j] and rangeStart <= high[j] and rangeEnd <= high[j])
                belowR = (1 / candleHeight) * (rangeStart - low[j])
                aboveR = (1 / candleHeight) * (high[j] - rangeEnd)
                pcCandleInThisRange := (1 - belowR - aboveR)
            else if (rangeStart <= high[j] and rangeStart >= low[j] and rangeEnd >= high[j])
                pcCandleInThisRange := (1 / candleHeight) * (rangeEnd - high[j])

            if (j <= endCandle + LBP)
                thisVolume1 := thisVolume1 + (pcCandleInThisRange * volume[j])
            else
                volWeight := 1 - (1 / (startCandle - LBP)) * (j - LBP)
                thisVolume1 := thisVolume1 + (pcCandleInThisRange * volume[j] * volWeight)
                
            j := j - 1
        
        if (largestVol < thisVolume1)
            largestVol := thisVolume1
        
        rangeStart := rangeEnd
        rangeEnd := rangeEnd * logBase
        i := i + 1.0
    
    
    x1 = 0
    x2 = 0
    x1R = 0
    x2R = 0
    i := 1.0
    midPointForLine = 0.0
    rangeStart := lowestPriceInRange
    rangeEnd := lowestPriceInRange * logBase
    candleHeight := 0.0
    pcCandleInThisRange := 0.0
    
    while i <= NOR
        thisVolume1 := 0.0
        thisVolumeBear := 0.0
        thisVolumeBull := 0.0
        j = startCandle
        candleHeight := 0.0
        pcCandleInThisRange := 0.0
        while j >= endCandle
            //  calculate percentage of that candle in this range and add that % of volume to thisVolume1
            pcCandleInThisRange := 0.0
            candleHeight := high[j] - low[j]
            
            
            if (rangeStart <= low[j] and rangeEnd >= high[j])
                pcCandleInThisRange := 1
            else if (rangeStart <= low[j] and rangeEnd >= low[j] and rangeEnd <= high[j])
                pcCandleInThisRange := (1 / candleHeight) * (rangeEnd - low[j])
            else if (rangeStart >= low[j] and rangeStart <= high[j] and rangeEnd <= high[j])
                belowR = (1 / candleHeight) * (rangeStart - low[j])
                aboveR = (1 / candleHeight) * (high[j] - rangeEnd)
                pcCandleInThisRange := (1 - belowR - aboveR)
            else if (rangeStart <= high[j] and rangeStart >= low[j] and rangeEnd >= high[j])
                pcCandleInThisRange := (1 / candleHeight) * (rangeEnd - high[j])
            
            
            
            if (j <= endCandle + LBP)
                thisVolume1 := thisVolume1 + (pcCandleInThisRange * volume[j])
            else
                volWeight := 1 - (1 / (startCandle - LBP)) * (j - LBP)
                thisVolume1 := thisVolume1 + (pcCandleInThisRange * volume[j] * volWeight)
            
            if (showRightIndic == true)
                if (open[j] > close[j])
                    //  down
                    if (j <= endCandle + LBP)
                        thisVolumeBear := thisVolumeBear + (pcCandleInThisRange * volume[j])
                    else
                        volWeight := 1 - (1 / (startCandle - LBP)) * (j - LBP)
                        thisVolumeBear := thisVolumeBear + (pcCandleInThisRange * volume[j] * volWeight)
                
                
                if (close[j] > open[j])
                    //  up
                    if (j <= endCandle + LBP)
                        thisVolumeBull := thisVolumeBull + (pcCandleInThisRange * volume[j])
                    else
                        volWeight := 1 - (1 / (startCandle - LBP)) * (j - LBP)
                        thisVolumeBull := thisVolumeBull + (pcCandleInThisRange * volume[j] * volWeight)              
                    
            j -= 1
            
        midPointForLine := math.pow(rangeStart * rangeEnd, 0.5)
        ///midPointForLine := rangeStart + ((rangeEnd - rangeStart) / 2)
        x1 := math.round((WOI + OFLC) - ((WOI / largestVol) * thisVolume1))
        x2 := math.round(WOI + OFLC)

        //dt2 = time - time[1]
        ///line.new(time + x1 * dt2, midPointForLine, time + x2 * dt2, midPointForLine, xloc = xloc.bar_time, width=VPLW)
        if (leftCol1 == applyLeftCol1)
            leftCol1 := applyLeftCol2
        else
            leftCol1 := applyLeftCol1
            
        line.new(bar_index + x1, midPointForLine, bar_index + x2, midPointForLine, width=VPLW, color=leftCol1)
        
        if (yBordersOn == true)
            line.new(bar_index[LBP + LBPA], rangeEnd, bar_index + x2, rangeEnd, width=1, color=yBordersColor, style=line.style_dotted)
        if (i == 1.0 and yBordersOn == true)
            line.new(bar_index[LBP + LBPA], rangeStart, bar_index + x2, rangeStart, width=1, color=yBordersColor, style=line.style_dotted)
        
///        line.new(bar_index + x2, rangeStart, bar_index + x2, rangeEnd, width=1, color=#000000FF, style=line.style_dashed)    
    
        if (showRightIndic == true and thisVolumeBull > thisVolumeBear)
            x2R := math.round((WOI + OFLC) + ((WOI / largestVol) * (thisVolumeBull - thisVolumeBear)))
            x1R := math.round(WOI + OFLC)
            line.new(bar_index + x1R, midPointForLine, bar_index + x2R, midPointForLine, width=VPLW, 
             color=bullColor1)
        else if (showRightIndic == true and thisVolumeBear > thisVolumeBull)
            x2R := math.round((WOI + OFLC) + ((WOI / largestVol) * (thisVolumeBear - thisVolumeBull)))
            x1R := math.round(WOI + OFLC)
            line.new(bar_index + x1R, midPointForLine, bar_index + x2R, midPointForLine, width=VPLW, 
             color=bearColor1)
        
        line.new(bar_index[LBP], low[LBP], bar_index[LBP], high[LBP], extend=extend.both, color=#948FFF37, style=line.style_dashed)
        
        if (LBPA > 0)
            line.new(bar_index[LBP + LBPA], low[LBP + LBPA], bar_index[LBP + LBPA], high[LBP + LBPA], extend=extend.both, color=#948FFF37, style=line.style_dashed)

///        l = line.new(time + 5 * dt, high, time + 10 * dt, high,  xloc = xloc.bar_time)

        
        rangeStart := rangeEnd
        rangeEnd := rangeEnd * logBase
        i := i + 1.0


