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)
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.