xmd79

BTC Log High/Low Chart

Apr 18th, 2023
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. // BTC Log High/Low Chart
  2. // Displays logarithmic regression lines
  3. // okor96
  4. //@version=5
  5.  
  6. indicator(title='BTC Log High/Low Chart', shorttitle='BTC H/L Chart', overlay=true)
  7.  
  8. // Calculate the number of days since January 1, 2009 for a given timestamp
  9. day(x) =>
  10. (x - timestamp(syminfo.timezone, 2009, 1, 1, 0, 0)) / (24 * 3600 * 1000)
  11.  
  12. // Calculate the high price using logarithmic regression
  13. fh(x) =>
  14. coef1 = -0.000242428211248408 * day(x) + 0.797394293577491
  15. coef2 = math.log(210994.757) / math.log(10) - math.pow(10, coef1)
  16. math.pow(10, coef2)
  17.  
  18. // Calculate the low price using logarithmic regression
  19. fl(x) =>
  20. coef1 = -0.0001830944532665595590 * day(x) + 0.8642347023073106981883
  21. coef2 = math.log(100000.00000000000000) / math.log(10) - math.pow(10, coef1)
  22. math.pow(10, coef2)
  23.  
  24. // Calculate the high and low lines
  25. th = fh(time)
  26. tl = fl(time)
  27.  
  28. // Plot the high and low lines
  29. plot(th, linewidth=2, color=color.new(color.red, 0), title='High price')
  30. plot(tl, linewidth=2, color=color.new(#19e241,0), title='Low price')
  31.  
  32. // Define a function to calculate a line using logarithmic regression between the high and low lines
  33. fi(x, c) =>
  34. y_lg_1 = math.log(fh(x)) / math.log(10)
  35. y_lg_2 = math.log(fl(x)) / math.log(10)
  36. coef2 = y_lg_1 * c + y_lg_2 * (1 - c)
  37. math.pow(10, coef2)
  38.  
  39. // Calculate and plot the three lines using logarithmic regression
  40. t1 = fi(time, 1 / 6.0)
  41. plot(t1, color=color.new(#19e241, 50), linewidth=2, title='Middle Low')
  42.  
  43. t2 = fi(time, 3.5 / 4.0)
  44. plot(t2, color=color.new(#ff5252, 50), linewidth=2, title='Middle High')
  45.  
  46. t3 = fi(time, 1 / 2.0)
  47. plot(t3, color=color.new(#ffffff, 50), linewidth=2, title='Middle')
  48.  
  49.  
  50.  
  51.  
  52.  
Advertisement
Add Comment
Please, Sign In to add comment