Bitcoin Best Value Corridor
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © LJBunyan

//@version=5
indicator(title = "Bitcoin Best Value Corridor", shorttitle = "BBVC", overlay = true)

// Days X-Axis Value

start = time == timestamp(2010,7,19,0,0) // First BLX Bitcoin Date
days = request.security(syminfo.tickerid, "D", ta.barssince(start))
offset = 561 // days between 2009/1/1 and "start" 561 - 579
d = days + offset

//Logarithmic Equations

// Center logarithmic trendline
a1 = input(-18, 'Regression Middle')
b1 = input(5.9466, 'Regression Gradient')
e1 = a1 + (b1 * math.log10(d))
y1 = 2 * math.pow(10, e1)

// Bottom logarithmic trendline
a2 = input(-18.18, 'Regression Lower')
b2 = input(5.9466, 'Regression Gradient')
e2 = a2 + (b2 * math.log10(d))
y2 = 2 * math.pow(10, e2)

// Peak logarithmic trendline
a3 = input(-17.82, 'Regression Higher')
b3 = input(5.9466, 'Regression Gradient')
e3 = a3 + (b3 * math.log10(d))
y3 = 2 * math.pow(10, e3)

// Plot

// Plotting each trendline
Fair = plot(y1, color = color.green, title = "Middle")
Lower = plot(y2, color = color.lime, title = "Lower")
Higher = plot(y3, color = color.lime, title = "Higher")

// Shading between each trendline
fill = input(true, "Plot Line Fill?")
fill(Higher, Fair, color = (color.new(color.green, 90)))
fill(Fair, Lower, color = (color.new(color.green, 90)))

//Label

// Orange label for center logarithmic trendline. Format.mintick gives two decimal places
labeltext = str.tostring(y1, format = format.mintick)

ourlabel = label.new(
 x              = bar_index,
 y              = y1,
 text           = labeltext,
 color          = color.new(color.green, 50),
 textcolor      = color.white,
 style          = label.style_label_left,
 size           = size.normal)

// Plots label for current bar only
label.delete(ourlabel[1])

// Green label for bottom logarithmic trendline. Format.mintick gives two decimal places
labeltext2 = str.tostring(y2, format = format.mintick)

ourlabel2 = label.new(
 x              = bar_index,
 y              = y2,
 text           = labeltext2,
 color          = color.new(color.lime, 50),
 textcolor      = color.white,
 style          = label.style_label_up,
 size           = size.normal)

// Plots label for current bar only
label.delete(ourlabel2[1])

// Red label for peak logarithmic trendline. Format.mintick gives two decimal places
labeltext3 = str.tostring(y3, format = format.mintick)

ourlabel3 = label.new(
 x              = bar_index,
 y              = y3,
 text           = labeltext3,
 color          = color.new(color.lime, 50),
 textcolor      = color.white,
 style          = label.style_label_down,
 size           = size.normal)

// Plots label for current bar only
label.delete(ourlabel3[1])