0% found this document useful (0 votes)
29 views10 pages

Adap

This document contains a Pine Script™ code for a trading indicator that combines Fibonacci Trend and Adaptive Trend Finder functionalities. It allows users to customize various settings related to Fibonacci levels, EMA colors, and adaptive channel parameters. The script includes calculations for Fibonacci levels, trend direction, and visual representation on trading charts.

Uploaded by

zakarie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

Adap

This document contains a Pine Script™ code for a trading indicator that combines Fibonacci Trend and Adaptive Trend Finder functionalities. It allows users to customize various settings related to Fibonacci levels, EMA colors, and adaptive channel parameters. The script includes calculations for Fibonacci levels, trend direction, and visual representation on trading charts.

Uploaded by

zakarie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

/// This Pine Script™ code combines Fibonacci Trend [ChartPrime] (MPL-2.

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)

//
-----------------------------------------------------------------------------------

// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
---------------------------------}

//
-----------------------------------------------------------------------------------
---------------------------------{

// Fibonacci Trend Inputs


float trend_ = input.float(4, "Trend Period", step = 0.01, group = "Fibonacci
Trend Settings")
int extend = input.int(15, "Extend", group = "Fibonacci Trend Settings", inline
= "1")
color fibo_color = input.color(color.gray, "Fibonacci Color", group = "Fibonacci
Trend Settings", inline = "2")
color fill_col = input.color(#2689901c, "Fill Color", group = "Fibonacci Trend
Settings", inline = "2")
float v_236 = input.float(0.236, "Fib 1")*100
float v_382 = input.float(0.382, "Fib 2")*100
float v_618 = input.float(0.618, "Fib 3")*100
float v_786 = input.float(0.786, "Fib 4")*100

// 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")

// Adaptive Trend Finder Inputs


sourceInput = input.source(close, title = "Source", group = "Adaptive Channel
Settings")
bool periodMode = input.bool(false, "Use Long-Term Channel", group = "Adaptive
Channel Settings", tooltip = "In Long-Term Channel mode, if the channel is not
visible, scroll back on the chart for additional historical data. To view both
Short-Term and Long-Term channels simultaneously, load this indicator twice on your
chart.")
float devMultiplier = input.float(2.0, "Deviation Multiplier:", group = "Adaptive
Channel Settings", step = 0.1)
color channel_color = input.color(color.gray, "Channel Color", group = "Adaptive
Channel Settings", inline = "channel")
string lineStyle1 = input.string("Solid", "", group = "Adaptive Channel Settings",
inline = "channel", options = ["Solid", "Dotted", "Dashed"])
string extendStyle = input.string("Extend Right", "", group = "Adaptive Channel
Settings", inline = "channel", options = ["Extend Right", "Extend Both", "Extend
None", "Extend Left"])
int fillTransparency = input.int(93, "Fill Transp:", group = "Adaptive Channel
Settings", inline = "transp", minval = 0, maxval = 100, step = 1)
int channelTransparency = input.int(40, "Line Transp:", group = "Adaptive Channel
Settings", inline = "transp", minval = 0, maxval = 100, step = 1)
color midline_color = input.color(color.blue, "Midline Color", group = "Adaptive
Channel Settings", inline = "midline")
int midline_transp = input.int(100, "Midline Transp:", group = "Adaptive Channel
Settings", inline = "midline", minval = 0, maxval = 100, step = 10)
int lineWidth = input.int(1, "Midline Width:", group = "Adaptive Channel Settings",
inline = "midline")
string midLineStyle = input.string("Dashed", "Midline Style:", group = "Adaptive
Channel Settings", inline = "midline", options = ["Dotted", "Solid", "Dashed"])
bool showAutoSelectedPeriod = input(true, "Show Auto-Selected Period", group =
"Table Settings", tooltip = "Displays the length of the period automatically
selected by the indicator that shows the strongest trend.")
bool showTrendStrength = input(true, "Show Trend Strength", group = "Table
Settings", inline = "secondLine")
bool showPearsonInput = input.bool(false, "Show Pearson's R", group = "Table
Settings", inline = "secondLine", tooltip = "Pearson's R measures the linear
relationship between price movements and trend projection.")
bool showTrendAnnualizedReturn = input(true, "Show Trend Annualized Return", group
= "Table Settings", tooltip = "Displays the annualized return (CAGR) of the trend
over the auto-selected period.")
string tablePositionInput = input.string("Bottom Right", "Table Position", options
= ["Bottom Right", "Bottom Left", "Middle Right", "Middle Left", "Top Right", "Top
Left", "Top Center", "Bottom Center"], group = "Table Settings")
string textSizeInput = input.string("Normal", "Text Size", options = ["Normal",
"Large", "Small"], group = "Table Settings")

// UDT for Fibonacci


type data
line fib05 = na
line fib0 = na
line fib236 = na
line fib382 = na
line fib618 = na
line fib786 = na
line fib_ = na
line fib_di = na
label H = na
label L = na
label L0 = na
label L236 = na
label L382 = na
label L618 = na
label L786 = na
label L_ = na

var fib_d = data.new()

//
-----------------------------------------------------------------------------------

// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
---------------------------------}

//
-----------------------------------------------------------------------------------
---------------------------------{

// 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] and trend == -1


fib_d.fib_ := line.new(bar_index, low, bar_index, low, color = fibo_color,
width = 2)
fib_d.fib0 := line.new(bar_index, high+atr*3, bar_index, high+atr*3, color
= fibo_color, width = 2)

if trend != trend[1] and trend == 1


fib_d.fib_ := line.new(bar_index, high, bar_index, high, color =
fibo_color, width = 2)
fib_d.fib0 := line.new(bar_index, low-atr*3, bar_index, low-atr*3, color =
fibo_color, width = 2)
fib_d.fib_di := line.new(li, l, hi, h, style = line.style_dashed, color =
fibo_color)

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)

if fib_d.fib_di.get_x1() < fib_d.fib0.get_x1() or fib_d.fib_di.get_x2() <


fib_d.fib0.get_x1()
line.delete(fib_d.fib_di)

size_step = (fib_d.fib0.get_y1() - fib_d.fib_.get_y1()) / 100

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()

fib_d.fib236 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_236 *


trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_236 * trend*-1, color =
fibo_color)
fib_d.fib382 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_382 *
trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_382 * trend*-1, color =
fibo_color)
fib_d.fib05 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * 50 *
trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * 50 * trend*-1, color =
color.new(fibo_color, 50), style = line.style_dotted)
fib_d.fib618 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_618 *
trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_618 * trend*-1, color =
fibo_color)
fib_d.fib786 := line.new(fib_d.fib0.get_x1(), val_0 - size_step * v_786 *
trend*-1, fib_d.fib0.get_x2(), val_0 - size_step * v_786 * trend*-1, color =
fibo_color)

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)

fib_d.L0 := label.new(bar_index+extend, val_0, text = "0 " +


str.tostring(val_0, "(#,###.####)"), textcolor = fibo_color, color =
chart.bg_color, style = label.style_label_left)
fib_d.L_ := label.new(bar_index+extend, val_, text = "1 " +
str.tostring(val_, "(#,###.####)"), textcolor = fibo_color, color = chart.bg_color,
style = label.style_label_left)
fib_d.L236 := label.new(bar_index+extend, fib_d.fib236.get_y1(), text =
str.tostring(v_236/100) + str.tostring(fib_d.fib236.get_y1(), " (#,###.####)"),
textcolor = fibo_color, color = chart.bg_color, style = label.style_label_left)
fib_d.L382 := label.new(bar_index+extend, fib_d.fib382.get_y1(), text =
str.tostring(v_382/100) + str.tostring(fib_d.fib382.get_y1(), " (#,###.####)"),
textcolor = fibo_color, color = chart.bg_color, style = label.style_label_left)
fib_d.L618 := label.new(bar_index+extend, fib_d.fib618.get_y1(), text =
str.tostring(v_618/100) + str.tostring(fib_d.fib618.get_y1(), " (#,###.####)"),
textcolor = fibo_color, color = chart.bg_color, style = label.style_label_left)
fib_d.L786 := label.new(bar_index+extend, fib_d.fib786.get_y1(), text =
str.tostring(v_786/100) + str.tostring(fib_d.fib786.get_y1(), " (#,###.####)"),
textcolor = fibo_color, color = chart.bg_color, style = label.style_label_left)

linefill.new(fib_d.fib618, fib_d.fib786, fill_col)


linefill.new(fib_d.fib05, fib_d.fib786, fill_col)

// Adaptive Trend Finder Calculations


confidence(pearsonR) =>
switch
pearsonR < 0.2 => "Extremely Weak"
pearsonR < 0.3 => "Very Weak"
pearsonR < 0.4 => "Weak"
pearsonR < 0.5 => "Mostly Weak"
pearsonR < 0.6 => "Somewhat Weak"
pearsonR < 0.7 => "Moderately Weak"
pearsonR < 0.8 => "Moderate"
pearsonR < 0.9 => "Moderately Strong"
pearsonR < 0.92 => "Mostly Strong"
pearsonR < 0.94 => "Strong"
pearsonR < 0.96 => "Very Strong"
pearsonR < 0.98 => "Exceptionally Strong"
=> "Ultra Strong"

getTablePosition(string pos) =>


switch pos
"Bottom Right" => position.bottom_right
"Bottom Center" => position.bottom_center
"Bottom Left" => position.bottom_left
"Top Right" => position.top_right
"Top Left" => position.top_left
"Top Center" => position.top_center
"Middle Right" => position.middle_right
=> position.middle_left

calcDev(float source, int length) =>


float logSource = math.log(source)
var int period_1 = length - 1
if barstate.islast
float sumX = 0.0
float sumXX = 0.0
float sumYX = 0.0
float sumY = 0.0
for int i = 1 to length by 1
float lSrc = logSource[i - 1]
sumX := sumX + i
sumXX := sumXX + i * i
sumYX := sumYX + i * lSrc
sumY := sumY + lSrc
float slope = nz((length * sumYX - sumX * sumY) / (length * sumXX - sumX *
sumX))
float average = sumY / length
float intercept = average - slope * sumX / length + slope
float sumDev = 0.0
float sumDxx = 0.0
float sumDyy = 0.0
float sumDyx = 0.0
float regres = intercept + slope * period_1 * 0.5
float sumSlp = intercept
for int i = 0 to period_1 by 1
float lSrc = logSource[i]
float dxt = lSrc - average
float dyt = sumSlp - regres
lSrc := lSrc - sumSlp
sumSlp := sumSlp + slope
sumDxx := sumDxx + dxt * dxt
sumDyy := sumDyy + dyt * dyt
sumDyx := sumDyx + dxt * dyt
sumDev := sumDev + lSrc * lSrc
float unStdDev = math.sqrt(sumDev / period_1)
float divisor = sumDxx * sumDyy
float pearsonR = nz(sumDyx / math.sqrt(divisor))
[unStdDev, pearsonR, slope, intercept]
else
[na, na, na, na]

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 string EXTEND_STYLE = switch extendStyle


"Extend Right" => extend.right
"Extend Both" => extend.both
"Extend None" => extend.none
=> extend.left

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)

[stdDev01, pearsonR01, slope01, intercept01] = calcDev(sourceInput, Periods.get(1))


[stdDev02, pearsonR02, slope02, intercept02] = calcDev(sourceInput, Periods.get(2))
[stdDev03, pearsonR03, slope03, intercept03] = calcDev(sourceInput, Periods.get(3))
[stdDev04, pearsonR04, slope04, intercept04] = calcDev(sourceInput, Periods.get(4))
[stdDev05, pearsonR05, slope05, intercept05] = calcDev(sourceInput, Periods.get(5))
[stdDev06, pearsonR06, slope06, intercept06] = calcDev(sourceInput, Periods.get(6))
[stdDev07, pearsonR07, slope07, intercept07] = calcDev(sourceInput, Periods.get(7))
[stdDev08, pearsonR08, slope08, intercept08] = calcDev(sourceInput, Periods.get(8))
[stdDev09, pearsonR09, slope09, intercept09] = calcDev(sourceInput, Periods.get(9))
[stdDev10, pearsonR10, slope10, intercept10] = calcDev(sourceInput,
Periods.get(10))
[stdDev11, pearsonR11, slope11, intercept11] = calcDev(sourceInput,
Periods.get(11))
[stdDev12, pearsonR12, slope12, intercept12] = calcDev(sourceInput,
Periods.get(12))
[stdDev13, pearsonR13, slope13, intercept13] = calcDev(sourceInput,
Periods.get(13))
[stdDev14, pearsonR14, slope14, intercept14] = calcDev(sourceInput,
Periods.get(14))
[stdDev15, pearsonR15, slope15, intercept15] = calcDev(sourceInput,
Periods.get(15))
[stdDev16, pearsonR16, slope16, intercept16] = calcDev(sourceInput,
Periods.get(16))
[stdDev17, pearsonR17, slope17, intercept17] = calcDev(sourceInput,
Periods.get(17))
[stdDev18, pearsonR18, slope18, intercept18] = calcDev(sourceInput,
Periods.get(18))
[stdDev19, pearsonR19, slope19, intercept19] = calcDev(sourceInput,
Periods.get(19))

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

var line upperLine = na


var linefill upperFill = na
var line baseLine = na
var line lowerLine = na
var linefill lowerFill = na

float startPrice = math.exp(detectedIntrcpt + detectedSlope * (detectedPeriod -


1))
float endPrice = math.exp(detectedIntrcpt)
int startAtBar = bar_index - detectedPeriod + 1
var color ChannelColor = color.new(channel_color, channelTransparency)

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)

float upperStartPrice = startPrice * math.exp(devMultiplier * detectedStdDev)


float upperEndPrice = endPrice * math.exp(devMultiplier * detectedStdDev)
if na(upperLine)
upperLine := line.new(startAtBar, upperStartPrice, bar_index,
upperEndPrice, width = 1, extend = EXTEND_STYLE, color = ChannelColor, style =
lineStyle1 == "Dotted" ? line.style_dotted : lineStyle1 == "Dashed" ?
line.style_dashed : line.style_solid)
else
line.set_xy1(upperLine, startAtBar, upperStartPrice)
line.set_xy2(upperLine, bar_index, upperEndPrice)

float lowerStartPrice = startPrice / math.exp(devMultiplier * detectedStdDev)


float lowerEndPrice = endPrice / math.exp(devMultiplier * detectedStdDev)
if na(lowerLine)
lowerLine := line.new(startAtBar, lowerStartPrice, bar_index,
lowerEndPrice, width = 1, extend = EXTEND_STYLE, color = ChannelColor, style =
lineStyle1 == "Dotted" ? line.style_dotted : lineStyle1 == "Dashed" ?
line.style_dashed : line.style_solid)
else
line.set_xy1(lowerLine, startAtBar, lowerStartPrice)
line.set_xy2(lowerLine, bar_index, lowerEndPrice)

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))

var table t = table.new(periodMode ? position.bottom_center :


getTablePosition(tablePositionInput), 2, 3)
string text1 = periodMode ? "Auto-Selected Period (Long Term): " +
str.tostring(detectedPeriod) : "Auto-Selected Period: " +
str.tostring(detectedPeriod)
var colorInputLight = color.new(channel_color, 0)

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

if showTrendAnnualizedReturn and is_valid_timeframe()


table.cell(t, 0, 2, "Trend Annualized Return: " + (not na(cagr) ?
str.tostring(cagr * 100, "#.#") + "%" : "N/A"), text_color = channel_color,
text_size = textSizeInput == "Large" ? size.large : textSizeInput == "Small" ?
size.small : size.normal)

//
-----------------------------------------------------------------------------------

// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
---------------------------------}

//
-----------------------------------------------------------------------------------
---------------------------------{

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)

You might also like