Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=6
- indicator("7H Profile · Fractal Model Pro", shorttitle = "7H Fractal Pro", overlay = true, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500, max_bars_back = 1000)
- const string G_GEN = "GENERAL"
- const string G_TXT = "TEXT & MARKERS"
- const string G_BIAS = "DAILY BIAS"
- const string G_REL = "RELEVANT SWING"
- const string G_FAIL = "FAILURE & SEPARATION"
- const string G_CONT = "CONTINUATION & SWEEP CANDLE"
- const string G_PROF = "7H PROFILE"
- const string G_PDRW = "PROFILE DRAWINGS"
- const string G_OPEN = "OPEN LINE"
- const string G_ENT = "ENTRY"
- const string G_CISD = "CISD & LEG"
- const string G_SIG = "ENTRY SIGNALS"
- const string G_RISK = "RISK"
- const string G_RBOX = "RISK BOXES"
- const string G_PNL = "7H CANDLES PANEL"
- const string G_DSH = "DASHBOARD"
- i_tz = input.string("America/New_York", "Timezone", group = G_GEN)
- i_dayStart = input.int(18, "Trading Day Start (hour)", minval = 0, maxval = 23, group = G_GEN)
- i_profHrs = input.int(7, "Profile Candle (hours)", minval = 1, maxval = 12, group = G_GEN)
- i_hist = input.int(3, "History (trading days)", minval = 1, maxval = 15, group = G_GEN)
- i_clean = input.bool(true, "Clean Mode", group = G_GEN)
- i_maxLine = input.int(96, "Max Live Line Length (bars)", minval = 10, maxval = 900, group = G_GEN)
- c_txt = input.color(#787b86, "Text", inline = "tx1", group = G_TXT)
- i_txtSize = input.string("Tiny", "Size", options = ["Tiny", "Small", "Normal"], inline = "tx1", group = G_TXT)
- i_dotSize = input.string("Tiny", "Dot Size", options = ["Micro", "Tiny", "Small", "Normal"], group = G_TXT)
- c_grey = input.color(#b0b4ba, "Retired Levels", group = G_TXT)
- i_swingLen = input.int(1, "Swing Strength (daily candles)", minval = 1, maxval = 5, group = G_BIAS)
- i_atrLen = input.int(14, "Daily ATR Length", minval = 1, maxval = 50, group = G_BIAS)
- i_biasConf = input.string("Reaction close", "Bias Trigger", options = ["Reaction close", "Close beyond sweep candle"], group = G_BIAS)
- i_wickFlt = input.bool(true, "Skip After Opposing Wick", inline = "wk", group = G_BIAS)
- i_wickMax = input.float(40, "Max %", minval = 1, maxval = 100, inline = "wk", group = G_BIAS)
- i_showBias = input.bool(true, "Relevant Swing", inline = "rs1", group = G_REL)
- c_rel = input.color(#5f6368, "", inline = "rs1", group = G_REL)
- i_relSt = input.string("Solid", "Style", options = ["Solid", "Dotted", "Dashed"], inline = "rs2", group = G_REL)
- i_relW = input.int(1, "Width", minval = 1, maxval = 4, inline = "rs2", group = G_REL)
- i_showRelDot = input.bool(true, "Dot", inline = "rs3", group = G_REL)
- c_relDot = input.color(#3d7bff, "", inline = "rs3", group = G_REL)
- i_showRelLbl = input.bool(true, "Caption", group = G_REL)
- i_failFlt = input.bool(true, "Separation Filter", group = G_FAIL)
- i_sepMult = input.float(0.5, "Min Separation (× ATR)", minval = 0, step = 0.1, group = G_FAIL)
- i_failPct = input.float(50, "Max Retracement %", minval = 5, maxval = 100, group = G_FAIL)
- i_showFail = input.bool(true, "Failure Swings", inline = "fs1", group = G_FAIL)
- c_fail = input.color(#b0b4ba, "", inline = "fs1", group = G_FAIL)
- i_showSep = input.bool(true, "Separation Bar", inline = "fs2", group = G_FAIL)
- c_sep = input.color(color.new(#3d7bff, 55), "", inline = "fs2", group = G_FAIL)
- i_showCont = input.bool(true, "Continuation Marks", inline = "ct1", group = G_CONT)
- c_contLn = input.color(color.new(#5f6368, 20), "", inline = "ct1", group = G_CONT)
- i_contInv = input.bool(true, "50% Invalidation", inline = "ct2", group = G_CONT)
- c_invBox = input.color(color.new(#9aa0a6, 88), "", inline = "ct2", group = G_CONT)
- i_showConf = input.bool(true, "Sweep Candle Level", inline = "ct3", group = G_CONT)
- c_conf = input.color(#5f6368, "", inline = "ct3", group = G_CONT)
- i_align = input.bool(true, "Align With Daily Bias", group = G_PROF)
- i_asia = input.bool(true, "Asia", inline = "ps", group = G_PROF)
- i_london = input.bool(true, "London", inline = "ps", group = G_PROF)
- i_ny = input.bool(true, "New York", inline = "ps", group = G_PROF)
- i_invMode = input.string("Extreme → expansion close", "Invalidation Level", options = ["Extreme → expansion close", "Expansion candle 50%"], group = G_PROF)
- i_invTrig = input.string("Wick", "Invalidation Trigger", options = ["Wick", "Close"], group = G_PROF)
- i_extViol = input.bool(true, "Invalidate On Extreme Break", group = G_PROF)
- i_showProf = input.bool(true, "Show Profile Drawings", group = G_PDRW)
- c_profLn = input.color(#5f6368, "Swept Level", inline = "pd1", group = G_PDRW)
- i_profW = input.int(1, "Width", minval = 1, maxval = 4, inline = "pd1", group = G_PDRW)
- c_profDot = input.color(#3d7bff, "Extreme Dot", group = G_PDRW)
- i_caption = input.bool(true, "Caption", group = G_PDRW)
- c_zone = input.color(color.new(#9aa0a6, 88), "Zone Fill", group = G_PDRW)
- c_inv = input.color(#5f6368, "50% Line", group = G_PDRW)
- c_zoneExt = input.color(#5f6368, "Extreme Line", group = G_PDRW)
- i_showOpen = input.bool(true, "Open Line", inline = "ol1", group = G_OPEN)
- c_open = input.color(#b0b4ba, "", inline = "ol1", group = G_OPEN)
- i_openHr = input.int(8, "Time", minval = 0, maxval = 23, inline = "ol2", group = G_OPEN)
- i_openMin = input.int(0, ":", minval = 0, maxval = 59, inline = "ol2", group = G_OPEN)
- i_openSt = input.string("Dotted", "Style", options = ["Solid", "Dotted", "Dashed"], inline = "ol3", group = G_OPEN)
- i_openW = input.int(1, "Width", minval = 1, maxval = 4, inline = "ol3", group = G_OPEN)
- i_openLen = input.int(24, "Max Length (bars)", minval = 3, maxval = 300, group = G_OPEN)
- i_openLbl = input.bool(true, "Label", group = G_OPEN)
- i_showEnt = input.bool(true, "Enable Entries", group = G_ENT)
- i_method = input.string("Auto", "Entry Method", options = ["Auto", "A: 7H + 15m", "B: 1H + 5m", "B: 30m + 3m"], group = G_ENT)
- i_pivLen = input.int(3, "Swing Strength (method A)", minval = 1, maxval = 10, group = G_ENT)
- i_cisdMax = input.int(20, "Max Bars Sweep → CISD", minval = 2, maxval = 200, group = G_ENT)
- i_needProf = input.bool(true, "Require Aligned Profile", group = G_ENT)
- i_endH = input.int(12, "Entry Window Ends (hour)", minval = 1, maxval = 23, group = G_ENT)
- i_maxEnt = input.int(1, "Entries Per Day", minval = 1, maxval = 5, group = G_ENT)
- i_cool = input.int(4, "Min Bars Between Entries", minval = 0, maxval = 100, group = G_ENT)
- i_keepSet = input.int(3, "Setups Kept", minval = 1, maxval = 20, group = G_ENT)
- i_ctxLines = input.bool(true, "CISD Line", inline = "cl1", group = G_CISD)
- c_cisd = input.color(#3d7bff, "", inline = "cl1", group = G_CISD)
- i_cisdW = input.int(2, "Width", minval = 1, maxval = 4, inline = "cl1", group = G_CISD)
- i_keepCisd = input.int(6, "CISD Lines Kept", minval = 1, maxval = 50, group = G_CISD)
- c_ext = input.color(#5f6368, "Sweep Extreme Line", group = G_CISD)
- i_showLeg = input.bool(true, "Leg Line", inline = "cl2", group = G_CISD)
- c_leg = input.color(#e5484d, "", inline = "cl2", group = G_CISD)
- i_showMid = input.bool(true, "CISD 50% Line", inline = "cl3", group = G_CISD)
- c_mid = input.color(#5f6368, "", inline = "cl3", group = G_CISD)
- i_lineW = input.int(1, "Leg / Extreme / 50% Width", minval = 1, maxval = 4, group = G_CISD)
- i_showArr = input.bool(true, "Arrow", inline = "sg1", group = G_SIG)
- c_entBull = input.color(#3d7bff, "Long", inline = "sg1", group = G_SIG)
- c_entBear = input.color(#e5484d, "Short", inline = "sg1", group = G_SIG)
- i_paintEnt = input.bool(true, "Paint Entry Candle", group = G_SIG)
- i_slMode = input.string("Sweep extreme", "Stop", options = ["Sweep extreme", "Profile extreme"], group = G_RISK)
- i_slBuf = input.int(0, "Stop Buffer (ticks)", minval = 0, group = G_RISK)
- i_tpMode = input.string("Fixed R:R", "Target", options = ["Fixed R:R", "Daily relevant swing"], group = G_RISK)
- i_rr = input.float(2.0, "R:R", minval = 0.5, maxval = 20, step = 0.25, group = G_RISK)
- i_timeExit = input.bool(true, "Time Exit", inline = "tx", group = G_RISK)
- i_exitHr = input.int(15, "Hour", minval = 0, maxval = 23, inline = "tx", group = G_RISK)
- c_tp = input.color(color.new(#3d7bff, 85), "Target", inline = "rb1", group = G_RBOX)
- c_sl = input.color(color.new(#9aa0a6, 85), "Stop", inline = "rb1", group = G_RBOX)
- i_boxLen = input.int(20, "Box Length (bars)", minval = 3, maxval = 300, group = G_RBOX)
- i_showPath = input.bool(true, "Price Path", inline = "rb2", group = G_RBOX)
- c_path = input.color(#8a8f98, "", inline = "rb2", group = G_RBOX)
- i_showPnl = input.bool(true, "Show Panel", group = G_PNL)
- i_pnlCount = input.int(4, "Candles", minval = 2, maxval = 8, group = G_PNL)
- i_pnlOff = input.int(6, "Offset (bars)", minval = 1, maxval = 100, group = G_PNL)
- i_pnlW = input.int(6, "Width", minval = 2, maxval = 20, inline = "pn1", group = G_PNL)
- i_pnlGap = input.int(3, "Gap", minval = 1, maxval = 20, inline = "pn1", group = G_PNL)
- i_pnlFit = input.int(60, "Fit Lookback (bars)", minval = 10, maxval = 300, group = G_PNL)
- i_pnlPct = input.int(45, "Height %", minval = 15, maxval = 85, group = G_PNL)
- i_pnlCap = input.bool(true, "Caption", group = G_PNL)
- i_pnlTrue = input.bool(true, "True Price Scale", group = G_PNL)
- c_bullC = input.color(#ffffff, "Bull", inline = "pn2", group = G_PNL)
- c_bearC = input.color(#3b3b3b, "Bear", inline = "pn2", group = G_PNL)
- c_wick = input.color(#787b86, "Outline", group = G_PNL)
- c_pnlHl = input.color(#e5484d, "Profile Frame", group = G_PNL)
- i_showDash = input.bool(true, "Show Dashboard", group = G_DSH)
- i_dashPos = input.string("Top Right", "Position", options = ["Top Left", "Top Center", "Top Right", "Middle Left", "Middle Center", "Middle Right", "Bottom Left", "Bottom Center", "Bottom Right"], group = G_DSH)
- i_dashSize = input.string("Small", "Text Size", options = ["Tiny", "Small", "Normal"], group = G_DSH)
- i_theme = input.string("Light", "Theme", options = ["Light", "Dark", "Custom"], group = G_DSH)
- c_dTx = input.color(#2a2a2a, "Custom Text", group = G_DSH)
- C_NONE = color.new(#ffffff, 100)
- if not timeframe.isintraday or timeframe.in_seconds() > 3600
- runtime.error("7H Fractal Pro works on intraday charts of 1 hour or lower (15m / 5m / 3m recommended).")
- int barMs = timeframe.in_seconds() * 1000
- bool vFail = i_showFail and not i_clean
- bool vSep = i_showSep and not i_clean
- bool vCtx = i_ctxLines and not i_clean
- bool vOpLbl = i_openLbl and not i_clean
- type Candle
- float o
- float h
- float l
- float c
- int tO
- int tE
- int tH
- int tL
- int bO
- int blk = -1
- type Swing
- float p
- int t
- int tBrk = na
- float leg
- line ln
- line cf
- label lb
- label dt
- type Zone
- box b
- line m
- line e
- int tC = na
- type Setup
- int dir
- float entry
- float sl
- float tp
- int bE
- float mfe
- float mae
- bool live = true
- box bxTP
- box bxSL
- box pgTP
- box pgSL
- line lnPath
- line lnCisd
- line lnExt
- line lnLeg
- line lnMid
- label lbArr
- type Group
- int t0
- int b0
- array<line> lns
- array<label> lbs
- array<box> bxs
- var array<Candle> dH = array.new<Candle>()
- var array<Candle> pH = array.new<Candle>()
- var array<Group> days = array.new<Group>()
- var array<line> cisdLines = array.new<line>()
- var array<Setup> setups = array.new<Setup>()
- var Swing sL = Swing.new()
- var Swing sH = Swing.new()
- var int rEdge = 0
- float atrV = ta.atr(50)
- float dotOff = nz(atrV, high - low) * 0.14
- int trailT = time[math.min(bar_index, i_maxLine)]
- float fitHi = nz(ta.highest(high, i_pnlFit), high)
- float fitLo = nz(ta.lowest(low, i_pnlFit), low)
- fSize(string s) =>
- s == "Tiny" ? size.tiny : s == "Small" ? size.small : size.normal
- fLs(string s) =>
- s == "Dotted" ? line.style_dotted : s == "Dashed" ? line.style_dashed : line.style_solid
- fPos(string s) =>
- switch s
- "Top Left" => position.top_left
- "Top Center" => position.top_center
- "Top Right" => position.top_right
- "Middle Left" => position.middle_left
- "Middle Center" => position.middle_center
- "Middle Right" => position.middle_right
- "Bottom Left" => position.bottom_left
- "Bottom Center" => position.bottom_center
- => position.bottom_right
- fDarker(color c) =>
- color.new(c, math.max(color.t(c) - 25, 0))
- fHour(int b) =>
- int h = (i_dayStart + b * i_profHrs) % 24
- str.format("{0,number,00}:00", h)
- fProfName(int t) =>
- t == 1 ? "asia reversal" : t == 2 ? "london reversal" : t == 3 ? "ny reversal" : "none"
- fNew(int b) =>
- Candle.new(o = open, h = high, l = low, c = close, tO = time, tE = time, tH = time, tL = time, bO = bar_index, blk = b)
- method grow(Candle this) =>
- if high > this.h
- this.h := high
- this.tH := time
- if low < this.l
- this.l := low
- this.tL := time
- this.c := close
- this.tE := time
- this
- method half(Candle this) =>
- (this.h + this.l) / 2
- fCapL(array<line> a, int n) =>
- while a.size() > n
- a.shift().delete()
- a.size()
- fDot(int x, float y, color col, bool isTime = true) =>
- string g = i_dotSize == "Micro" ? "•" : "●"
- string sz = i_dotSize == "Micro" or i_dotSize == "Tiny" ? size.tiny : i_dotSize == "Small" ? size.small : size.normal
- label.new(x, y, g, xloc = isTime ? xloc.bar_time : xloc.bar_index, style = label.style_none, color = C_NONE, textcolor = col, size = sz)
- fGL(line l) =>
- if not na(l) and days.size() > 0
- Group g = days.last()
- g.lns.push(l)
- l
- fGLb(label lb) =>
- if not na(lb) and days.size() > 0
- Group g = days.last()
- g.lbs.push(lb)
- lb
- fGB(box b) =>
- if not na(b) and days.size() > 0
- Group g = days.last()
- g.bxs.push(b)
- b
- fDelGroup(Group g) =>
- while g.lns.size() > 0
- g.lns.pop().delete()
- while g.lbs.size() > 0
- g.lbs.pop().delete()
- while g.bxs.size() > 0
- g.bxs.pop().delete()
- fTrail(line ln, int tOrigin) =>
- if not na(ln)
- ln.set_x1(math.max(tOrigin, trailT))
- ln.set_x2(time)
- fLive(Swing sw, bool isLow) =>
- if not na(sw.p) and na(sw.tBrk)
- if isLow ? low < sw.p : high > sw.p
- sw.tBrk := time
- if not na(sw.ln)
- int xL = math.max(sw.t, trailT)
- sw.ln.set_x1(xL)
- sw.ln.set_x2(time)
- if not na(sw.lb)
- sw.lb.set_x(xL)
- if not na(sw.cf)
- sw.cf.set_x1(math.max(sw.cf.get_x1(), trailT))
- sw.cf.set_x2(time)
- fDAtr(array<Candle> a, int n) =>
- int sz = a.size()
- int m = math.min(n, sz - 1)
- float s = 0.0
- float res = na
- if m >= 1
- for i = 0 to m - 1
- Candle c = a.get(sz - 1 - i)
- Candle p = a.get(sz - 2 - i)
- s += math.max(c.h - c.l, math.max(math.abs(c.h - p.c), math.abs(c.l - p.c)))
- res := s / m
- res
- fLegX(bool isLow, int a, int b, int tMin) =>
- float r = na
- for j = a to b
- Candle cj = dH.get(j)
- if cj.tE >= tMin
- r := na(r) ? (isLow ? cj.h : cj.l) : (isLow ? math.max(r, cj.h) : math.min(r, cj.l))
- r
- fRetire(Swing sw, bool greyLine, bool keepLabel, int tEnd = na) =>
- int x2 = math.max(sw.t, nz(tEnd, time))
- int x1 = math.max(sw.t, x2 - i_maxLine * barMs)
- if not na(sw.ln)
- sw.ln.set_x1(x1)
- sw.ln.set_x2(x2)
- if greyLine
- sw.ln.set_color(c_grey)
- fGL(sw.ln)
- if not na(sw.dt)
- if i_clean or sw.t < x1
- sw.dt.delete()
- else
- sw.dt.set_textcolor(c_grey)
- fGLb(sw.dt)
- if not na(sw.lb)
- if keepLabel
- sw.lb.set_x(x1)
- fGLb(sw.lb)
- else
- sw.lb.delete()
- sw.ln := na
- sw.dt := na
- sw.lb := na
- sw.tBrk := na
- fSetRel(Swing sw, bool isLow, float p, int t, bool withLabel) =>
- sw.p := p
- sw.t := t
- sw.tBrk := na
- if i_showBias
- int x1 = math.max(t, trailT)
- sw.ln := line.new(x1, p, time, p, xloc = xloc.bar_time, color = c_rel, style = fLs(i_relSt), width = i_relW)
- if i_showRelDot
- sw.dt := fDot(t, isLow ? p - dotOff : p + dotOff, c_relDot)
- if withLabel and i_showRelLbl
- sw.lb := label.new(x1, p, "relevant swing", xloc = xloc.bar_time, style = isLow ? label.style_label_upper_left : label.style_label_lower_left, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize))
- sw.p
- fPivot(Swing sw, bool isLow, Candle pc, int k, float atrU) =>
- float p = isLow ? pc.l : pc.h
- int t = isLow ? pc.tL : pc.tH
- int n = dH.size()
- if na(sw.p) or (isLow ? p < sw.p : p > sw.p)
- fRetire(sw, true, false, nz(sw.tBrk, t))
- fSetRel(sw, isLow, p, t, true)
- sw.leg := fLegX(isLow, k, n - 1, 0)
- else if p != sw.p
- float leg = fLegX(isLow, 0, k, sw.t)
- float rng = na(leg) ? na : (isLow ? leg - sw.p : sw.p - leg)
- float sep = isLow ? p - sw.p : sw.p - p
- float retr = (na(rng) or rng <= 0) ? 100.0 : (isLow ? (leg - p) : (p - leg)) / rng * 100
- bool ok = not i_failFlt or (sep >= i_sepMult * atrU and retr <= i_failPct)
- if ok
- float oldP = sw.p
- fRetire(sw, true, false, t)
- fSetRel(sw, isLow, p, t, true)
- sw.leg := fLegX(isLow, k, n - 1, 0)
- if i_showBias and vSep
- fGL(line.new(t, isLow ? p - dotOff * 2 : p + dotOff * 2, t, oldP, xloc = xloc.bar_time, color = c_sep, width = 4))
- else if i_showBias and vFail
- fGLb(fDot(t, isLow ? p - dotOff : p + dotOff, c_fail))
- fGL(line.new(math.max(t, time - i_maxLine * barMs), p, time, p, xloc = xloc.bar_time, color = c_fail, style = line.style_dotted, width = 1))
- true
- fDrawProf(bool bull, float swept, int sweptT, float ext, int extT, string cap) =>
- label res = na
- if i_showProf
- fGL(line.new(sweptT, swept, time + barMs * 4, swept, xloc = xloc.bar_time, color = c_profLn, width = i_profW))
- fGLb(fDot(extT, bull ? ext - dotOff : ext + dotOff, c_profDot))
- if i_caption
- res := fGLb(label.new(extT, bull ? ext - dotOff * 2.2 : ext + dotOff * 2.2, cap, xloc = xloc.bar_time, style = bull ? label.style_label_up : label.style_label_down, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize)))
- res
- fZone(int tL, float inv, float edge, float ext) =>
- Zone z = Zone.new()
- if i_showProf
- z.b := fGB(box.new(tL, math.max(inv, edge), time, math.min(inv, edge), xloc = xloc.bar_time, border_color = C_NONE, bgcolor = c_zone))
- z.m := fGL(line.new(tL, inv, time, inv, xloc = xloc.bar_time, color = c_inv, width = i_profW))
- z.e := fGL(line.new(tL, ext, time, ext, xloc = xloc.bar_time, color = c_zoneExt, style = line.style_dotted, width = 1))
- z.tC := time
- z
- fSetup(int d, float cLvl, int cBar, float ext, int extBar, float sl, float tp) =>
- float ent = close
- int x = bar_index + 1
- Setup st = Setup.new(dir = d, entry = ent, sl = sl, tp = tp, bE = x, mfe = ent, mae = ent)
- st.bxSL := box.new(x, math.max(ent, sl), x + i_boxLen, math.min(ent, sl), border_color = C_NONE, bgcolor = c_sl)
- st.bxTP := box.new(x, math.max(ent, tp), x + i_boxLen, math.min(ent, tp), border_color = C_NONE, bgcolor = c_tp)
- st.pgSL := box.new(x, ent, x, ent, border_color = C_NONE, bgcolor = fDarker(c_sl))
- st.pgTP := box.new(x, ent, x, ent, border_color = C_NONE, bgcolor = fDarker(c_tp))
- st.lnCisd := line.new(cBar, cLvl, bar_index + 2, cLvl, color = c_cisd, width = i_cisdW)
- st.lnExt := line.new(extBar, ext, x + 1, ext, color = c_ext, width = i_lineW)
- if i_showLeg and extBar < bar_index
- st.lnLeg := line.new(extBar, ext, bar_index, d == 1 ? low : high, color = c_leg, width = i_lineW)
- if i_showMid
- float m = (high + low) / 2
- st.lnMid := line.new(bar_index, m, bar_index + 3, m, color = c_mid, width = i_lineW)
- if i_showPath
- st.lnPath := line.new(x, ent, x, ent, color = c_path, style = line.style_dashed, width = 1)
- if i_showArr
- st.lbArr := label.new(bar_index, d == 1 ? low : high, d == 1 ? "▲ BUY" : "▼ SELL", style = d == 1 ? label.style_label_up : label.style_label_down, color = C_NONE, textcolor = d == 1 ? c_entBull : c_entBear, size = size.tiny)
- st
- fDelSetup(Setup s) =>
- s.bxTP.delete()
- s.bxSL.delete()
- s.pgTP.delete()
- s.pgSL.delete()
- s.lnPath.delete()
- s.lnCisd.delete()
- s.lnExt.delete()
- s.lnLeg.delete()
- s.lnMid.delete()
- s.lbArr.delete()
- int hNY = hour(time, i_tz)
- int nyMins = hNY * 60 + minute(time, i_tz)
- int blkLen = i_profHrs * 60
- int relMins = (nyMins - i_dayStart * 60 + 1440) % 1440
- int blk = math.floor(relMins / blkLen)
- bool gap = bar_index > 0 and (time - time[1]) >= blkLen * 60000
- bool newBlk = bar_index == 0 or blk != blk[1] or gap
- bool newDay = newBlk and (bar_index == 0 or blk <= blk[1])
- if newDay
- days.push(Group.new(t0 = time, b0 = bar_index, lns = array.new<line>(), lbs = array.new<label>(), bxs = array.new<box>()))
- while days.size() > i_hist
- fDelGroup(days.shift())
- if days.size() > 0
- int minB = days.first().b0
- while setups.size() > 0 and not setups.first().live and setups.first().bE < minB
- fDelSetup(setups.shift())
- int biasEvt = 0
- int profEvt = 0
- bool invEvt = false
- bool biasInv = false
- int entryNow = 0
- int exitEvt = 0
- var Candle dCur = na
- var int bias = 0
- var int todayBias = 0
- var bool skipDay = false
- var float pendBull = na
- var float pendBullInv = na
- var float pendBear = na
- var float pendBearInv = na
- var int revDir = 0
- var float revLvl = na
- var float contLvl = na
- var line contLn = na
- var bool contInvalid = false
- bool dayClosed = false
- if newDay
- if not na(dCur)
- dH.push(dCur)
- if dH.size() > 150
- dH.shift()
- dayClosed := true
- dCur := fNew(-1)
- else if not na(dCur)
- dCur.grow()
- if dayClosed
- Candle dc = dH.last()
- int sz = dH.size()
- float atrU = nz(fDAtr(dH, i_atrLen), dc.h - dc.l)
- sL.cf := na
- sH.cf := na
- if revDir != 0
- if i_showBias and i_showCont
- if revDir == 1 and dc.c > revLvl
- fGLb(label.new(dc.tH, dc.h, "continuation", xloc = xloc.bar_time, style = label.style_label_left, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize)))
- if revDir == -1 and dc.c < revLvl
- fGLb(label.new(dc.tL, dc.l, "continuation", xloc = xloc.bar_time, style = label.style_label_left, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize)))
- revDir := 0
- if not na(pendBull)
- if dc.c > pendBull
- bias := 1
- biasEvt := 1
- pendBull := na
- else if dc.c < pendBullInv
- pendBull := na
- if not na(pendBear)
- if dc.c < pendBear
- bias := -1
- biasEvt := -1
- pendBear := na
- else if dc.c > pendBearInv
- pendBear := na
- if not na(sL.p)
- sL.leg := math.max(nz(sL.leg, dc.h), dc.h)
- if not na(sH.p)
- sH.leg := math.min(nz(sH.leg, dc.l), dc.l)
- if sz >= 2 * i_swingLen + 1
- int k = sz - 1 - i_swingLen
- Candle pc = dH.get(k)
- bool isPH = true
- bool isPL = true
- for i = 1 to i_swingLen
- Candle lc = dH.get(k - i)
- Candle rc = dH.get(k + i)
- if lc.h >= pc.h or rc.h > pc.h
- isPH := false
- if lc.l <= pc.l or rc.l < pc.l
- isPL := false
- if isPL
- fPivot(sL, true, pc, k, atrU)
- if isPH
- fPivot(sH, false, pc, k, atrU)
- bool bullR = not na(sL.p) and dc.l < sL.p and dc.c > sL.p
- bool bearR = not na(sH.p) and dc.h > sH.p and dc.c < sH.p
- if bullR and bearR
- bullR := dc.c >= dc.o
- bearR := not bullR
- if not bullR and not na(sL.p) and dc.c < sL.p
- fRetire(sL, false, false, nz(sL.tBrk, dc.tL))
- sL.p := na
- sL.leg := na
- bias := -1
- biasEvt := -1
- if not bearR and not na(sH.p) and dc.c > sH.p
- fRetire(sH, false, false, nz(sH.tBrk, dc.tH))
- sH.p := na
- sH.leg := na
- bias := 1
- biasEvt := 1
- Candle prv = na
- if sz >= 2
- prv := dH.get(sz - 2)
- if bullR
- fRetire(sL, false, true, nz(sL.tBrk, dc.tL))
- fSetRel(sL, true, dc.l, dc.tL, false)
- sL.leg := dc.h
- if i_showBias and i_showConf
- sL.cf := fGL(line.new(dc.tH, dc.h, time, dc.h, xloc = xloc.bar_time, color = c_conf, width = i_relW))
- if i_biasConf == "Reaction close"
- bias := 1
- biasEvt := 1
- else
- pendBull := dc.h
- pendBullInv := dc.l
- if bearR
- fRetire(sH, false, true, nz(sH.tBrk, dc.tH))
- fSetRel(sH, false, dc.h, dc.tH, false)
- sH.leg := dc.l
- if i_showBias and i_showConf
- sH.cf := fGL(line.new(dc.tL, dc.l, time, dc.l, xloc = xloc.bar_time, color = c_conf, width = i_relW))
- if i_biasConf == "Reaction close"
- bias := -1
- biasEvt := -1
- else
- pendBear := dc.l
- pendBearInv := dc.h
- if not bullR and not bearR and not na(prv)
- if bias == 1 and dc.l < prv.l and dc.c > prv.l
- if i_showBias and i_showCont
- fGL(line.new(prv.tL, prv.l, dc.tL, prv.l, xloc = xloc.bar_time, color = c_contLn, width = i_relW))
- fGLb(label.new(dc.tL, dc.l - dotOff, "reversal", xloc = xloc.bar_time, style = label.style_label_up, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize)))
- revDir := 1
- revLvl := dc.h
- else if bias == -1 and dc.h > prv.h and dc.c < prv.h
- if i_showBias and i_showCont
- fGL(line.new(prv.tH, prv.h, dc.tH, prv.h, xloc = xloc.bar_time, color = c_contLn, width = i_relW))
- fGLb(label.new(dc.tH, dc.h + dotOff, "reversal", xloc = xloc.bar_time, style = label.style_label_down, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize)))
- revDir := -1
- revLvl := dc.l
- fLive(sL, true)
- fLive(sH, false)
- var int contT = na
- if newDay
- todayBias := bias
- skipDay := false
- contInvalid := false
- contLvl := na
- contLn := na
- contT := na
- if dayClosed and bias != 0
- Candle d1 = dH.last()
- float rg = d1.h - d1.l
- if i_wickFlt and rg > 0
- float opw = bias == 1 ? d1.h - math.max(d1.o, d1.c) : math.min(d1.o, d1.c) - d1.l
- if opw / rg * 100 > i_wickMax
- todayBias := 0
- skipDay := true
- if i_contInv and todayBias != 0
- float opp = todayBias == 1 ? sL.p : sH.p
- if not na(opp) and (todayBias == 1 ? opp < d1.c : opp > d1.c)
- contLvl := (d1.c + opp) / 2
- if i_showBias and i_showCont
- contT := time
- contLn := fGL(line.new(time, contLvl, time, contLvl, xloc = xloc.bar_time, color = c_contLn, style = line.style_dotted, width = 1))
- if not na(contLvl) and not contInvalid and todayBias != 0
- if not na(contLn) and not na(contT)
- fTrail(contLn, contT)
- if barstate.isconfirmed and (todayBias == 1 ? close < contLvl : close > contLvl)
- contInvalid := true
- biasInv := true
- if i_showBias and i_showCont
- fGB(box.new(time, math.max(contLvl, close), time + barMs * 8, math.min(contLvl, close), xloc = xloc.bar_time, border_color = C_NONE, bgcolor = c_invBox, text = "invalid", text_size = fSize(i_txtSize), text_color = c_txt, text_halign = text.align_right, text_valign = text.align_center))
- rEdge := math.max(rEdge, bar_index + 8)
- if not na(contLn)
- contLn.set_color(color.new(c_grey, 40))
- todayBias := 0
- var Candle pCur = na
- var int pState = 0
- var int pType = 0
- var int pDir = 0
- var Candle pRev = na
- var float pExt = na
- var float pSwept = na
- var float pInv = na
- var float dayLo = na
- var float dayHi = na
- var int dayLoT = na
- var int dayHiT = na
- var int entCount = 0
- var Zone zn = na
- var bool zLive = false
- var label prCap = na
- bool profClosed = false
- if not na(pCur) and newBlk
- pH.push(pCur)
- if pH.size() > 30
- pH.shift()
- profClosed := true
- if profClosed
- Candle C = pH.last()
- Candle P = na
- if pH.size() >= 2
- P := pH.get(pH.size() - 2)
- if C.blk == 1 and pType == 1 and (pState == 1 or pState == 2) and not na(pRev)
- bool expand = pDir == 1 ? C.c > pRev.h : C.c < pRev.l
- pInv := i_invMode == "Expansion candle 50%" ? C.half() : (pExt + C.c) / 2
- if expand
- pState := 2
- if i_showProf
- zn := fZone(C.tO, pInv, pDir == 1 ? C.h : C.l, pDir == 1 ? C.l : C.h)
- zLive := true
- else if not na(P) and (C.blk == 0 or C.blk == 1) and (pState == 0 or pState == 3) and (C.blk == 0 ? i_asia : i_london)
- bool fb = C.l < P.l and C.c > P.l and (not i_align or todayBias == 1)
- bool fs = C.h > P.h and C.c < P.h and (not i_align or todayBias == -1)
- if fb and fs
- fb := C.c >= C.o
- fs := not fb
- if fb or fs
- pState := 1
- pType := C.blk + 1
- pDir := fb ? 1 : -1
- pRev := C
- pExt := fb ? C.l : C.h
- pSwept := fb ? P.l : P.h
- pInv := na
- profEvt := pDir
- zLive := false
- prCap := fDrawProf(fb, pSwept, fb ? P.tL : P.tH, pExt, fb ? C.tL : C.tH, fProfName(pType))
- if C.blk == 1
- pInv := i_invMode == "Expansion candle 50%" ? C.half() : (pExt + C.c) / 2
- if i_showProf
- zn := fZone(C.tO, pInv, fb ? C.h : C.l, pExt)
- zLive := true
- if C.blk == 0 or C.blk == 1
- if na(dayLo) or C.l < dayLo
- dayLo := C.l
- dayLoT := C.tL
- if na(dayHi) or C.h > dayHi
- dayHi := C.h
- dayHiT := C.tH
- if na(pCur) or newBlk
- pCur := fNew(blk)
- else
- pCur.grow()
- var int dayStartBar = 0
- if newDay
- dayStartBar := bar_index
- pState := 0
- pType := 0
- pDir := 0
- pRev := na
- pExt := na
- pSwept := na
- pInv := na
- dayLo := na
- dayHi := na
- dayLoT := na
- dayHiT := na
- zLive := false
- zn := na
- prCap := na
- entCount := 0
- if blk == 2 and pState == 0 and i_ny and not na(dayLo) and not na(dayHi) and not na(pCur) and barstate.isconfirmed
- bool bullNY = (not i_align or todayBias == 1) and pCur.l < dayLo and close > dayLo and close > open
- bool bearNY = (not i_align or todayBias == -1) and pCur.h > dayHi and close < dayHi and close < open
- if bullNY and bearNY
- bullNY := todayBias != -1
- bearNY := not bullNY
- if bullNY or bearNY
- pState := 1
- pType := 3
- pDir := bullNY ? 1 : -1
- pRev := pCur
- pExt := bullNY ? pCur.l : pCur.h
- pSwept := bullNY ? dayLo : dayHi
- pInv := pExt
- profEvt := pDir
- zLive := false
- prCap := fDrawProf(bullNY, pSwept, bullNY ? dayLoT : dayHiT, pExt, bullNY ? pCur.tL : pCur.tH, fProfName(3))
- if profEvt != 0
- rEdge := math.max(rEdge, bar_index + 4)
- if pState == 1 and not na(pRev) and barstate.isconfirmed
- if pType == 2 and (pDir == 1 ? close > pRev.h : close < pRev.l)
- pState := 2
- else if pType == 3 and (pDir == 1 ? close > pRev.o : close < pRev.o)
- pState := 2
- bool invNow = false
- if (pState == 1 or pState == 2) and not na(pExt)
- if i_extViol and (pDir == 1 ? low < pExt : high > pExt)
- invNow := true
- if not invNow and blk == 2 and (pType == 1 or pType == 2) and not na(pInv)
- bool brk = i_invTrig == "Wick" ? (pDir == 1 ? low < pInv : high > pInv) : (barstate.isconfirmed and (pDir == 1 ? close < pInv : close > pInv))
- if brk
- invNow := true
- if invNow
- pState := 3
- invEvt := true
- zLive := false
- if not na(prCap)
- prCap.set_textcolor(c_grey)
- if i_showProf
- float lv = na(pInv) ? close : pInv
- fGLb(label.new(time, lv, "⟶ this is invalid", xloc = xloc.bar_time, style = label.style_label_left, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize)))
- rEdge := math.max(rEdge, bar_index + 16)
- if zLive and not na(zn) and not na(zn.b)
- if blk > 2 or (not na(zn.tC) and time - zn.tC >= i_maxLine * barMs)
- zLive := false
- else
- zn.b.set_right(time)
- zn.m.set_x2(time)
- zn.e.set_x2(time)
- int openMins = i_openHr * 60 + i_openMin
- bool isOpen = i_showOpen and nyMins >= openMins and (nz(nyMins[1], -1) < openMins or nyMins < nz(nyMins[1], 0))
- if isOpen
- int winMins = i_endH * 60 - nyMins
- int opBars = winMins > 0 ? math.max(1, math.min(i_openLen, int(math.floor(winMins * 60000 / barMs)))) : i_openLen
- int opEndT = time + barMs * opBars
- int hr12 = i_openHr % 12 == 0 ? 12 : i_openHr % 12
- string ampm = i_openHr >= 12 ? "pm" : "am"
- fGL(line.new(time, open, opEndT, open, xloc = xloc.bar_time, color = c_open, style = fLs(i_openSt), width = i_openW))
- if vOpLbl
- fGLb(label.new(opEndT, open, str.format("{0,number,0}:{1,number,00} {2}", hr12, i_openMin, ampm), xloc = xloc.bar_time, style = label.style_label_left, color = C_NONE, textcolor = c_txt, size = fSize(i_txtSize)))
- rEdge := math.max(rEdge, bar_index + opBars + (vOpLbl ? 8 : 0))
- int tfSec = timeframe.in_seconds()
- string rawMth = i_method == "Auto" ? (tfSec >= 600 ? "A" : tfSec >= 240 ? "B1" : "B2") : i_method == "A: 7H + 15m" ? "A" : i_method == "B: 1H + 5m" ? "B1" : "B2"
- string mth = (rawMth == "B1" and tfSec >= 3600) or (rawMth == "B2" and tfSec >= 1800) ? "A" : rawMth
- bool useA = mth == "A"
- string htfTF = mth == "B1" ? "60" : mth == "B2" ? "30" : timeframe.period
- float pvLow = ta.pivotlow(low, i_pivLen, i_pivLen)
- float pvHigh = ta.pivothigh(high, i_pivLen, i_pivLen)
- bool htfNew = not useA and timeframe.change(htfTF)
- var float hCurH = na
- var float hCurL = na
- var int hCurHB = na
- var int hCurLB = na
- var float hPrvH = na
- var float hPrvL = na
- var int hPrvHB = na
- var int hPrvLB = na
- if htfNew
- hPrvH := hCurH
- hPrvL := hCurL
- hPrvHB := hCurHB
- hPrvLB := hCurLB
- hCurH := high
- hCurL := low
- hCurHB := bar_index
- hCurLB := bar_index
- else
- if high > hCurH
- hCurH := high
- hCurHB := bar_index
- if low < hCurL
- hCurL := low
- hCurLB := bar_index
- var float refL = na
- var int refLB = na
- var float refH = na
- var int refHB = na
- if useA
- if not na(pvLow)
- refL := pvLow
- refLB := bar_index - i_pivLen
- if not na(pvHigh)
- refH := pvHigh
- refHB := bar_index - i_pivLen
- else
- refL := hPrvL
- refLB := hPrvLB
- refH := hPrvH
- refHB := hPrvHB
- bool bearC = close < open
- bool bullC = close > open
- var float dnO = na
- var int dnB = na
- var float upO = na
- var int upB = na
- if bearC and not bearC[1]
- dnO := open
- dnB := bar_index
- if bullC and not bullC[1]
- upO := open
- upB := bar_index
- var float swL = na
- var int swLB = na
- var int usedLB = -1
- var float cLvlB = na
- var int cBarB = na
- if newDay
- swL := na
- cLvlB := na
- if na(swL)
- if not na(refL) and nz(refLB, -2) != usedLB and low < refL
- swL := low
- swLB := bar_index
- usedLB := refLB
- cLvlB := dnO
- cBarB := dnB
- else
- if low <= swL
- swL := low
- swLB := bar_index
- cLvlB := dnO
- cBarB := dnB
- if bar_index - swLB > i_cisdMax
- swL := na
- var float swH = na
- var int swHB = na
- var int usedHB = -1
- var float cLvlS = na
- var int cBarS = na
- if newDay
- swH := na
- cLvlS := na
- if na(swH)
- if not na(refH) and nz(refHB, -2) != usedHB and high > refH
- swH := high
- swHB := bar_index
- usedHB := refHB
- cLvlS := upO
- cBarS := upB
- else
- if high >= swH
- swH := high
- swHB := bar_index
- cLvlS := upO
- cBarS := upB
- if bar_index - swHB > i_cisdMax
- swH := na
- bool cisdBull = barstate.isconfirmed and not na(swL) and not na(cLvlB) and close > cLvlB and bullC
- bool cisdBear = barstate.isconfirmed and not na(swH) and not na(cLvlS) and close < cLvlS and bearC
- var Setup act = na
- var int wins = 0
- var int losses = 0
- var int timeOuts = 0
- var float netR = 0.0
- int exitRel = (i_exitHr * 60 - i_dayStart * 60 + 1440) % 1440
- bool timeOut = newDay or (i_timeExit and relMins >= exitRel and nz(relMins[1], 0) < exitRel)
- if not na(act) and act.live and bar_index >= act.bE
- bool gapSL = act.dir == 1 ? open <= act.sl : open >= act.sl
- bool gapTP = act.dir == 1 ? open >= act.tp : open <= act.tp
- bool closeAtOpen = gapSL or gapTP or timeOut
- bool hitSL = not closeAtOpen and (act.dir == 1 ? low <= act.sl : high >= act.sl)
- bool hitTP = not closeAtOpen and (act.dir == 1 ? high >= act.tp : low <= act.tp)
- bool closed = closeAtOpen or hitSL or hitTP
- float barHi = closeAtOpen ? open : high
- float barLo = closeAtOpen ? open : low
- act.mfe := act.dir == 1 ? math.max(act.mfe, barHi) : math.min(act.mfe, barLo)
- act.mae := act.dir == 1 ? math.min(act.mae, barLo) : math.max(act.mae, barHi)
- float slEdge = act.dir == 1 ? math.max(act.mae, act.sl) : math.min(act.mae, act.sl)
- act.pgSL.set_lefttop(act.bE, math.max(act.entry, slEdge))
- act.pgSL.set_rightbottom(bar_index + 1, math.min(act.entry, slEdge))
- if i_showPath and not na(act.lnPath)
- act.lnPath.set_xy2(bar_index, close)
- if closed
- float xp = closeAtOpen ? open : hitSL ? act.sl : act.tp
- float risk = math.max(math.abs(act.entry - act.sl), syminfo.mintick)
- float resR = (xp - act.entry) * act.dir / risk
- act.live := false
- exitEvt := (gapSL or hitSL) ? -1 : (gapTP or hitTP) ? 1 : 2
- if exitEvt == 1
- wins += 1
- else if exitEvt == -1
- losses += 1
- else
- timeOuts += 1
- netR += resR
- act.bxSL.set_right(bar_index)
- act.bxTP.set_right(bar_index)
- act.pgTP.set_right(bar_index)
- act.pgSL.set_right(bar_index)
- if i_showPath and not na(act.lnPath)
- act.lnPath.set_xy2(bar_index, xp)
- var int lastEntBar = -1000
- bool inWin = blk == 1 or (blk == 2 and hNY < i_endH)
- bool profLiv = pState == 1 or pState == 2
- bool ctxB = inWin and (not i_align or todayBias == 1) and (not i_needProf or (profLiv and pDir == 1))
- bool ctxS = inWin and (not i_align or todayBias == -1) and (not i_needProf or (profLiv and pDir == -1))
- bool actLive = not na(act) and act.live
- bool canNew = i_showEnt and barstate.isconfirmed and not actLive and entCount < i_maxEnt and bar_index - lastEntBar >= i_cool
- bool goB = canNew and cisdBull and ctxB
- bool goS = canNew and cisdBear and ctxS and not goB
- if goB or goS
- int d = goB ? 1 : -1
- float ext = goB ? swL : swH
- int exB = goB ? swLB : swHB
- float cLv = goB ? cLvlB : cLvlS
- int cBr = goB ? cBarB : cBarS
- float slP = ext + (goB ? -1 : 1) * i_slBuf * syminfo.mintick
- if i_slMode == "Profile extreme" and profLiv and pDir == d and not na(pExt)
- slP := pExt + (goB ? -1 : 1) * i_slBuf * syminfo.mintick
- if na(slP) or (d == 1 ? slP >= close : slP <= close)
- slP := d == 1 ? low : high
- float risk = math.abs(close - slP)
- if risk >= syminfo.mintick
- float tpP = d == 1 ? close + risk * i_rr : close - risk * i_rr
- if i_tpMode == "Daily relevant swing"
- float tgt = d == 1 ? sH.p : sL.p
- if not na(tgt) and (d == 1 ? tgt >= close + risk : tgt <= close - risk)
- tpP := tgt
- Setup st = fSetup(d, cLv, cBr, ext, exB, slP, tpP)
- act := st
- setups.push(st)
- while setups.size() > i_keepSet
- fDelSetup(setups.shift())
- entCount += 1
- lastEntBar := bar_index
- entryNow := d
- else if vCtx and barstate.isconfirmed
- if cisdBull and ctxB and not na(cBarB)
- cisdLines.push(fGL(line.new(cBarB, cLvlB, bar_index + 3, cLvlB, color = c_cisd, width = i_cisdW)))
- rEdge := math.max(rEdge, bar_index + 3)
- if cisdBear and ctxS and not na(cBarS)
- cisdLines.push(fGL(line.new(cBarS, cLvlS, bar_index + 3, cLvlS, color = c_cisd, width = i_cisdW)))
- rEdge := math.max(rEdge, bar_index + 3)
- fCapL(cisdLines, i_keepCisd)
- if cisdBull
- swL := na
- cLvlB := na
- if cisdBear
- swH := na
- cLvlS := na
- barcolor(i_paintEnt and entryNow != 0 and time >= last_bar_time - (i_hist + 2) * 86400000 ? (entryNow == 1 ? c_entBull : c_entBear) : na, title = "Entry candle")
- alertcondition(exitEvt == 2, "Time exit", "7H Fractal: setup closed at session exit")
- var array<box> pnB = array.new<box>()
- var array<line> pnL = array.new<line>()
- var array<label> pnT = array.new<label>()
- if barstate.islast
- while pnB.size() > 0
- pnB.pop().delete()
- while pnL.size() > 0
- pnL.pop().delete()
- while pnT.size() > 0
- pnT.pop().delete()
- if i_showPnl and not na(pCur)
- int cnt = pH.size()
- int nC = i_pnlCount
- int rightClr = math.max(bar_index, rEdge)
- for st in setups
- if not na(st.bxTP)
- rightClr := math.max(rightClr, st.bxTP.get_right())
- if not na(st.bxSL)
- rightClr := math.max(rightClr, st.bxSL.get_right())
- int maxBase = bar_index + 495 - nC * (i_pnlW + i_pnlGap)
- int baseX = math.min(rightClr + i_pnlOff, math.max(bar_index + 1, maxBase))
- float lo = na
- float hi = na
- for k = 0 to nC - 1
- int idx = cnt - (nC - 1) + k
- if idx >= 0
- Candle cd = idx < cnt ? pH.get(idx) : pCur
- lo := na(lo) ? cd.l : math.min(lo, cd.l)
- hi := na(hi) ? cd.h : math.max(hi, cd.h)
- if not na(lo) and not na(hi)
- float visRng = math.max(fitHi - fitLo, syminfo.mintick * 10)
- float tgtH = visRng * (i_pnlPct / 100.0)
- float pRng = math.max(hi - lo, syminfo.mintick)
- float scl = i_pnlTrue ? 1.0 : tgtH / pRng
- float pMid = (lo + hi) * 0.5
- float loClamp = fitLo + tgtH * 0.55
- float hiClamp = fitHi - tgtH * 0.50
- float midY = i_pnlTrue ? pMid : (loClamp <= hiClamp ? math.max(loClamp, math.min(hiClamp, close)) : (fitLo + fitHi) * 0.5)
- float panelBot = i_pnlTrue ? lo - visRng * 0.04 : midY - tgtH * 0.5
- float prevXm = na
- for k = 0 to nC - 1
- int idx = cnt - (nC - 1) + k
- if idx >= 0
- Candle cd = idx < cnt ? pH.get(idx) : pCur
- int xl = math.min(baseX + k * (i_pnlW + i_pnlGap), bar_index + 498)
- int xr = math.min(xl + i_pnlW, bar_index + 499)
- int xm = int(math.round((xl + xr) * 0.5))
- bool bull = cd.c >= cd.o
- float yL = midY + (cd.l - pMid) * scl
- float yH = midY + (cd.h - pMid) * scl
- float bot = midY + (math.min(cd.o, cd.c) - pMid) * scl
- float top = midY + (math.max(cd.o, cd.c) - pMid) * scl
- if top - bot < visRng * 0.004
- top := bot + visRng * 0.004
- bool hl = pState > 0 and not na(pRev) and cd.tO == pRev.tO
- color hlCol = pState == 3 ? c_grey : c_pnlHl
- pnL.push(line.new(xm, yL, xm, yH, color = c_wick, width = 1))
- pnB.push(box.new(xl, top, xr, bot, border_color = hl ? hlCol : c_wick, border_width = hl ? 2 : 1, bgcolor = bull ? c_bullC : c_bearC))
- pnT.push(label.new(xm, panelBot - tgtH * 0.08, fHour(cd.blk), style = label.style_label_up, color = C_NONE, textcolor = c_txt, size = size.tiny))
- if hl
- pnT.push(fDot(xm, pDir == 1 ? yL - tgtH * 0.02 : yH + tgtH * 0.02, pState == 3 ? c_grey : c_profDot, false))
- if not na(pSwept) and not na(prevXm)
- float ySw = midY + (pSwept - pMid) * scl
- pnL.push(line.new(int(math.round(prevXm)), ySw, xm, ySw, color = c_profLn, width = 1))
- prevXm := xm
- if i_pnlTrue and pState > 0 and not na(pExt) and not na(pSwept)
- color lkC = pState == 3 ? c_grey : c_profLn
- pnL.push(line.new(bar_index, pSwept, baseX, pSwept, color = lkC, style = line.style_dotted, width = 1))
- pnL.push(line.new(bar_index, pExt, baseX, pExt, color = lkC, style = line.style_dotted, width = 1))
- if i_pnlCap
- string cap = pType > 0 ? fProfName(pType) + " profile ( the " + fHour(pType - 1) + " candle )" + (pState == 3 ? " · invalid" : "") : "no profile"
- int cx = math.min(baseX + int(math.round((nC * (i_pnlW + i_pnlGap) - i_pnlGap) * 0.5)), bar_index + 498)
- pnT.push(label.new(cx, panelBot - tgtH * 0.22, cap, style = label.style_label_up, color = C_NONE, textcolor = pState == 3 ? c_grey : c_txt, size = fSize(i_txtSize)))
- color tBg = C_NONE
- color tTx = i_theme == "Dark" ? #d1d4dc : i_theme == "Light" ? #2a2a2a : c_dTx
- color tNe = #8a8f98
- var table tbl = table.new(fPos(i_dashPos), 2, 8, frame_color = C_NONE, frame_width = 0, border_color = C_NONE, border_width = 0)
- fRow(int r, string k, string v, color vc) =>
- tbl.cell(0, r, k, text_color = tNe, bgcolor = tBg, text_size = fSize(i_dashSize), text_halign = text.align_left)
- tbl.cell(1, r, v, text_color = vc, bgcolor = tBg, text_size = fSize(i_dashSize), text_halign = text.align_right)
- if barstate.islast and i_showDash
- tbl.cell(0, 0, "7H Fractal Model", text_color = tTx, bgcolor = C_NONE, text_size = fSize(i_dashSize), text_halign = text.align_center)
- tbl.merge_cells(0, 0, 1, 0)
- string bTx = todayBias == 1 ? "Bullish ▲" : todayBias == -1 ? "Bearish ▼" : skipDay ? "Skip (" + (bias == 1 ? "bull" : "bear") + " wick)" : contInvalid ? "Invalidated (50%)" : "Neutral"
- color bCl = todayBias == 1 ? c_entBull : todayBias == -1 ? c_entBear : tNe
- fRow(1, "Daily bias", bTx, bCl)
- string pTx = pState == 0 ? "—" : fProfName(pType) + (pState == 1 ? " · formed" : pState == 2 ? " · expanded" : " · invalid")
- color pCl = pState == 0 or pState == 3 ? tNe : (pDir == 1 ? c_entBull : c_entBear)
- fRow(2, "7H profile", pTx, pCl)
- bool hasToday = not na(act) and act.bE >= dayStartBar
- bool okBias = todayBias != 0
- bool okProf = profLiv and (not i_align or pDir == todayBias)
- bool okCisd = hasToday and (not i_align or todayBias == 0 or act.dir == todayBias)
- bool swPend = (todayBias == 1 and not na(swL)) or (todayBias == -1 and not na(swH)) or (todayBias == 0 and (not na(swL) or not na(swH)))
- int score = (okBias ? 1 : 0) + (okProf ? 1 : 0) + (okCisd ? 1 : 0)
- fRow(3, "Bias · Profile · CISD", (okBias ? "●" : "○") + " " + (okProf ? "●" : "○") + " " + (okCisd ? "●" : swPend ? "◐" : "○"), score == 3 ? (todayBias == 1 ? c_entBull : c_entBear) : tNe)
- bool has = hasToday
- fRow(4, "Setup (today)", not has ? "—" : (act.dir == 1 ? "Long" : "Short") + (act.live ? " · live" : " · closed"), not has ? tNe : (act.dir == 1 ? c_entBull : c_entBear))
- fRow(5, "Entry / Stop", has ? str.tostring(act.entry, format.mintick) + " / " + str.tostring(act.sl, format.mintick) : "—", tTx)
- float rrV = has ? math.abs(act.tp - act.entry) / math.max(math.abs(act.entry - act.sl), syminfo.mintick) : na
- fRow(6, "Target", has ? str.tostring(act.tp, format.mintick) + " (" + str.tostring(rrV, "#.0") + "R)" : "—", tTx)
- int wl = wins + losses
- int tot = wl + timeOuts
- string wTx = wl > 0 ? " · " + str.tostring(wins * 100.0 / wl, "#") + "%" : ""
- string rTx = tot > 0 ? " · " + (netR >= 0 ? "+" : "") + str.tostring(netR, "#.0") + "R" : ""
- fRow(7, "W / L / T", str.tostring(wins) + " / " + str.tostring(losses) + " / " + str.tostring(timeOuts) + wTx + rTx, tTx)
- alertcondition(biasEvt == 1, "Bias · Bullish", "7H Fractal: daily bias turned bullish")
- alertcondition(biasEvt == -1, "Bias · Bearish", "7H Fractal: daily bias turned bearish")
- alertcondition(biasInv, "Bias invalidated", "7H Fractal: daily bias invalidated (continuation 50%)")
- alertcondition(profEvt == 1, "Profile · Long", "7H Fractal: bullish 7H reversal profile formed")
- alertcondition(profEvt == -1, "Profile · Short", "7H Fractal: bearish 7H reversal profile formed")
- alertcondition(invEvt, "Profile invalid", "7H Fractal: profile invalidated")
- alertcondition(entryNow == 1, "Entry · Long", "7H Fractal: long CISD entry")
- alertcondition(entryNow == -1, "Entry · Short", "7H Fractal: short CISD entry")
- alertcondition(exitEvt == 1, "Target hit", "7H Fractal: target reached")
- alertcondition(exitEvt == -1, "Stop hit", "7H Fractal: stop loss hit")
Advertisement
Add Comment
Please, Sign In to add comment