3VFF3H_MONS

CRN Alpha Line

May 14th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © capriole_charles
  3.  
  4. //@version=4
  5. study("CRN Alpha Line",shorttitle="CRN Alpha Line", overlay=false)
  6.  
  7. // INPUTS
  8. index_var = input(1.0,"Index threshold for Alert",step=0.05)
  9. p_old = input(0.05,"Ave. Electricity Cost $USD KWh (Pre June 2019)")
  10. p_new = input(0.04,"Ave. Electricity Cost $USD KWh (Post June 2019")
  11. elec_pct = input(0.60,"% electricity to Total Mining Costs")
  12. plot_mp = input(true,"Plot BTC Miner Price (Close + Transaction Fee Revenue / BTC)")
  13. plot_tc = input(true,"Plot Production & Electricity Cost Curves")
  14. labels = input(false,"Plot Annual Profit Margin Labels?")
  15.  
  16. // DATA
  17.  
  18. fees = security("QUANDL:BCHAIN/TRFUS","D",close)
  19.  
  20. elec_consumption() =>
  21. // Cambridge Bitcoin Electricity Consumption Index (CBECI) - Bitcoin's global electricity consumption in TwH.
  22. // NB: Uses MONTHLY averages of raw data from CBECI. TV script run-time is too slow with Daily/Weekly data here.
  23. // This requires manual updating once a month for ongoing accuracy.
  24.  
  25. d = dayofmonth
  26. m = month
  27. y = year
  28.  
  29. e = float(na)
  30. e := d==15 and m==12 and y==2014? 1.85803466666667 :
  31. d==15 and m==1 and y==2015? 1.84261966666667 :
  32. d==15 and m==2 and y==2015? 1.910415 :
  33. d==15 and m==3 and y==2015? 2.07733266666667 :
  34. d==15 and m==4 and y==2015? 2.125437 :
  35. d==15 and m==5 and y==2015? 2.10028 :
  36. d==15 and m==6 and y==2015? 2.149371 :
  37. d==15 and m==7 and y==2015? 2.21597833333333 :
  38. d==15 and m==8 and y==2015? 2.335304 :
  39. d==15 and m==9 and y==2015? 2.32026033333333 :
  40. d==15 and m==10 and y==2015? 2.15466433333333 :
  41. d==15 and m==11 and y==2015? 2.29930733333333 :
  42. d==15 and m==12 and y==2015? 2.83890766666667 :
  43. d==15 and m==1 and y==2016? 3.76853166666667 :
  44. d==15 and m==2 and y==2016? 4.984321 :
  45. d==15 and m==3 and y==2016? 5.751456 :
  46. d==15 and m==4 and y==2016? 6.09711766666667 :
  47. d==15 and m==5 and y==2016? 6.65274233333333 :
  48. d==15 and m==6 and y==2016? 6.44479366666667 :
  49. d==15 and m==7 and y==2016? 5.618041 :
  50. d==15 and m==8 and y==2016? 4.439068 :
  51. d==15 and m==9 and y==2016? 4.43830366666667 :
  52. d==15 and m==10 and y==2016? 4.95330933333334 :
  53. d==15 and m==11 and y==2016? 5.12000766666667 :
  54. d==15 and m==12 and y==2016? 5.80765 :
  55. d==15 and m==1 and y==2017? 6.54180066666666 :
  56. d==15 and m==2 and y==2017? 7.62688133333333 :
  57. d==15 and m==3 and y==2017? 7.09545833333333 :
  58. d==15 and m==4 and y==2017? 6.71110866666667 :
  59. d==15 and m==5 and y==2017? 7.62911266666667 :
  60. d==15 and m==6 and y==2017? 11.720838 :
  61. d==15 and m==7 and y==2017? 13.17811 :
  62. d==15 and m==8 and y==2017? 12.0859133333333 :
  63. d==15 and m==9 and y==2017? 14.9976133333333 :
  64. d==15 and m==10 and y==2017? 17.342 :
  65. d==15 and m==11 and y==2017? 19.9178833333333 :
  66. d==15 and m==12 and y==2017? 22.4013633333333 :
  67. d==15 and m==1 and y==2018? 28.01982 :
  68. d==15 and m==2 and y==2018? 34.9384066666667 :
  69. d==15 and m==3 and y==2018? 34.81782 :
  70. d==15 and m==4 and y==2018? 36.8095066666667 :
  71. d==15 and m==5 and y==2018? 37.6163133333333 :
  72. d==15 and m==6 and y==2018? 41.5086133333333 :
  73. d==15 and m==7 and y==2018? 44.4878133333333 :
  74. d==15 and m==8 and y==2018? 49.8791433333333 :
  75. d==15 and m==9 and y==2018? 51.38618 :
  76. d==15 and m==10 and y==2018? 51.4356766666667 :
  77. d==15 and m==11 and y==2018? 47.8622633333333 :
  78. d==15 and m==12 and y==2018? 36.0539266666667 :
  79. d==15 and m==1 and y==2019? 36.1260666666667 :
  80. d==15 and m==2 and y==2019? 36.2145133333333 :
  81. d==15 and m==3 and y==2019? 36.9071833333333 :
  82. d==15 and m==4 and y==2019? 39.3832533333333 :
  83. d==15 and m==5 and y==2019? 41.2841866666667 :
  84. d==15 and m==6 and y==2019? 47.9736866666667 :
  85. d==15 and m==7 and y==2019? 56.3321133333333 :
  86. d==15 and m==8 and y==2019? 61.70129 :
  87. d==15 and m==9 and y==2019? 67.4179133333333 :
  88. d==15 and m==10 and y==2019? 77.0788966666667 :
  89. d==15 and m==11 and y==2019? 73.8160033333333 :
  90. d==15 and m==12 and y==2019? 72.26226 :
  91. d==15 and m==1 and y==2020? 73.39557 :
  92. d==15 and m==2 and y==2020? 77.9706866666667 : na
  93. e
  94.  
  95. btc_mined_per_day() =>
  96. blocks_per_day = 144
  97. block_reward = time < timestamp(2012,11,28,0,0) ? 50 :
  98. time < timestamp(2016,7,9,0,0) ? 25 :
  99. time < timestamp(2020,5,14,0,0) ? 12.5 : 6.25 // 2020 estimated
  100. btc_per_day = blocks_per_day*block_reward
  101. btc_per_day
  102.  
  103. // CALCULATIONS
  104.  
  105. miner_price = close + fees/btc_mined_per_day()
  106.  
  107. elec = float(na)
  108. elec := na(elec_consumption()) ? elec[1] : elec_consumption()
  109.  
  110. p = time < timestamp(2019,6,30,0,0) ? p_old : p_new
  111.  
  112. btc_elec_cost = float(na)
  113. btc_elec_cost := (elec/365.25)*pow(10,9) / btc_mined_per_day() * p //convert: --> days --> KwH --> Per BTC --> * Price/KwH
  114. btc_elec_cost2= close/btc_elec_cost
  115.  
  116. total_cost = btc_elec_cost/elec_pct
  117. total_cost2 = close/total_cost
  118.  
  119. margin = ((miner_price/total_cost)-1.0)*100.0
  120. profit_margin = round(sma(margin,365))
  121. m = ''
  122. m := profit_margin > 0 ? "+" : ''
  123.  
  124. // PLOT
  125.  
  126. //index_under_cost(index,cost) => //unused
  127.  
  128. cost_under_index = btc_elec_cost2 < index_var and btc_elec_cost2[1] >= index_var
  129.  
  130. cui_value_plot = cost_under_index ? btc_elec_cost2 : 0
  131. cui_value_trigger = cui_value_plot != 0
  132.  
  133. plot(cui_value_plot, color=na, transp=100, title="<index Alert", show_last=1)
  134.  
  135. plotshape(cui_value_trigger ? (cui_value_plot-0.05) : na, title = "Cost < Index" , style = shape.triangleup, size = size.small, location = location.absolute, color = color.green)
  136.  
  137.  
  138.  
  139. hlined7 = hline(index_var, title="index_var", linewidth=1, color=#ffcd9a)
  140. a = plot(plot_tc ? btc_elec_cost2 : na,color=color.red,linewidth=2,title=" Electricity")
  141.  
  142. clr = miner_price < total_cost ? color.red : na
  143.  
  144.  
  145. // LABELS
  146.  
  147. if labels and (barstate.islast or (dayofmonth ==1 and month ==1) and profit_margin)
  148. label.new(bar_index, btc_elec_cost, style=label.style_labelup,
  149. text="Margin (p.a.)\n" + m + tostring(profit_margin) +"%",
  150. textcolor=color.white,color=color.green)
Add Comment
Please, Sign In to add comment