Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // BTC Log High/Low Chart
- // Displays logarithmic regression lines
- // okor96
- //@version=5
- indicator(title='BTC Log High/Low Chart', shorttitle='BTC H/L Chart', overlay=true)
- // Calculate the number of days since January 1, 2009 for a given timestamp
- day(x) =>
- (x - timestamp(syminfo.timezone, 2009, 1, 1, 0, 0)) / (24 * 3600 * 1000)
- // Calculate the high price using logarithmic regression
- fh(x) =>
- coef1 = -0.000242428211248408 * day(x) + 0.797394293577491
- coef2 = math.log(210994.757) / math.log(10) - math.pow(10, coef1)
- math.pow(10, coef2)
- // Calculate the low price using logarithmic regression
- fl(x) =>
- coef1 = -0.0001830944532665595590 * day(x) + 0.8642347023073106981883
- coef2 = math.log(100000.00000000000000) / math.log(10) - math.pow(10, coef1)
- math.pow(10, coef2)
- // Calculate the high and low lines
- th = fh(time)
- tl = fl(time)
- // Plot the high and low lines
- plot(th, linewidth=2, color=color.new(color.red, 0), title='High price')
- plot(tl, linewidth=2, color=color.new(#19e241,0), title='Low price')
- // Define a function to calculate a line using logarithmic regression between the high and low lines
- fi(x, c) =>
- y_lg_1 = math.log(fh(x)) / math.log(10)
- y_lg_2 = math.log(fl(x)) / math.log(10)
- coef2 = y_lg_1 * c + y_lg_2 * (1 - c)
- math.pow(10, coef2)
- // Calculate and plot the three lines using logarithmic regression
- t1 = fi(time, 1 / 6.0)
- plot(t1, color=color.new(#19e241, 50), linewidth=2, title='Middle Low')
- t2 = fi(time, 3.5 / 4.0)
- plot(t2, color=color.new(#ff5252, 50), linewidth=2, title='Middle High')
- t3 = fi(time, 1 / 2.0)
- plot(t3, color=color.new(#ffffff, 50), linewidth=2, title='Middle')
Advertisement
Add Comment
Please, Sign In to add comment