//@version=6 // Time Cycles — cyclus-derden als blokken, met het eerste-cyclus model. // // Standaard: cyclus 13m20s, ouder 40m (= 3 x 13m20s). // De EERSTE cyclus van elke ouder krijgt een dikke rand: die zet de richting. // Sluit een bevestigingscandle buiten die eerste range, dan wordt de // TEGENOVERLIGGENDE kant beschermd tot het einde van de ouder-cyclus. // // cyclus 13m20s -> bevestiging 3m close // cyclus 40m -> bevestiging 5m close // cyclus 2h -> bevestiging 15m close // // Anker 18:00 New York. Body close, geen wick. indicator("Time Cycles", "Cycles", overlay = true, max_lines_count = 500, max_labels_count = 500, max_boxes_count = 500) gC = "Cyclus" cycTxt = input.string("13m20s", "Cyclus (de blokken)", group = gC, tooltip = "13m20s · 40m · 27m · 90m · 2h · 13:20\nKaal getal = minuten.\nDe ouder is automatisch 3 x deze lengte.") d1 = input.bool(true, "1e derde", group = gC, inline = "d") d2 = input.bool(true, "2e derde", group = gC, inline = "d") d3 = input.bool(true, "3e derde", group = gC, inline = "d") gM = "Eerste-cyclus model" modelAan = input.bool(true, "Bevestiging en beschermd niveau tonen", group = gM) confTxt = input.string("auto", "Bevestigingscandle", group = gM, options = ["auto", "1", "3", "5", "15", "30"], tooltip = "auto: 13m20s -> 3m · 40m -> 5m · 2h -> 15m") toonRef = input.bool(true, "Range van de eerste cyclus doortrekken", group = gM) gA = "Anker" anchorTxt = input.string("18:00", "Reset elke dag om", group = gA) tzTxt = input.string("America/New_York", "Tijdzone", group = gA, options = ["America/New_York", "Europe/Amsterdam", "Asia/Dubai", "UTC"]) gS = "Stijl" k1 = input.color(#1c4e80, "1e derde", group = gS, inline = "k") k2 = input.color(#7a8b3f, "2e derde", group = gS, inline = "k") k3 = input.color(#9c5a2d, "3e derde", group = gS, inline = "k") kBull = input.color(#1f7a4d, "Beschermd — bullish", group = gS) kBear = input.color(#a33a3a, "Beschermd — bearish", group = gS) vul = input.int(90, "Blok doorzichtigheid", minval = 70, maxval = 99, group = gS) toonTijd = input.bool(true, "Begin- en eindtijd bij elk blok", group = gS) kOuder = input.color(#95a3ae, "Ouder-lijn", group = gS) keepN = input.int(40, "Blokken bewaren", minval = 5, maxval = 200, group = gS) // ───────────────────────────────────────────────────────────── parser parseDur(string raw) => string t = str.replace_all(str.lower(raw), " ", "") float total = 0.0 bool unit = str.contains(t, "h") or str.contains(t, "m") or str.contains(t, "s") if str.contains(t, ":") and not unit a = str.split(t, ":") float mm = array.size(a) > 0 ? nz(str.tonumber(array.get(a, 0))) : 0.0 float ss = array.size(a) > 1 ? nz(str.tonumber(array.get(a, 1))) : 0.0 total := mm * 60.0 + ss else string buf = "" string last = "" if str.length(t) > 0 for i = 0 to str.length(t) - 1 string ch = str.substring(t, i, i + 1) if ch == "h" or ch == "m" or ch == "s" total += nz(str.tonumber(buf)) * (ch == "h" ? 3600.0 : ch == "m" ? 60.0 : 1.0) buf := "" last := ch else buf := buf + ch if str.length(buf) > 0 total += nz(str.tonumber(buf)) * (last == "h" ? 60.0 : last == "" ? 60.0 : 1.0) total fmt(float s) => int t = int(math.round(s)) int h = int(math.floor(t / 3600.0)) int m = int(math.floor((t % 3600) / 60.0)) int x = t % 60 string o = "" if h > 0 o := o + str.tostring(h) + "h" if m > 0 o := o + str.tostring(m) + "m" if x > 0 o := o + str.tostring(x) + "s" o == "" ? "0" : o // ─────────────────────────────────────────────── seconden sinds anker ap = str.split(anchorTxt, ":") int aH = array.size(ap) > 0 ? int(math.round(nz(str.tonumber(array.get(ap, 0))))) : 18 int aM = array.size(ap) > 1 ? int(math.round(nz(str.tonumber(array.get(ap, 1))))) : 0 int rel = hour(time, tzTxt) * 3600 + minute(time, tzTxt) * 60 + second(time, tzTxt) - (aH * 3600 + aM * 60) rel := rel < 0 ? rel + 86400 : rel float C = parseDur(cycTxt) float P = C * 3.0 int tfSec = timeframe.in_seconds() bool actief = C >= tfSec // bevestigingscandle: auto uit de cycluslengte string confAuto = C <= 1200 ? "3" : C <= 3600 ? "5" : "15" string confTF = confTxt == "auto" ? confAuto : confTxt int confSec = timeframe.in_seconds(confTF) bool confKan = confSec >= tfSec // een bevestigingscandle is zojuist AFGESLOTEN op de vorige bar bool confDicht = ta.change(time(confTF)) != 0 // ──────────────────────────────────────────────────────────── blokken var array bxs = array.new() var array