The trendline bug: a line continued past its second anchor at a different slope. Two conventions were fighting, and both were wrong. Lightweight Charts spaces bars evenly however much time separates them — a weekend is forty-nine hours and one bar wide. The renderer extended the line by interpolating between bar indices, which looked straight but disagreed with the server, since price_at() advances per second. Measured on real bars that reached 147 points: the chart drew a level the alerts did not believe in. Making the renderer match price_at() fixed the disagreement and made the visible kick worse, because now the line really did climb an hour's worth of slope across a one-bar maintenance break. Neither convention is what a person means by drawing a line. A trendline advances per bar, so both sides now evaluate in bar space: a new bar_space module the runtime uses to position sloped levels, mirrored by indexAt() in the chart. The line is straight on screen and the alert fires where it is drawn. Also, from testing against the live chart: - A plain click with the trendline tool armed did nothing and left the tool armed, so the next click began a new line — which is how the slope change was first noticed. Click-click and press-drag-release are both supported now, with the rubber band following the cursor between clicks. - Hand-placed levels are armed, fire once, then disarm themselves, and can be re-armed from the sidebar. Verified end to end: created armed, tripped within thirty seconds, disarmed, re-armed. - Layers is collapsible. - The 1h moving averages are gone; only the daily set remains. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
61 lines
2.2 KiB
Python
61 lines
2.2 KiB
Python
from pathlib import Path
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
from app.bars.models import Timeframe
|
|
|
|
|
|
TIMEFRAME_WEIGHT = {
|
|
Timeframe.M1: 1,
|
|
Timeframe.M2: 1,
|
|
Timeframe.M5: 1,
|
|
Timeframe.M15: 2,
|
|
Timeframe.M30: 3,
|
|
Timeframe.H1: 4,
|
|
Timeframe.D1: 16,
|
|
}
|
|
MA_WEIGHT_FACTOR = 0.75
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
|
|
|
|
live_source: str = "yahoo"
|
|
seed_source: str = "yahoo"
|
|
yahoo_symbol: str = "ES=F"
|
|
yahoo_poll_seconds: float = 20
|
|
seed_1h_range: str = "730d"
|
|
seed_1m_range: str = "8d"
|
|
timeframes: str = "1m,5m,15m,30m,1h,1d"
|
|
base_timeframes: str = "1m,30m,1d"
|
|
max_bars_per_tf: int = 5000
|
|
ma_sets__1d: str = "sma10,sma20,sma50,sma100,sma200"
|
|
daily_anchor_et: str = "18:00"
|
|
manual_lines_path: Path = Path("./data/manual_lines.json")
|
|
confluence_min_score: float = 28
|
|
# Four hours, chosen from the sweep in scripts/calibrate_alerts.py. Suppression is
|
|
# per price zone, so an unrelated zone still alerts immediately; this only
|
|
# governs how often the *same* area repeats itself.
|
|
alert_cooldown_seconds: int = 14400
|
|
ntfy_topic: str = ""
|
|
ntfy_server: str = "https://ntfy.sh"
|
|
chart_auth_token: str = ""
|
|
replay_file: Path | None = None
|
|
|
|
@property
|
|
def enabled_timeframes(self) -> list[Timeframe]:
|
|
return [Timeframe(value.strip()) for value in self.timeframes.split(",") if value.strip()]
|
|
|
|
@property
|
|
def ma_sets(self) -> dict[Timeframe, list[tuple[str, int]]]:
|
|
configured = {Timeframe.D1: self.ma_sets__1d}
|
|
result: dict[Timeframe, list[tuple[str, int]]] = {}
|
|
for tf, value in configured.items():
|
|
definitions = []
|
|
for item in filter(None, (part.strip().lower() for part in value.split(","))):
|
|
kind = "sma" if item.startswith("sma") else "ema" if item.startswith("ema") else ""
|
|
if not kind or not item[len(kind) :].isdigit():
|
|
raise ValueError(f"Invalid MA definition: {item}")
|
|
definitions.append((kind, int(item[len(kind) :])))
|
|
result[tf] = definitions
|
|
return result
|