Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title="Bitcoin Rainbow Wave", overlay=true)
- // @leoum x.com@leomathheart
- // Just 5 Model parameters to fit all 15 years of data: {Intercept, Slope, Decay factor, Learning pace, Band width} = {1.5; 5.4; 0.8; -1.4; 2/3}
- // --- INPUT OPTIONS ---
- s11 = input.bool(true , "Show Power Law" , inline="Power_Law" , group="Rainbow chart and PL")
- s12 = input.bool(true , "Show Rainbow bands" , inline="Rainbow_bands" , group="Rainbow chart and PL")
- s13 = input.bool(false, "Show Fair value zone" , inline="Fair_rainbow" , group="Rainbow chart and PL")
- s14 = input.bool(false, "Show Rainbow chart" , inline="Rainbow_chart" , group="Rainbow chart and PL")
- s21 = input.bool(true , "Show Wave line" , inline="Wave_line" , group="Rainbow Wave chart")
- s22 = input.bool(true , "Show Wave bands" , inline="Wave_bands" , group="Rainbow Wave chart")
- s23 = input.bool(true ,"Show Fair value zone" , inline="Fair_wave" , group="Rainbow Wave chart")
- s24 = input.bool(false,"Show Rainbow Wave" , inline="Rainbow_wave" , group="Rainbow Wave chart")
- s25 = input.bool(true ,"Miners hate losses" , inline="Miners_protest", group="Rainbow Wave chart")
- s31 = input.bool(true , "Show Halvings" , inline="Halvings_marks", group="Extra Marks")
- s32 = input.bool(false, "Show 25% of Halvings" , inline="25%_marks" , group="Extra Marks")
- s33 = input.bool(false, "Show Buy-Sell Zones" , inline="Buy_Sell_zones", group="Extra Marks")
- s34 = input.bool(false, "Show Max from PL" , inline="Max_from_PL" , group="Extra Marks")
- s35 = input.bool(false, "Show Max Fair Wave" , inline="Max_Fair_Wave" , group="Extra Marks")
- // --- CALCULATING "The bitcoin halving time" using a piecewise linear function with breaks at the time of halvings.
- H000 = timestamp (2009, 01, 03, 18, 15, 05) // Block 0. The Genesis block
- H025 = timestamp (2010, 04, 22, 12, 15, 34) // Block 52 500
- H050 = timestamp (2011, 01, 28, 10, 41, 47) // Block 105 000
- H075 = timestamp (2011, 12, 14, 16, 24, 37) // Block 157 500
- H100 = timestamp (2012, 11, 28, 16, 24, 38) // Block 210 000. Halving 1 block
- H125 = timestamp (2013, 10, 09, 05, 28, 22) // Block 262 500
- H150 = timestamp (2014, 08, 11, 05, 06, 05) // Block 315 000
- H175 = timestamp (2015, 07, 29, 15, 45, 38) // Block 367 500
- H200 = timestamp (2016, 07, 09, 18, 46, 13) // Block 420 000. Halving 2 block
- H225 = timestamp (2017, 06, 23, 07, 43, 51) // Block 472 500
- H250 = timestamp (2018, 05, 29, 22, 24, 42) // Block 525 000
- H275 = timestamp (2019, 05, 24, 05, 37, 41) // Block 577 500
- H300 = timestamp (2020, 05, 11, 21, 23, 43) // Block 630 000. Halving 3 block
- H325 = timestamp (2021, 05, 08, 05, 20, 11) // Block 682 500
- H350 = timestamp (2022, 05, 05, 12, 23, 33) // Block 735 000
- H375 = timestamp (2023, 04, 29, 17, 06, 18) // Block 787 500
- H400 = timestamp (2024, 04, 20, 02, 09, 27) // Block 840 000. Halving 4 block
- // Average time between blocks in milliseconds withing a specific interval of blocks. Factual in the past.
- block_time_after_h000 = (H025 - H000) / 52500 // = milliseconds per block within the block range 0 - 52500
- block_time_after_h025 = (H050 - H025) / 52500 // = milliseconds per block within the block range 52500 - 105K
- block_time_after_h050 = (H075 - H050) / 52500 // = milliseconds per block within the block range 105K - 157500
- block_time_after_h075 = (H100 - H075) / 52500 // = milliseconds per block within the block range 157500 - 210K
- block_time_after_h100 = (H150 - H100) / 105000 // = milliseconds per block within the block range 210K - 315K
- block_time_after_h150 = (H200 - H150) / 105000 // = milliseconds per block within the block range 315K - 420K
- block_time_after_h200 = (H300 - H200) / 210000 // = 576868 milliseconds per block within the block range 420K - 630K
- block_time_after_h300 = (H400 - H300) / 210000 // = 592127 milliseconds per block within the block range 630K - 840K
- block_time_after_h400= (timestamp (2024, 09, 26, 21, 41, 57) - H200) / 442980 // = milliseconds per block within the block range 840k-863k
- // Future halving events estimates
- H425 = H400 + block_time_after_h400 * 52500
- H450 = H400 + block_time_after_h400 * 105000
- H475 = H400 + block_time_after_h400 * 157500
- H500 = H400 + block_time_after_h400 * 210000
- H525 = H400 + block_time_after_h400 * 262500
- H550 = H400 + block_time_after_h400 * 315000
- H575 = H400 + block_time_after_h400 * 367500
- H600 = H400 + block_time_after_h400 * 420000
- // Now we can convert regular "time" into "Bitcoin halving time "h": h = block height / 210 000. "h" is the number of halving cycles passed to date in %%.
- h = if time >= H400
- 4 + (time - H400) / (block_time_after_h400 * 210000)
- else if time >= H300 and time < H400
- 3 + (time - H300) / (block_time_after_h300 * 210000)
- else if time >= H200 and time < H300
- 2 + (time - H200) / (block_time_after_h200 * 210000)
- else if time >= H150 and time < H200
- 1.50 + (time - H150) / (block_time_after_h150 * 210000)
- else if time >= H100 and time < H150
- 1 + (time - H100) / (block_time_after_h100 * 210000)
- else if time >= H075 and time < H100
- 0.75 + (time - H075) / (block_time_after_h075 * 210000)
- else if time >= H050 and time < H075
- 0.50 + (time - H050) / (block_time_after_h050 * 210000)
- else if time >= H025 and time < H050
- 0.25 + (time - H025) / (block_time_after_h025 * 210000)
- else
- 0.25 - (H025 - time) / (block_time_after_h000 * 210000)
- // --- MODEL PARAMETERS - Just 5 parameters for the whole model! - Here they are all: {1.5; 5.4; 0.8; -1.4; 2/3}
- // Logarithmic regression (Power Law) model parameters (Green line on the chart). LOG(h) is the independant variable, LOG (BTC price) - is the dependant variable.
- a = 1.5 // Parameter 1 - Intercept (a): This is the constant term in the regression equation.
- b = 5.4 // Parameter 2 - Slope (b): This coefficient represents the rate of change of the dependent variable with respect to the independent variable.
- decay = math.pow(0.8, h + 1) // Parameter 3 - the exponential decay factor: 0.8 in the power of h+1 or exp(-0.223*(h+1))
- sin = math.sin(2 * math.pi * h - math.pow(h, -1.4)) // Parameter 4 - The learning curve for the time delay after halving or "The Ignorance lag": h in the power of -1.4
- width = 0.66667 // Parameter 5 - the width of the sinusoidal bands (the upper and lower shift): sin() +- 2/3.
- BTC_t = math.pow(10, a + b * math.log10(h))
- // --- FUTURE PROJECTION OFFSET ---
- var int futureBars = 3000
- he = 4 + (time - H400 + futureBars * timeframe.in_seconds() * 1000) / (block_time_after_h400* 210000)
- sine = math.sin(2 * math.pi * he - math.pow(he, -1.4))
- decaye = math.pow(0.8, he + 1)
- BTC_te = request.security(syminfo.tickerid, timeframe.period, math.pow(10, a + b * math.log10(he)))
- // --- INDICATOR PLOTTING ---
- // Plotting The Power Law Trend and Rainbow chart
- t_3 = plot(s12 or s14 ? BTC_t * math.pow(10, -3 * decay / 3) : na, color=color.rgb(100, 0, 251), linewidth = 2)
- t_2 = plot(s13 or s14 ? BTC_t * math.pow(10, -2 * decay / 3) : na, color=color.blue, linewidth = 1)
- t_1 = plot(s13 or s14 ? BTC_t * math.pow(10, -1 * decay / 3) : na, color=color.green, linewidth = 1)
- t0 = plot(s11 or s13 or s14 ? BTC_t : na, color=color.green, title="Power Law Trend", linewidth = 3)
- t1 = plot(s13 or s14 ? BTC_t * math.pow(10, +1 * decay / 3) : na, color=color.green, linewidth = 1)
- t2 = plot(s14 ? BTC_t * math.pow(10, +2 * decay / 3) : na, color=color.yellow, linewidth = 1)
- t3 = plot(s14 ? BTC_t * math.pow(10, +3 * decay / 3) : na, color=color.orange, linewidth = 1)
- t4 = plot(s14 ? BTC_t * math.pow(10, +4 * decay / 3) : na, color=color.orange, linewidth = 1)
- t5 = plot(s12 or s14 ? BTC_t * math.pow(10, +5 * decay / 3) : na, color=color.red, linewidth = 2)
- t_3e = plot(s12 or s14 ? BTC_te * math.pow(10, -3 * decaye / 3) : na, color=color.rgb(100, 0, 251), linewidth = 2, offset = futureBars, show_last = futureBars+1)
- t_2e = plot(s13 or s14 ? BTC_te * math.pow(10, -2 * decaye / 3) : na, color=color.blue, linewidth = 1, offset = futureBars, show_last = futureBars+1)
- t_1e = plot(s13 or s14 ? BTC_te * math.pow(10, -1 * decaye / 3) : na, color=color.green, linewidth = 1, offset = futureBars, show_last = futureBars+1)
- t0e = plot(s11 or s13 or s14 ? BTC_te : na, color=color.green, title="Future Power Law Trend", linewidth = 3, offset = futureBars, show_last = futureBars+1)
- t1e = plot(s13 or s14 ? BTC_te * math.pow(10, +1 * decaye / 3) : na, color=color.green, linewidth = 1, offset = futureBars, show_last = futureBars+1)
- t2e = plot(s14 ? BTC_te * math.pow(10, +2 * decaye / 3) : na, color=color.yellow, linewidth = 1, offset = futureBars, show_last = futureBars+1)
- t3e = plot(s14 ? BTC_te * math.pow(10, +3 * decaye / 3) : na, color=color.orange, linewidth = 1, offset = futureBars, show_last = futureBars+1)
- t4e = plot(s14 ? BTC_te * math.pow(10, +4 * decaye / 3) : na, color=color.orange, linewidth = 1, offset = futureBars, show_last = futureBars+1)
- t5e = plot(s12 or s14 ? BTC_te * math.pow(10, +5 * decaye / 3) : na, color=color.red, linewidth = 2, offset = futureBars, show_last = futureBars+1)
- fill(t_3, t_2, color= s14 ? color.new(color.rgb(120, 0, 255), 80) : na)
- fill(t_3e, t_2e, color= s14 and he > 4.1 ? color.new(color.rgb(120, 0, 255), 80) : na)
- fill(t_2, t_1, color= s13 or s14 ? color.new(color.blue , 60) : na)
- fill(t_2e, t_1e, color=(s13 or s14) and he > 4.1 ? color.new(color.blue , 60) : na)
- fill(t_1, t0, color= s13 or s14 ? color.new(color.rgb(0, 200, 200), 60) : na)
- fill(t_1e, t0e, color=(s13 or s14) and he > 4.1 ? color.new(color.rgb(0, 200, 200), 60) : na)
- fill(t0, t1, color= s13 or s14 ? color.new(color.green , 60) : na)
- fill(t0e, t1e, color=(s13 or s14) and he > 4.1 ? color.new(color.green , 60) : na)
- fill(t1, t2, color= s14 ? color.new(color.rgb(150, 220, 0), 80) : na)
- fill(t1e, t2e, color= s14 and he > 4.1 ? color.new(color.rgb(150, 220, 0), 80) : na)
- fill(t2, t3, color= s14 ? color.new(color.yellow, 80) : na)
- fill(t2e, t3e, color= s14 and he > 4.1 ? color.new(color.yellow, 80) : na)
- fill(t3, t4, color= s14 ? color.new(color.orange, 80) : na)
- fill(t3e, t4e, color= s14 and he > 4.1 ? color.new(color.orange, 80) : na)
- fill(t4, t5, color= s14 ? color.new(color.red, 80) : na)
- fill(t4e, t5e, color= s14 and he > 4.1 ? color.new(color.red, 80) : na)
- // Indicator 2: Wave - Damped harmonic oscillator with decaying learning time lag
- // Calculating the Rainbow Wave lines
- w_2 = BTC_t * math.pow(10, decay * ( sin - width ))
- w_1 = BTC_t * math.pow(10, decay * ( sin - width/2))
- w0 = BTC_t * math.pow(10, decay * sin )
- w1 = BTC_t * math.pow(10, decay * ( sin + width/2))
- w2 = BTC_t * math.pow(10, decay * ( sin + width ))
- w_2c = BTC_t * math.pow(10, decay * math.max(-1 , sin - width ))
- w_1c = BTC_t * math.pow(10, decay * math.max(-1 , sin - width/2))
- w0c = BTC_t * math.pow(10, decay * math.max(-width , sin ))
- w1c = BTC_t * math.pow(10, decay * math.max(-width/2, sin + width/2))
- w2c = BTC_t * math.pow(10, decay * math.max( 0 , sin + width ))
- w_2e = BTC_te * math.pow(10, decaye * ( sine - width ))
- w_1e = BTC_te * math.pow(10, decaye * ( sine - width/2))
- w0e = BTC_te * math.pow(10, decaye * sine )
- w1e = BTC_te * math.pow(10, decaye * ( sine + width/2))
- w2e = BTC_te * math.pow(10, decaye * ( sine + width ))
- w_2ce = BTC_te * math.pow(10, decaye * math.max(-1 , sine - width ))
- w_1ce = BTC_te * math.pow(10, decaye * math.max(-1 , sine - width/2))
- w0ce = BTC_te * math.pow(10, decaye * math.max(-width , sine ))
- w1ce = BTC_te * math.pow(10, decaye * math.max(-width/2, sine + width/2))
- w2ce = BTC_te * math.pow(10, decaye * math.max( 0 , sine + width ))
- // Plotting the Rainbow wave lines and fills
- wl_2 = plot((s22 or s24) and not s25 ? w_2 : (s22 or s24) and s25 ? w_2c : na, color=color.aqua, title="Wave -2 Band", linewidth=2)
- wl_2e = plot((s22 or s24) and not s25 ? w_2e : (s22 or s24) and s25 ? w_2ce : na, color=color.aqua, title="Future Wave -2 Band", linewidth=2, offset=futureBars, show_last=futureBars + 1)
- wl_1 = plot((s23 or s24) and not s25 ? w_1 : (s23 or s24) and s25 ? w_1c : na, color=color.blue, title="Wave -1 Band", linewidth=1)
- wl_1e = plot((s23 or s24) and not s25 ? w_1e : (s23 or s24) and s25 ? w_1ce : na, color=color.blue, title="Future Wave -1 Band", linewidth=1, offset=futureBars, show_last=futureBars + 1)
- wl0 = plot((s21 and not s22 and not s23 and not s24) or (s21 or s23 or s24) and not s25 ? w0 : s25 and ((s21 and not s22 and not s23 and not s24) or s23 or s24) ? w0c : na, color=color.fuchsia, title="Wave", linewidth=3)
- wl0e = plot((s21 and not s22 and not s23 and not s24) or (s21 or s23 or s24) and not s25 ? w0e : s25 and ((s21 and not s22 and not s23 and not s24) or s23 or s24) ? w0ce : na, color=color.fuchsia, title="Future Wave", linewidth=3, offset=futureBars, show_last=futureBars + 1)
- wl1 = plot((s23 or s24) and not s25 ? w1 : (s23 or s24) and s25 ? w1c : na, color=color.orange, title="Wave 1 Band", linewidth=1)
- wl1e = plot((s23 or s24) and not s25 ? w1e : (s23 or s24) and s25 ? w1ce : na, color=color.orange, title="Future Wave 1 Band", linewidth=1, offset=futureBars, show_last=futureBars + 1)
- wl2 = plot((not s24 and s22) or (s24 and not s25) ? w2 : s24 and s25 ? w2c : na, color=color.red, title="Wave 2 Band", linewidth=2)
- wl2e = plot((not s24 and s22) or (s24 and not s25) ? w2e : s24 and s25 ? w2ce : na, color=color.red, title="Future Wave 2 Band", linewidth=2, offset=futureBars, show_last=futureBars + 1)
- fill(wl1 , wl2 , color= s24 ? color.new(color.red , 80) : na)
- fill(wl1e , wl2e , color= s24 and he > 4.1 ? color.new(color.red , 80) : na)
- fill(wl0 , wl1 , color= s24 or s23 ? color.new(color.orange, 80) : na)
- fill(wl0e , wl1e , color=(s24 or s23) and he > 4.1 ? color.new(color.orange, 80) : na)
- fill(wl_1 , wl0 , color= s24 or s23 ? color.new(color.green , 80) : na)
- fill(wl_1e, wl0e , color=(s24 or s23) and he > 4.1 ? color.new(color.green , 80) : na)
- fill(wl_2 , wl_1 , color= s24 ? color.new(color.blue , 80) : na)
- fill(wl_2e, wl_1e, color= s24 and he > 4.1 ? color.new(color.blue , 80) : na)
- // Indicator 3: Halving and Block marks and labels
- if s31
- int[] lineXCoords = array.from(H025 , H050 , H075 , H100 , H125 , H150 , H175 , H200 , H225 , H250 , H275 , H300 , H325 , H350 , H375 , H400 , H425 , H450 , H475 , H500 , H525 , H550 , H575 , H600 )
- float[] lineYCoords1 = array.from(0.002 , 0.15 , 1.5 , 7.3 , 25 , 68 , 180 , 405 , 820 , 1520 , 2740 , 4600 , 7500 , 11800 , 18000 , 26000 , 38500 , 55000 , 76000 , 102000 , 139000 , 185000 , 242000 , 309000 )
- float[] lineYCoords2 = array.from(0.59 , 11.5 , 95.6 , 367 , 1050 , 2360 , 5000 , 9390 , 16600 , 25500 , 39500 , 58000 , 83500 , 112500 , 150000 , 198000 , 257000 , 327000 , 414000 , 514000 , 635000 , 780000 , 935000 , 1126000 )
- int[] lineWidths = array.from(1 , 1 , 1 , 2 , 1 , 1 , 1 , 2 , 1 , 1 , 1 , 2 , 1 , 1 , 1 , 2 , 1 , 1 , 1 , 2 , 1 , 1 , 1 , 2 )
- bool[] lineDashed = array.from(true , true , true , false , true , true , true , false , true , true , true , false , true , true , true , false , true , true , true , false , true , true , true , false )
- string[] labelTexts = array.from("h=25% 22/4/10 t=473", "h=50% 28/1/11 t=754", "h=75% 14/12/11 t=1074", "h=100% 28/11/12 t=1424", "h=125% 9/10/13 t=1739", "h=150% 11/8/14 t=2045", "h=175% 29/7/15 t=2397", "h=200% 9/7/16 t=2744", "h=225% 23/6/17 t=3092", "h=250% 29/5/18 t=3433", "h=275% 24/5/19 t=3792", "h=300% 11/5/20 t=4146", "h=325% 8/5/21 t=4507", "h=350% 5/5/22 t=4869", "h=375% 29/4/23 t=5228", "h=400% 20/4/24 t=5585", "h=425% 10/04/25 t=5940", "h=450% 30/3/26 t=6295", "h=475% 20/3/27 t=6650", "h=500% 10/3/28 t=7006", "h=525% 28/2/29 t=7361", "h=550% 18/2/30 t=7716", "h=575% 8/2/31 t=8071", "h=600% 29/1/32 t=8426")
- for i = 0 to array.size(lineXCoords) - 1
- var line currentLine = na
- var label currentLabel = na
- currentLine := s32 or not array.get(lineDashed, i) ? line.new(x1 = array.get(lineXCoords, i), y1 = array.get(lineYCoords1, i), x2 = array.get(lineXCoords, i), y2 = array.get(lineYCoords2, i), color = color.yellow, width = array.get(lineWidths, i), xloc = xloc.bar_time, style = array.get(lineDashed, i) ? line.style_dashed : line.style_solid ) : na
- currentLabel := s32 or not array.get(lineDashed, i) ? label.new(x = array.get(lineXCoords, i), y = array.get(lineYCoords1, i), text = array.get(labelTexts, i), color = color.yellow, style = label.style_label_left, size = size.normal, xloc = xloc.bar_time) : na
- // Indicator 4: Top or the cycles marks and labels
- if s34
- int[] lineXCoords4 = array.from(timestamp(2009,11,18,12,00,00),timestamp(2010,05,08,12,00,00),timestamp(2011,05,20,12,00,00),timestamp(2014,02,06,12,00,00),timestamp(2017,09,01,12,00,00),timestamp(2021,06,26,12,00,00),timestamp(2025,05,11,12,00,00),timestamp(2029,04,01,12,00,00),timestamp(2033,02,23,12,00,00))
- float[] lineYCoords14 = array.from(0.04 ,0.43 ,26.43 ,1572.0 , 17827.0 , 84554.0 , 262350.0 , 642047.0 , 1355151.0 )
- float[] lineYCoords24 = array.from(25.0 ,60.0 ,900 ,15000.0 ,100000.0 , 500000.0 , 1000000.0 , 2000000.0 , 4000000.0 )
- string[] labelTexts4 = array.from("h=16% 18/11/9 t=336 $0.04" ,"h=26% 8/5/10 t=493 $0.43" ,"h=48% 20/5/11 t=733 $26" ,"h=135% 6/2/14 t=1860 $1.6k" ,"h=230% 1/9/17 t=3163 $17.8k" ,"h=328% 26/6/21 t=4557 $84.5k" ,"h=427% 11/5/25 t=5973 $262k" ,"h=526% 1/4/29 t=7394 $642k" ,"h=626% 23/2/33 t=8818 $1.35m" )
- for i = 0 to array.size(lineXCoords4) - 1
- var line currentLine = na
- var label currentLabel = na
- currentLine := line.new(x1 = array.get(lineXCoords4, i), y1 = array.get(lineYCoords14, i), x2 = array.get(lineXCoords4, i), y2 = array.get(lineYCoords24, i), color = color.red, width = 1, xloc = xloc.bar_time, style = line.style_solid )
- currentLabel := label.new(x = array.get(lineXCoords4, i), y = array.get(lineYCoords24, i), text = array.get(labelTexts4, i), color = color.red, style = label.style_label_left, size = size.normal, xloc = xloc.bar_time)
- if s35
- int[] lineXCoords5 = array.from(timestamp(2011,07,04,12,00,00),timestamp(2014,04,17,12,00,00),timestamp(2017,11,01,12,00,00),timestamp(2021,08,02,12,00,00),timestamp(2025,06,16,12,00,00),timestamp(2029,05,08,12,00,00),timestamp(2033,03,29,12,00,00))
- float[] lineYCoords15 = array.from(18.6 ,1100 ,12900 ,64630 ,211128 ,539846 ,1181518 )
- float[] lineYCoords25 = array.from(370.0 ,6500 ,48000 ,230000 ,500000 ,1000000 ,2000000 )
- string[] labelTexts5 = array.from("h=63% 4/7/11 t=902 $18.6" ,"h=141% 17/4/14 t=1930 $1.1k" ,"h=235% 1/11/17 t=3224 $13k" ,"h=332% 2/8/21 t=4603 $65k" ,"h=431% 16/6/25 t=6009 $211k" ,"h=531% 8/5/29 t=7431 $540k" ,"h=630% 29/3/33 t=8852 $1.2m" )
- for i = 0 to array.size(lineXCoords5) - 1
- var line currentLine = na
- var label currentLabel = na
- currentLine := line.new(x1 = array.get(lineXCoords5, i), y1 = array.get(lineYCoords15, i), x2 = array.get(lineXCoords5, i), y2 = array.get(lineYCoords25, i), color = color.orange, width = 1, xloc = xloc.bar_time, style = line.style_solid )
- currentLabel := label.new(x = array.get(lineXCoords5, i), y = array.get(lineYCoords25, i), text = array.get(labelTexts5, i), color = color.orange, style = label.style_label_left, size = size.normal, xloc = xloc.bar_time)
- // Indicator 5. Buy and Sell Zones
- // Buy/Sell Lines by coordinates x=h and y=price. Drown by the intersection points of the upper and lower wave lines with the rainbow lines ## +4, +3, -1, -3.
- float[] x4 = array.from( 0.5165, 1.236 , 2.172, 3.15 , 4.138 , 5.1292, 6.125 )
- float[] x3 = array.from( 0.7056, 1.534 , 2.49 , 3.4738, 4.465 , 5.4577, 6.454 )
- float[] x_1 = array.from(0.2950, 0.7056, 1.534 , 2.49 , 3.4738, 4.465 , 5.4577, 6.454 )
- float[] x_3 = array.from(0.4400, 1.0877, 2.0066, 2.98 , 3.9695, 4.9648, 5.9560, 6.953 )
- float[] y4 = array.from( 7.93 , 641 , 9436 , 52208 , 179290, 475000, 1056000)
- float[] y3 = array.from( 23.0 , 1176 , 12617, 61725 , 201500, 521700, 1152000)
- float[] y_1 = array.from(0.027 , 2.87 , 205 , 3066 , 19913 , 81100 , 251800, 648500 )
- float[] y_3 = array.from(0.07 , 11.7 , 417 , 4453 , 25325 , 100100, 297900, 756900 )
- // Helper functions
- f_sell_line(i) => array.get(y4, i) * math.pow(array.get(y3, i) / array.get(y4, i), (h - array.get(x4, i)) / (array.get(x3, i) - array.get(x4, i)))
- f_buy_line(i) => array.get(y_1, i) * math.pow(array.get(y_3, i) / array.get(y_1, i), (h - array.get(x_1, i)) / (array.get(x_3, i) - array.get(x_1, i)))
- f_sell_linee(i) => array.get(y4, i) * math.pow(array.get(y3, i) / array.get(y4, i), (he - array.get(x4, i)) / (array.get(x3, i) - array.get(x4, i)))
- f_buy_linee(i) => array.get(y_1, i) * math.pow(array.get(y_3, i) / array.get(y_1, i), (he - array.get(x_1, i)) / (array.get(x_3, i) - array.get(x_1, i)))
- //Sell Zones
- SellLine = (not s24 and s22) or (s24 and not s25) ? w2 : s24 and s25 ? w2c : na // Default to w2 if no zone matches
- for i = 0 to 3 // Iterate through sell zones in the past
- if h > array.get(x4, i) and h < array.get(x3, i)
- SellLine := f_sell_line(i)
- break // Exit loop when a match is found
- SellLinee = (not s24 and s22) or (s24 and not s25) ? w2e : s24 and s25 ? w2ce : na // Default to w2 if no zone matches
- for i = 4 to 6 // Iterate sell zones in the future
- if he > array.get(x4, i) and he < array.get(x3, i)
- SellLinee := f_sell_linee(i)
- break // Exit loop when a match is found
- // Buy Zones
- BuyLine = w_2c // Default to w2 if no zone matches
- for i = 0 to 4 // Iterate through buy zones in the past
- if h > array.get(x_1, i) and h < array.get(x_3, i)
- BuyLine := f_buy_line(i)
- break // Exit loop when a match is found
- BuyLinee = w_2ce // Default to w2 if no zone matches
- for i = 5 to 7 // for i = 0 to 5 // Iterate through buy zones in the future
- if he > array.get(x_1, i) and he < array.get(x_3, i)
- BuyLinee := f_buy_linee(i)
- break // Exit loop when a match is found
- // Draw the cut off sell and buy lines
- Lbuy = plot(BuyLine , na, color = s33 ? color.green : na, linewidth=1)
- Lbuye = plot(BuyLinee , na, color = s33 ? color.green : na, linewidth=1, offset=futureBars, show_last=futureBars + 1)
- Lsell = plot(SellLine , na, color = s33 ? color.red : na, linewidth=1)
- Lselle = plot(SellLinee, na, color = s33 ? color.red : na, linewidth=1, offset=futureBars, show_last=futureBars + 1)
- // Fill the sell and buy zones
- fill(Lsell , wl2, color = s33 ? color.new(color.red, 40) : na, title="Sell Zones")
- fill(Lselle, wl2e, color = s33 ? color.new(color.red, 40) : na, title="Buy Zones")
- fill(Lbuy , wl_2, color = s33 ? color.new(color.green, 40) : na, title="Future Sell Zones")
- fill(Lbuye , wl_2e, color = s33 ? color.new(color.green, 40) : na, title="Future Buy Zones")
Advertisement
Add Comment
Please, Sign In to add comment