OPEN-SOURCE SCRIPT

Cassures Tokyo pendant New York

172
//version=5
indicator("Cassures Tokyo pendant New York", overlay=true)

// Paramètres de sessions
// Début et fin de Tokyo (00h00 - 08h00 GMT)
tokyo_start = timestamp("GMT+0", year(timenow), month(timenow), dayofmonth(timenow), 0, 0)
tokyo_end = timestamp("GMT+0", year(timenow), month(timenow), dayofmonth(timenow), 8, 0)

// Début et fin de New York (13h30 - 22h00 GMT)
ny_start = timestamp("GMT+0", year(timenow), month(timenow), dayofmonth(timenow), 13, 30)
ny_end = timestamp("GMT+0", year(timenow), month(timenow), dayofmonth(timenow), 22, 0)

// Initialisation des variables persistantes
var float tokyo_high = na
var float tokyo_low = na
var bool ny_started = false
var bool high_broken = false
var bool low_broken = false

// Reset des valeurs à chaque nouvelle journée
if (time >= tokyo_start and time < tokyo_end)
tokyo_high := na
tokyo_low := na
high_broken := false
low_broken := false
ny_started := false

// Détection du high/low Tokyo
if (time >= tokyo_start and time < tokyo_end)
tokyo_high := na(tokyo_high) ? high : math.max(tokyo_high, high)
tokyo_low := na(tokyo_low) ? low : math.min(tokyo_low, low)

// Détection des cassures pendant New York
if (time >= ny_start and time < ny_end)
ny_started := true
if not na(tokyo_high) and high > tokyo_high
high_broken := true
if not na(tokyo_low) and low < tokyo_low
low_broken := true

// Affichage des niveaux Tokyo
plot(tokyo_high, "Tokyo High", color=color.green, linewidth=1, style=plot.style_linebr)
plot(tokyo_low, "Tokyo Low", color=color.red, linewidth=1, style=plot.style_linebr)

// Surlignage visuel en session NY selon cassure
bgcolor(ny_started and high_broken and low_broken ? color.orange : ny_started and high_broken ? color.new(color.green, 80) : ny_started and low_broken ? color.new(color.red, 80) : na)

// Affichage texte sur le graphique
label_id = label.new(x=bar_index, y=high, text="", style=label.style_label_down, textcolor=color.white, size=size.tiny, color=color.gray)

if (ny_started)
label_text = high_broken and low_broken ? "Cassure HIGH & LOW Tokyo" :
high_broken ? "Cassure HIGH Tokyo" :
low_broken ? "Cassure LOW Tokyo" :
"Aucune cassure"
label.set_text(label_id, label_text)
label.set_xy(label_id, bar_index, high + syminfo.mintick * 10)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.