OPEN-SOURCE SCRIPT
ATH Projection (2013, 2017, 2021 -> 2025)

//version=6
indicator(title="ATH Projection (2013, 2017, 2021 -> 2025)", overlay=true, max_labels_count=20, max_lines_count=20)
// ----------- Inputs (ATH manuels) -----------
t1 = input.time(defval=timestamp("2013-12-01T00:00:00"), title="Date ATH #1 (2013)")
p1 = input.float(defval=1100.0, title="Prix ATH #1 (2013)")
t2 = input.time(defval=timestamp("2017-12-01T00:00:00"), title="Date ATH #2 (2017)")
p2 = input.float(defval=20000.0, title="Prix ATH #2 (2017)")
t3 = input.time(defval=timestamp("2021-11-01T00:00:00"), title="Date ATH #3 (2021)")
p3 = input.float(defval=69000.0, title="Prix ATH #3 (2021)")
// Projection future (ex: fin 2025)
t_proj = input.time(defval=timestamp("2025-12-01T00:00:00"), title="Date cible (fin 2025)")
// ----------- Utilitaire -----------
f_days(t) => ((t - t1) / 86400000.0) + 1.0 // nb jours depuis t1 (+1 pour éviter log(0))
// ----------- Coordonnées X (jours) -----------
x1 = f_days(t1)
x2 = f_days(t2)
x3 = f_days(t3)
xP = f_days(t_proj)
// ----------- Régression power-law (3 points) -----------
X1 = math.log(x1), Y1 = math.log(p1)
X2 = math.log(x2), Y2 = math.log(p2)
X3 = math.log(x3), Y3 = math.log(p3)
n = 3.0
sumX = X1 + X2 + X3
sumY = Y1 + Y2 + Y3
sumX2 = X1*X1 + X2*X2 + X3*X3
sumXY = X1*Y1 + X2*Y2 + X3*Y3
denom = n*sumX2 - sumX*sumX
var float a = na
var float b = na
b := denom != 0 ? (n*sumXY - sumX*sumY) / denom : na
a := na(b) ? na : math.exp((sumY - b*sumX) / n)
// ----------- Courbe au fil des barres -----------
x_now = f_days(time)
curve = (not na(a) and not na(b) and x_now > 0) ? a * math.pow(x_now, b) : na
plot(series=curve, title="Courbe prévision (power-law)", color=color.fuchsia, linewidth=2)
// ----------- Projection fin 2025 -----------
proj2025 = (not na(a) and not na(b) and xP > 0) ? a * math.pow(xP, b) : na
bi_proj = ta.valuewhen(time >= t_proj, bar_index, 0)
x_for_label = na(bi_proj) ? bar_index : bi_proj
// Label affichant la projection
var label lbl = na
if barstate.islast and not na(proj2025)
txt = "Projection 2025 ≈ " + str.tostring(proj2025, format.price)
if na(lbl)
lbl := label.new(x=x_for_label, y=proj2025, text=txt, xloc=xloc.bar_index, style=label.style_label_up, color=color.green, textcolor=color.white, size=size.normal)
else
label.set_x(id=lbl, x=x_for_label)
label.set_y(id=lbl, y=proj2025)
label.set_text(id=lbl, text=txt)
indicator(title="ATH Projection (2013, 2017, 2021 -> 2025)", overlay=true, max_labels_count=20, max_lines_count=20)
// ----------- Inputs (ATH manuels) -----------
t1 = input.time(defval=timestamp("2013-12-01T00:00:00"), title="Date ATH #1 (2013)")
p1 = input.float(defval=1100.0, title="Prix ATH #1 (2013)")
t2 = input.time(defval=timestamp("2017-12-01T00:00:00"), title="Date ATH #2 (2017)")
p2 = input.float(defval=20000.0, title="Prix ATH #2 (2017)")
t3 = input.time(defval=timestamp("2021-11-01T00:00:00"), title="Date ATH #3 (2021)")
p3 = input.float(defval=69000.0, title="Prix ATH #3 (2021)")
// Projection future (ex: fin 2025)
t_proj = input.time(defval=timestamp("2025-12-01T00:00:00"), title="Date cible (fin 2025)")
// ----------- Utilitaire -----------
f_days(t) => ((t - t1) / 86400000.0) + 1.0 // nb jours depuis t1 (+1 pour éviter log(0))
// ----------- Coordonnées X (jours) -----------
x1 = f_days(t1)
x2 = f_days(t2)
x3 = f_days(t3)
xP = f_days(t_proj)
// ----------- Régression power-law (3 points) -----------
X1 = math.log(x1), Y1 = math.log(p1)
X2 = math.log(x2), Y2 = math.log(p2)
X3 = math.log(x3), Y3 = math.log(p3)
n = 3.0
sumX = X1 + X2 + X3
sumY = Y1 + Y2 + Y3
sumX2 = X1*X1 + X2*X2 + X3*X3
sumXY = X1*Y1 + X2*Y2 + X3*Y3
denom = n*sumX2 - sumX*sumX
var float a = na
var float b = na
b := denom != 0 ? (n*sumXY - sumX*sumY) / denom : na
a := na(b) ? na : math.exp((sumY - b*sumX) / n)
// ----------- Courbe au fil des barres -----------
x_now = f_days(time)
curve = (not na(a) and not na(b) and x_now > 0) ? a * math.pow(x_now, b) : na
plot(series=curve, title="Courbe prévision (power-law)", color=color.fuchsia, linewidth=2)
// ----------- Projection fin 2025 -----------
proj2025 = (not na(a) and not na(b) and xP > 0) ? a * math.pow(xP, b) : na
bi_proj = ta.valuewhen(time >= t_proj, bar_index, 0)
x_for_label = na(bi_proj) ? bar_index : bi_proj
// Label affichant la projection
var label lbl = na
if barstate.islast and not na(proj2025)
txt = "Projection 2025 ≈ " + str.tostring(proj2025, format.price)
if na(lbl)
lbl := label.new(x=x_for_label, y=proj2025, text=txt, xloc=xloc.bar_index, style=label.style_label_up, color=color.green, textcolor=color.white, size=size.normal)
else
label.set_x(id=lbl, x=x_for_label)
label.set_y(id=lbl, y=proj2025)
label.set_text(id=lbl, text=txt)
Script open-source
Dans l'esprit de TradingView, le créateur de ce script l'a rendu open-source, afin que les traders puissent examiner et vérifier sa fonctionnalité. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit de TradingView, le créateur de ce script l'a rendu open-source, afin que les traders puissent examiner et vérifier sa fonctionnalité. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.