Adap
Adap
0) and
Adaptive Trend Finder (GPL-3.0)
// © ChartPrime and Julien_Eche
//@version=6
indicator("Fibonacci Trend with Adaptive Channels", overlay = true, max_lines_count
= 500, max_bars_back = 1200)
//
-----------------------------------------------------------------------------------
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
---------------------------------}
//
-----------------------------------------------------------------------------------
---------------------------------{
// EMA Inputs
color ema10_color = input.color(color.blue, "EMA 10 Color", group = "EMA
Settings", inline = "ema1")
color ema55_color = input.color(color.orange, "EMA 55 Color", group = "EMA
Settings", inline = "ema2")
color ema200_color = input.color(color.purple, "EMA 200 Color", group = "EMA
Settings", inline = "ema3")
//
-----------------------------------------------------------------------------------
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
---------------------------------}
//
-----------------------------------------------------------------------------------
---------------------------------{
// Fibonacci Calculations
[supertrend, direction] = ta.supertrend(trend_, 25)
ema10 = ta.ema(close, 10)
ema55 = ta.ema(close, 55)
ema200 = ta.ema(close, 200)
draw_fibb(trend)=>
var h = float(na)
var l = float(na)
var hi = int(na)
var li = int(na)
var val_0 = float(na)
var val_ = float(na)
atr = ta.atr(200)
if trend != trend[1]
line.delete(fib_d.fib_)
line.delete(fib_d.fib0)
line.delete(fib_d.fib05)
line.delete(fib_d.fib_di)
line.delete(fib_d.fib236)
line.delete(fib_d.fib382)
line.delete(fib_d.fib618)
line.delete(fib_d.fib786)
label.delete(fib_d.H)
label.delete(fib_d.L)
label.delete(fib_d.L0)
label.delete(fib_d.L_)
label.delete(fib_d.L236)
label.delete(fib_d.L382)
label.delete(fib_d.L618)
label.delete(fib_d.L786)
if trend == trend[1]
if low < fib_d.fib_.get_y1()
fib_d.fib_.set_y1(low)
fib_d.fib_.set_y2(low)
if high > fib_d.fib0.get_y1()
fib_d.fib0.set_y1(high)
fib_d.fib0.set_y2(high)
if high == fib_d.fib0.get_y1()
h := high
hi := bar_index
label.delete((fib_d[1]).H)
fib_d.H := label.new(hi, h, str.tostring(h, "#,###.####"), color =
#15373b)
if low == fib_d.fib_.get_y1()
l := low
li := bar_index
label.delete((fib_d[1]).L)
fib_d.L := label.new(li, l, str.tostring(l, "#,###.####"), style =
label.style_label_up, color = #15373b)
fib_d.fib_.set_x2(bar_index+extend)
fib_d.fib0.set_x2(bar_index+extend)
line.delete((fib_d[1]).fib_di)
fib_d.fib_di := line.new(li, l, hi, h, style = line.style_dashed, color =
fibo_color)
line.delete((fib_d[1]).fib05)
line.delete((fib_d[1]).fib382)
line.delete((fib_d[1]).fib236)
line.delete((fib_d[1]).fib618)
line.delete((fib_d[1]).fib786)
if trend == -1
val_0 := fib_d.fib0.get_y1()
val_ := fib_d.fib_.get_y1()
if trend == 1
val_0 := fib_d.fib_.get_y1()
val_ := fib_d.fib0.get_y1()
label.delete((fib_d[1]).L0)
label.delete((fib_d[1]).L_)
label.delete((fib_d[1]).L236)
label.delete((fib_d[1]).L382)
label.delete((fib_d[1]).L618)
label.delete((fib_d[1]).L786)
get_tf_multiplier() =>
var float multiplier = 1.0
if syminfo.type == "crypto"
if timeframe.isdaily
multiplier := 365
else if timeframe.isweekly
multiplier := 52
else
if timeframe.isdaily
multiplier := 252
else if timeframe.isweekly
multiplier := 52
multiplier
is_valid_timeframe() =>
timeframe.isdaily or timeframe.isweekly
var array<int> Periods = periodMode ? array.from(na, 300, 350, 400, 450, 500, 550,
600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200) :
array.from(na, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160,
170, 180, 190, 200)
if barstate.islast
float highestPearsonR = math.max(pearsonR01, pearsonR02, pearsonR03,
pearsonR04, pearsonR05, pearsonR06, pearsonR07, pearsonR08, pearsonR09, pearsonR10,
pearsonR11, pearsonR12, pearsonR13, pearsonR14, pearsonR15, pearsonR16, pearsonR17,
pearsonR18, pearsonR19)
int detectedPeriod = na
float detectedSlope = na
float detectedIntrcpt = na
float detectedStdDev = na
if highestPearsonR == pearsonR01
detectedPeriod := Periods.get(1)
detectedSlope := slope01
detectedIntrcpt := intercept01
detectedStdDev := stdDev01
else if highestPearsonR == pearsonR02
detectedPeriod := Periods.get(2)
detectedSlope := slope02
detectedIntrcpt := intercept02
detectedStdDev := stdDev02
else if highestPearsonR == pearsonR03
detectedPeriod := Periods.get(3)
detectedSlope := slope03
detectedIntrcpt := intercept03
detectedStdDev := stdDev03
else if highestPearsonR == pearsonR04
detectedPeriod := Periods.get(4)
detectedSlope := slope04
detectedIntrcpt := intercept04
detectedStdDev := stdDev04
else if highestPearsonR == pearsonR05
detectedPeriod := Periods.get(5)
detectedSlope := slope05
detectedIntrcpt := intercept05
detectedStdDev := stdDev05
else if highestPearsonR == pearsonR06
detectedPeriod := Periods.get(6)
detectedSlope := slope06
detectedIntrcpt := intercept06
detectedStdDev := stdDev06
else if highestPearsonR == pearsonR07
detectedPeriod := Periods.get(7)
detectedSlope := slope07
detectedIntrcpt := intercept07
detectedStdDev := stdDev07
else if highestPearsonR == pearsonR08
detectedPeriod := Periods.get(8)
detectedSlope := slope08
detectedIntrcpt := intercept08
detectedStdDev := stdDev08
else if highestPearsonR == pearsonR09
detectedPeriod := Periods.get(9)
detectedSlope := slope09
detectedIntrcpt := intercept09
detectedStdDev := stdDev09
else if highestPearsonR == pearsonR10
detectedPeriod := Periods.get(10)
detectedSlope := slope10
detectedIntrcpt := intercept10
detectedStdDev := stdDev10
else if highestPearsonR == pearsonR11
detectedPeriod := Periods.get(11)
detectedSlope := slope11
detectedIntrcpt := intercept11
detectedStdDev := stdDev11
else if highestPearsonR == pearsonR12
detectedPeriod := Periods.get(12)
detectedSlope := slope12
detectedIntrcpt := intercept12
detectedStdDev := stdDev12
else if highestPearsonR == pearsonR13
detectedPeriod := Periods.get(13)
detectedSlope := slope13
detectedIntrcpt := intercept13
detectedStdDev := stdDev13
else if highestPearsonR == pearsonR14
detectedPeriod := Periods.get(14)
detectedSlope := slope14
detectedIntrcpt := intercept14
detectedStdDev := stdDev14
else if highestPearsonR == pearsonR15
detectedPeriod := Periods.get(15)
detectedSlope := slope15
detectedIntrcpt := intercept15
detectedStdDev := stdDev15
else if highestPearsonR == pearsonR16
detectedPeriod := Periods.get(16)
detectedSlope := slope16
detectedIntrcpt := intercept16
detectedStdDev := stdDev16
else if highestPearsonR == pearsonR17
detectedPeriod := Periods.get(17)
detectedSlope := slope17
detectedIntrcpt := intercept17
detectedStdDev := stdDev17
else if highestPearsonR == pearsonR18
detectedPeriod := Periods.get(18)
detectedSlope := slope18
detectedIntrcpt := intercept18
detectedStdDev := stdDev18
else
detectedPeriod := Periods.get(19)
detectedSlope := slope19
detectedIntrcpt := intercept19
detectedStdDev := stdDev19
if na(baseLine)
baseLine := line.new(startAtBar, startPrice, bar_index, endPrice, width =
lineWidth, extend = EXTEND_STYLE, color = color.new(midline_color, midline_transp),
style = midLineStyle == "Dotted" ? line.style_dotted : midLineStyle == "Dashed" ?
line.style_dashed : line.style_solid)
else
line.set_xy1(baseLine, startAtBar, startPrice)
line.set_xy2(baseLine, bar_index, endPrice)
if na(upperFill)
upperFill := linefill.new(upperLine, baseLine, color =
color.new(channel_color, fillTransparency))
if na(lowerFill)
lowerFill := linefill.new(baseLine, lowerLine, color =
color.new(channel_color, fillTransparency))
if showAutoSelectedPeriod
table.cell(t, 0, 0, text1, text_color = colorInputLight, text_size =
textSizeInput == "Large" ? size.large : textSizeInput == "Small" ? size.small :
size.normal)
if showTrendStrength
if showPearsonInput
table.cell(t, 0, 1, "Pearson's R: " + str.tostring(detectedSlope >
0.0 ? -highestPearsonR : highestPearsonR, "#.###"), text_color = channel_color,
text_size = textSizeInput == "Large" ? size.large : textSizeInput == "Small" ?
size.small : size.normal)
else
table.cell(t, 0, 1, "Trend Strength: " + confidence(highestPearsonR),
text_color = channel_color, text_size = textSizeInput == "Large" ? size.large :
textSizeInput == "Small" ? size.small : size.normal)
float cagr = na
if not na(detectedPeriod) and bar_index >= detectedPeriod and
is_valid_timeframe()
float num_of_periods = detectedPeriod
float multiplier = get_tf_multiplier()
float startClosePrice = close[detectedPeriod - 1]
cagr := math.pow(close / startClosePrice, multiplier / num_of_periods) - 1
//
-----------------------------------------------------------------------------------
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
---------------------------------}
//
-----------------------------------------------------------------------------------
---------------------------------{
draw_fibb(direction)
plot(ema10, title="EMA 10", color=ema10_color, linewidth=1)
plot(ema55, title="EMA 55", color=ema55_color, linewidth=1)
plot(ema200, title="EMA 200", color=ema200_color, linewidth=2)