17_STRATEGII/08_mbp: noua etichete scoase de pe linii in diagrama de ansamblu

Raportata era una singura. eticheta_libera le-a gasit pe toate noua, inclusiv
cinci praguri din panoul TICUS scrise de mana in generator, la trei inaltimi
diferite fata de linia lor. Doua lucruri pe care nu le vedeam fara unealta:
marcajul candelei M era plafonat de Chart exact pe linia SL-ului, iar o mutare
de-a corectorului a creat o regresie noua (text peste text), prinsa de
audit_diagrams.

Verificarea ruleaza acum in generator fara exceptii, deci regresiile se prind
singure data viitoare. Cifrele n-au fost atinse.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ThN7ixZrowca8aTGrK1MUJ
This commit is contained in:
Claude Agent
2026-10-02 05:04:32 +00:00
parent bd24084c29
commit c15004c62b
4 changed files with 139 additions and 111 deletions

View File

@@ -29,7 +29,9 @@ import sys
from pathlib import Path
sys.path.insert(0, "/workspace/atm-curs-dl")
sys.path.insert(0, "/workspace/atm-curs-dl/gen")
from svg_candles import Chart, Level, Mark, from_closes # noqa: E402
from eticheta_libera import eticheta_libera # noqa: E402
OUT = Path(__file__).resolve().parent / "mbp_ansamblu.svg"
@@ -106,13 +108,19 @@ assert abs((exit_ill - entry) / risc - 4.0) < 0.15, (exit_ill - entry) / risc
# nu există nicio linie de stop desenată deasupra intrării
assert sl < entry
# `label_dy` ridică eticheta cu 8 px peste linia ei: implicit stă la y − 6, cu
# coada literelor peste linie. Banda inferioară merge în jos (dy = +22), nu în
# sus: la 0.05 $ deasupra ei trece linia de intrare, iar la scara asta (150
# px/$) între cele două linii nu încape un rând de text.
levels = [
Level(623.90, "623.90 — bandă inferioară", BLUE, dash="4 3", label_at="left"),
Level(624.70, "624.70 — bandă superioară", BLUE, dash="4 3", label_at="right"),
Level(624.30, "624.30 — SMA20 / TP1", GRAY, dash="4 3", label_at="left"),
Level(sl, f"SL {sl:.2f} (lowest low, 4 candele)", RED, label_at="left"),
Level(entry, f"trigger Buy Momentum → intrare {entry:.2f}", GREEN, label_at="right"),
Level(625.35, "ieșire ilustrativă ~625.35 (≈ 1:4)", GREEN, dash="2 3", label_at="right"),
Level(623.90, "623.90 — bandă inferioară", BLUE, dash="4 3", label_at="left", label_dy=22),
Level(624.70, "624.70 — bandă superioară", BLUE, dash="4 3", label_at="right", label_dy=-8),
Level(624.30, "624.30 — SMA20 / TP1", GRAY, dash="4 3", label_at="left", label_dy=-8),
Level(sl, f"SL {sl:.2f} (lowest low, 4 candele)", RED, label_at="left", label_dy=-8),
Level(entry, f"trigger Buy Momentum → intrare {entry:.2f}", GREEN, label_at="right",
label_dy=-8),
Level(625.35, "ieșire ilustrativă ~625.35 (≈ 1:4)", GREEN, dash="2 3", label_at="right",
label_dy=-8),
]
assert all("stop" not in lv.text.lower() or lv.price < entry for lv in levels)
assert all(not ("sl" in lv.text.lower() and lv.price > entry) for lv in levels)
@@ -124,9 +132,15 @@ marks = [
# titlul si eticheta de trend sunt injectate manual (nu prin Chart.title, care
# ar sta lipit de prima candelă, si nici prin Chart.trend, care s-ar bate cu
# titlul) ca sa rămână spațiu liber deasupra seriei.
ch = Chart(candles=cds, levels=levels, marks=marks,
# nivel-distanțier fără etichetă: coboară baza graficului cu 15 px, ca marcajul
# de sub candela M să nu mai fie plafonat exact pe linia SL-ului
SPACER = [Level(sl - 0.10, "", "none", dash="")]
ch = Chart(candles=cds, levels=levels + SPACER, marks=marks,
scale=150.0, gap=16, body_w=10, left=48, width=700, top=96)
svg = ch.render()
# eticheta goală a distanțierului nu are ce căuta în SVG: auditul o citește ca
# text suprapus peste ce e sub ea
svg = re.sub(r"\n\s*<text[^>]*>\s*</text>", "", svg)
TITLE = "SPY — 15 min: bandă + TICUS pe aceeași candelă → trigger → intrare → SL → TP1 → trail"
@@ -137,7 +151,7 @@ m = re.search(r'viewBox="0 0 (\d+) ([0-9.]+)"', svg)
W, H0 = int(m.group(1)), float(m.group(2))
ticus_top = H0 + 34
y0 = ticus_top + 70 # linia 0
y0 = ticus_top + 84 # linia 0
px1000 = 50.0 # 1000 unități TICUS = 50 px
def ty(v: float) -> float:
return y0 - v / 1000.0 * px1000
@@ -149,22 +163,22 @@ panel = [
f'<text x="24" y="{ticus_top:.0f}" fill="#333">TICUS — presiunea pieței (↑ = peste 0)</text>',
# linii de prag
f'<line x1="24" y1="{ty(1000):.1f}" x2="{W - 14}" y2="{ty(1000):.1f}" stroke="{RED}" stroke-width="1.5" stroke-dasharray="4 3"/>',
f'<text x="28" y="{ty(1000) - 4:.1f}" fill="{RED}">+1000 — supracumpărare</text>',
f'<text x="28" y="{ty(1000) - 9:.1f}" fill="{RED}">+1000 — supracumpărare</text>',
f'<line x1="24" y1="{ty(500):.1f}" x2="{W - 14}" y2="{ty(500):.1f}" stroke="#caa000" stroke-width="1" stroke-dasharray="2 2"/>',
f'<text x="28" y="{ty(500) - 4:.1f}" fill="#caa000">+500 (doar referință vizuală)</text>',
f'<text x="28" y="{ty(500) - 9:.1f}" fill="#caa000">+500 (doar referință vizuală)</text>',
f'<line x1="24" y1="{ty(0):.1f}" x2="{W - 14}" y2="{ty(0):.1f}" stroke="#888" stroke-width="1.5"/>',
f'<text x="{W - 12}" y="{ty(0) + 4:.1f}" fill="#666" text-anchor="end">0</text>',
f'<text x="{W - 12}" y="{ty(0) - 9:.1f}" fill="#666" text-anchor="end">0</text>',
f'<line x1="24" y1="{ty(-500):.1f}" x2="{W - 14}" y2="{ty(-500):.1f}" stroke="#caa000" stroke-width="1" stroke-dasharray="2 2"/>',
f'<text x="28" y="{ty(-500) + 13:.1f}" fill="#caa000">-500 (doar referință vizuală)</text>',
f'<text x="28" y="{ty(-500) - 9:.1f}" fill="#caa000">-500 (doar referință vizuală)</text>',
f'<line x1="24" y1="{ty(-1000):.1f}" x2="{W - 14}" y2="{ty(-1000):.1f}" stroke="{GREEN}" stroke-width="1.5" stroke-dasharray="4 3"/>',
f'<text x="28" y="{ty(-1000) + 13:.1f}" fill="{GREEN}">-1000 — oversold</text>',
f'<text x="28" y="{ty(-1000) - 9:.1f}" fill="{GREEN}">-1000 — oversold</text>',
# barul TICUS al candelei M, sub -1000 (colorat roșu)
f'<rect x="{xm - 5:.1f}" y="{bar_top:.1f}" width="10" height="{bar_bot - bar_top:.1f}" fill="{RED}"/>',
f'<text x="{xm + 10:.1f}" y="{bar_bot + 4:.1f}" fill="{RED}">M: TICUS -1150 (sub -1000)</text>',
f'<text x="{xm + 14:.1f}" y="{bar_bot + 18:.1f}" fill="{RED}">M: TICUS -1150 (sub -1000)</text>',
]
# linia punctată verticală: aceeași candelă sus și jos (pornește sub mark-ul
# lui M, ca să nu taie textul „M: roșie...")
y_candle_m = ch._y(cds[M_IX].l) + 26
y_candle_m = ch._y(cds[M_IX].l) + 46
panel.insert(0, f'<line x1="{xm:.1f}" y1="{y_candle_m:.1f}" x2="{xm:.1f}" y2="{bar_bot:.1f}" '
f'stroke="#aaa" stroke-width="1" stroke-dasharray="3 3"/>')
@@ -194,6 +208,17 @@ assert bar_svg in svg, "barul TICUS nu a fost desenat"
assert abs((float(re.search(r'x="([\d.]+)"', bar_svg).group(1)) + 5) - ch._cx(M_IX)) < 1e-9
# aceeași scară px/unitate: SL-intrare și intrare-TP1 sunt egale și vizual (1:1)
assert abs((ch._y(sl) - ch._y(entry)) - (ch._y(entry) - ch._y(tp1))) < 1e-9
# nicio etichetă de nivel sau de candelă nu are voie să stea pe desen: aici
# contează mai ales liniile vecine (banda inferioară și intrarea sunt la 0.05 $
# una de alta, deci etichetele lor se bat cap în cap cu linia celuilalt)
eticheta_libera(svg, "ansamblu", {lv.text for lv in levels} | {mk.text for mk in marks},
rects=True)
# același tratament pentru etichetele panoului de TICUS, scrise de mână aici
eticheta_libera(svg, "panoul TICUS",
{"+1000 — supracumpărare", "+500 (doar referință vizuală)", "0",
"-500 (doar referință vizuală)", "-1000 — oversold",
"M: TICUS -1150 (sub -1000)", "TICUS — presiunea pieței (↑ = peste 0)"},
rects=True)
assert f'x1="{xm:.1f}"' in svg
OUT.write_text(svg)
print(f"scris {OUT.name}: {len(cds)} candele, entry {entry:.2f}, SL {sl:.2f}, "

View File

@@ -1,16 +1,17 @@
<svg viewBox="0 0 700 715" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;font:12px sans-serif">
<line x1="24" y1="381.0" x2="686" y2="381.0" stroke="#1a5fb4" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="30" y="375.0" fill="#1a5fb4">623.90 — bandă inferioară</text>
<line x1="24" y1="261.0" x2="686" y2="261.0" stroke="#1a5fb4" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="672" y="255.0" fill="#1a5fb4" text-anchor="end">624.70 — bandă superioară</text>
<line x1="24" y1="321.0" x2="686" y2="321.0" stroke="#777" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="30" y="315.0" fill="#777">624.30 — SMA20 / TP1</text>
<line x1="24" y1="426.0" x2="686" y2="426.0" stroke="#c00" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="30" y="420.0" fill="#c00">SL 623.60 (lowest low, 4 candele)</text>
<line x1="24" y1="373.5" x2="686" y2="373.5" stroke="#188a3e" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="672" y="367.5" fill="#188a3e" text-anchor="end">trigger Buy Momentum → intrare 623.95</text>
<line x1="24" y1="163.5" x2="686" y2="163.5" stroke="#188a3e" stroke-width="1.5" stroke-dasharray="2 3"/>
<text x="672" y="157.5" fill="#188a3e" text-anchor="end">ieșire ilustrativă ~625.35 (≈ 1:4)</text>
<svg viewBox="0 0 700 744" xmlns="http://www.w3.org/2000/svg" style="width:100%;height:auto;font:12px sans-serif">
<line x1="24.0" y1="381.0" x2="686" y2="381.0" stroke="#1a5fb4" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="30.0" y="397.0" fill="#1a5fb4">623.90 — bandă inferioară</text>
<line x1="24.0" y1="261.0" x2="686" y2="261.0" stroke="#1a5fb4" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="672" y="247.0" fill="#1a5fb4" text-anchor="end">624.70 — bandă superioară</text>
<line x1="24.0" y1="321.0" x2="686" y2="321.0" stroke="#777" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="30.0" y="307.0" fill="#777">624.30 — SMA20 / TP1</text>
<line x1="24.0" y1="426.0" x2="686" y2="426.0" stroke="#c00" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="30.0" y="412.0" fill="#c00">SL 623.60 (lowest low, 4 candele)</text>
<line x1="24.0" y1="373.5" x2="686" y2="373.5" stroke="#188a3e" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="672" y="359.5" fill="#188a3e" text-anchor="end">trigger Buy Momentum → intrare 623.95</text>
<line x1="24.0" y1="163.5" x2="686" y2="163.5" stroke="#188a3e" stroke-width="1.5" stroke-dasharray="2 3"/>
<text x="672" y="149.5" fill="#188a3e" text-anchor="end">ieșire ilustrativă ~625.35 (≈ 1:4)</text>
<line x1="24.0" y1="441.0" x2="686" y2="441.0" stroke="none" stroke-width="1.5" stroke-dasharray=""/>
<line x1="48.0" y1="96.0" x2="48.0" y2="153.0" stroke="#1a1a1a" stroke-width="1.2"/>
<rect x="43.0" y="103.5" width="10" height="22.5" fill="#c00"/>
<line x1="64.0" y1="99.0" x2="64.0" y2="180.0" stroke="#1a1a1a" stroke-width="1.2"/>
@@ -71,25 +72,25 @@
<rect x="491.0" y="174.0" width="10" height="12.0" fill="#188a3e"/>
<line x1="512.0" y1="163.5" x2="512.0" y2="192.0" stroke="#1a1a1a" stroke-width="1.2"/>
<rect x="507.0" y="163.5" width="10" height="10.5" fill="#188a3e"/>
<text x="272.0" y="440.0" fill="#c00" text-anchor="middle" style="font-weight:bold">M: roșie, close 623.87 sub bandă</text>
<text x="272.0" y="446.0" fill="#c00" text-anchor="middle" style="font-weight:bold">M: roșie, close 623.87 sub bandă</text>
<text x="24" y="26" fill="#333" style="font-weight:bold">SPY — 15 min: bandă + TICUS pe aceeași candelă → trigger → intrare → SL → TP1 → trail</text>
<text x="24" y="64" fill="#999">trend descendent anterior (14 bare)</text>
<line x1="272.0" y1="452.0" x2="272.0" y2="613.5" stroke="#aaa" stroke-width="1" stroke-dasharray="3 3"/>
<text x="24" y="486" fill="#333">TICUS — presiunea pieței (↑ = peste 0)</text>
<line x1="24" y1="506.0" x2="686" y2="506.0" stroke="#c00" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="28" y="502.0" fill="#c00">+1000 — supracumpărare</text>
<line x1="24" y1="531.0" x2="686" y2="531.0" stroke="#caa000" stroke-width="1" stroke-dasharray="2 2"/>
<text x="28" y="527.0" fill="#caa000">+500 (doar referință vizuală)</text>
<line x1="24" y1="556.0" x2="686" y2="556.0" stroke="#888" stroke-width="1.5"/>
<text x="688" y="560.0" fill="#666" text-anchor="end">0</text>
<line x1="24" y1="581.0" x2="686" y2="581.0" stroke="#caa000" stroke-width="1" stroke-dasharray="2 2"/>
<text x="28" y="594.0" fill="#caa000">-500 (doar referință vizuală)</text>
<line x1="24" y1="606.0" x2="686" y2="606.0" stroke="#188a3e" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="28" y="619.0" fill="#188a3e">-1000 — oversold</text>
<rect x="267.0" y="556.0" width="10" height="57.5" fill="#c00"/>
<text x="282.0" y="617.5" fill="#c00">M: TICUS -1150 (sub -1000)</text>
<text x="24" y="650.0" fill="#555">SPY 15 min. Cifre din curs: M close 623.87 (sub bandă 623.90), TICUS -1150 pe aceeași candelă,</text>
<text x="24" y="667.0" fill="#555">trigger Buy Momentum → entry 623.95, SL 623.60 (lowest low din 4 candele, trigger inclus),</text>
<text x="24" y="684.0" fill="#555">TP1 624.30 (+0.35, 1:1). Ieșirea ~625.35 = entry + 4R (≈1:4) e ilustrativă — preț derivat din R,</text>
<text x="24" y="701.0" fill="#555">nu din curs. Structura candelelor (30 bare continue) e construită de mine.</text>
<line x1="272.0" y1="472.0" x2="272.0" y2="642.5" stroke="#aaa" stroke-width="1" stroke-dasharray="3 3"/>
<text x="24" y="501" fill="#333">TICUS — presiunea pieței (↑ = peste 0)</text>
<line x1="24" y1="535.0" x2="686" y2="535.0" stroke="#c00" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="28" y="526.0" fill="#c00">+1000 — supracumpărare</text>
<line x1="24" y1="560.0" x2="686" y2="560.0" stroke="#caa000" stroke-width="1" stroke-dasharray="2 2"/>
<text x="28" y="551.0" fill="#caa000">+500 (doar referință vizuală)</text>
<line x1="24" y1="585.0" x2="686" y2="585.0" stroke="#888" stroke-width="1.5"/>
<text x="688" y="576.0" fill="#666" text-anchor="end">0</text>
<line x1="24" y1="610.0" x2="686" y2="610.0" stroke="#caa000" stroke-width="1" stroke-dasharray="2 2"/>
<text x="28" y="601.0" fill="#caa000">-500 (doar referință vizuală)</text>
<line x1="24" y1="635.0" x2="686" y2="635.0" stroke="#188a3e" stroke-width="1.5" stroke-dasharray="4 3"/>
<text x="28" y="626.0" fill="#188a3e">-1000 — oversold</text>
<rect x="267.0" y="585.0" width="10" height="57.5" fill="#c00"/>
<text x="286.0" y="660.5" fill="#c00">M: TICUS -1150 (sub -1000)</text>
<text x="24" y="679.0" fill="#555">SPY 15 min. Cifre din curs: M close 623.87 (sub bandă 623.90), TICUS -1150 pe aceeași candelă,</text>
<text x="24" y="696.0" fill="#555">trigger Buy Momentum → entry 623.95, SL 623.60 (lowest low din 4 candele, trigger inclus),</text>
<text x="24" y="713.0" fill="#555">TP1 624.30 (+0.35, 1:1). Ieșirea ~625.35 = entry + 4R (≈1:4) e ilustrativă — preț derivat din R,</text>
<text x="24" y="730.0" fill="#555">nu din curs. Structura candelelor (30 bare continue) e construită de mine.</text>
</svg>

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB