while25 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- while25/__init__.py +341 -0
- while25/_costs/brokers/alpaca.json +96 -0
- while25/_costs/brokers/binance.json +34 -0
- while25/_costs/brokers/coinbase.json +34 -0
- while25/_costs/brokers/ibkr.json +39 -0
- while25/_costs/brokers/upstox.json +175 -0
- while25/_costs/brokers/zerodha.json +175 -0
- while25/_costs/crypto_alpaca.json +27 -0
- while25/_costs/global_crypto.json +18 -0
- while25/_costs/in_nse_equity.json +238 -0
- while25/_costs/in_nse_etf.json +352 -0
- while25/_costs/in_nse_fo.json +450 -0
- while25/_costs/us_crypto.json +18 -0
- while25/_costs/us_equity.json +175 -0
- while25/_costs/us_options.json +172 -0
- while25/_days.py +123 -0
- while25/_figures.py +233 -0
- while25/_runtime.py +49 -0
- while25/_universes/banknifty.json +80 -0
- while25/_universes/ndx100.json +520 -0
- while25/_universes/nifty50.json +260 -0
- while25/_universes/nifty500.json +2505 -0
- while25/_universes/sp500.json +2525 -0
- while25/assume.py +263 -0
- while25/backtest.py +881 -0
- while25/barline.py +160 -0
- while25/combo_legs.py +238 -0
- while25/errors.py +77 -0
- while25/fonts/IBMPlexMono-Regular.ttf +0 -0
- while25/fonts/IBMPlexMono-SemiBold.ttf +0 -0
- while25/fonts/Inter-Bold.ttf +0 -0
- while25/fonts/Inter-Regular.ttf +0 -0
- while25/fonts/Inter-SemiBold.ttf +0 -0
- while25/fonts/OFL-IBMPlexMono.txt +93 -0
- while25/fonts/OFL-Inter.txt +93 -0
- while25/future_pick.py +77 -0
- while25/inputs.py +215 -0
- while25/instruments.py +488 -0
- while25/modules.py +397 -0
- while25/money.py +24 -0
- while25/option_pick.py +221 -0
- while25/plots.py +147 -0
- while25/report.py +644 -0
- while25/ui.py +680 -0
- while25/universes.py +70 -0
- while25-0.1.0.dist-info/METADATA +3194 -0
- while25-0.1.0.dist-info/RECORD +50 -0
- while25-0.1.0.dist-info/WHEEL +5 -0
- while25-0.1.0.dist-info/licenses/LICENSE +201 -0
- while25-0.1.0.dist-info/top_level.txt +1 -0
while25/plots.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"""How an indicator declares what it draws.
|
|
2
|
+
|
|
3
|
+
ONE indicator, ONE label, N lines. A custom Bollinger is a single entry on the
|
|
4
|
+
chart with three plots under it — not three unrelated series the user has to
|
|
5
|
+
recognise as belonging together and configure one at a time.
|
|
6
|
+
|
|
7
|
+
Everything here maps onto what the terminal's own indicators already use, so a
|
|
8
|
+
Python indicator is not a second-class citizen: the same settings dialog edits
|
|
9
|
+
it, the same style overrides apply, and a user can recolour or re-thickness any
|
|
10
|
+
line exactly as they would for a built-in.
|
|
11
|
+
|
|
12
|
+
Declared, not drawn. The author says what the shape IS; While25 renders it. That
|
|
13
|
+
is what keeps a plugin from being able to break the chart's look or its
|
|
14
|
+
rendering performance.
|
|
15
|
+
"""
|
|
16
|
+
from dataclasses import dataclass, field
|
|
17
|
+
|
|
18
|
+
# Matches the chart's LineStyleKey exactly. A value outside this set would be
|
|
19
|
+
# silently dropped at render time, so it is refused here where the author can
|
|
20
|
+
# see it.
|
|
21
|
+
LINE_STYLES = ("solid", "dotted", "dashed", "large-dashed", "sparse-dotted")
|
|
22
|
+
|
|
23
|
+
# How a plot is drawn. `line` is the default; `histogram` and `area` are the
|
|
24
|
+
# shapes that a line genuinely cannot express (MACD bars, filled envelopes).
|
|
25
|
+
PLOT_TYPES = ("line", "histogram", "area", "stepline")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class PlotError(ValueError):
|
|
29
|
+
"""A declaration the chart could not render as written."""
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass
|
|
33
|
+
class Plot:
|
|
34
|
+
"""One line of an indicator.
|
|
35
|
+
|
|
36
|
+
`name` is both the key `compute()` returns and the label shown in the
|
|
37
|
+
settings dialog and the legend — one name, so an author cannot end up with a
|
|
38
|
+
series called "upper" that displays as something else.
|
|
39
|
+
"""
|
|
40
|
+
name: str
|
|
41
|
+
color: str = "" # "" = the chart's rotating palette picks one
|
|
42
|
+
width: int = 1
|
|
43
|
+
style: str = "solid"
|
|
44
|
+
plot_type: str = "line"
|
|
45
|
+
# Histogram / bi-colour down-colour. Absent means "same as color".
|
|
46
|
+
color_down: str = ""
|
|
47
|
+
opacity: float = 1.0
|
|
48
|
+
overlay: bool | None = None # None = follow the indicator's own setting
|
|
49
|
+
visible: bool = True
|
|
50
|
+
|
|
51
|
+
def __post_init__(self) -> None:
|
|
52
|
+
if not str(self.name).strip():
|
|
53
|
+
raise PlotError("a plot needs a name")
|
|
54
|
+
if self.style not in LINE_STYLES:
|
|
55
|
+
raise PlotError(
|
|
56
|
+
f"unknown line style {self.style!r}; expected one of {', '.join(LINE_STYLES)}")
|
|
57
|
+
if self.plot_type not in PLOT_TYPES:
|
|
58
|
+
raise PlotError(
|
|
59
|
+
f"unknown plot type {self.plot_type!r}; expected one of {', '.join(PLOT_TYPES)}")
|
|
60
|
+
# The chart clamps to 1..4 at apply time; refusing here tells the author
|
|
61
|
+
# rather than silently drawing something they did not ask for.
|
|
62
|
+
if not 1 <= int(self.width) <= 4:
|
|
63
|
+
raise PlotError(f"width must be 1-4, not {self.width}")
|
|
64
|
+
if not 0.0 <= float(self.opacity) <= 1.0:
|
|
65
|
+
raise PlotError(f"opacity must be 0-1, not {self.opacity}")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass
|
|
69
|
+
class Fill:
|
|
70
|
+
"""A translucent band between two named plots — the Bollinger envelope."""
|
|
71
|
+
upper: str
|
|
72
|
+
lower: str
|
|
73
|
+
color: str = ""
|
|
74
|
+
opacity: float = 0.08
|
|
75
|
+
|
|
76
|
+
def __post_init__(self) -> None:
|
|
77
|
+
if not self.upper or not self.lower:
|
|
78
|
+
raise PlotError("a fill needs an upper and a lower plot name")
|
|
79
|
+
if self.upper == self.lower:
|
|
80
|
+
raise PlotError("a fill needs two DIFFERENT plots")
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
@dataclass
|
|
84
|
+
class Level:
|
|
85
|
+
"""A horizontal reference line — RSI's 30 and 70."""
|
|
86
|
+
value: float
|
|
87
|
+
color: str = ""
|
|
88
|
+
width: int = 1
|
|
89
|
+
style: str = "dashed"
|
|
90
|
+
|
|
91
|
+
def __post_init__(self) -> None:
|
|
92
|
+
if self.style not in LINE_STYLES:
|
|
93
|
+
raise PlotError(f"unknown line style {self.style!r}")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@dataclass
|
|
97
|
+
class Band:
|
|
98
|
+
"""Shading between two levels — RSI's overbought zone."""
|
|
99
|
+
top: float
|
|
100
|
+
bottom: float
|
|
101
|
+
color: str = ""
|
|
102
|
+
opacity: float = 0.06
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass
|
|
106
|
+
class Style:
|
|
107
|
+
"""The whole appearance of an indicator, as declared."""
|
|
108
|
+
plots: list = field(default_factory=list)
|
|
109
|
+
fills: list = field(default_factory=list)
|
|
110
|
+
levels: list = field(default_factory=list)
|
|
111
|
+
bands: list = field(default_factory=list)
|
|
112
|
+
overlay: bool = True
|
|
113
|
+
# A fixed scale for bounded indicators (RSI 0-100), so the pane does not
|
|
114
|
+
# autoscale to whatever the data happens to span.
|
|
115
|
+
y_min: float | None = None
|
|
116
|
+
y_max: float | None = None
|
|
117
|
+
precision: int | None = None
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def validate(plots, fills=(), levels=(), bands=()) -> None:
|
|
121
|
+
"""Refuse a declaration the chart cannot honour, at DECLARATION time.
|
|
122
|
+
|
|
123
|
+
Catching it here means the author sees it when they run the file, rather
|
|
124
|
+
than discovering at render time that one of their lines silently vanished.
|
|
125
|
+
"""
|
|
126
|
+
names = [p.name for p in plots]
|
|
127
|
+
if not names:
|
|
128
|
+
raise PlotError("an indicator must declare at least one plot")
|
|
129
|
+
|
|
130
|
+
seen = set()
|
|
131
|
+
for n in names:
|
|
132
|
+
if n in seen:
|
|
133
|
+
# Two plots under one name: compute() returns a dict, so one would
|
|
134
|
+
# simply overwrite the other with no way to tell which won.
|
|
135
|
+
raise PlotError(f"plot {n!r} is declared more than once")
|
|
136
|
+
seen.add(n)
|
|
137
|
+
|
|
138
|
+
for f in fills:
|
|
139
|
+
for side in (f.upper, f.lower):
|
|
140
|
+
if side not in seen:
|
|
141
|
+
raise PlotError(
|
|
142
|
+
f"fill references {side!r}, which is not one of the declared plots")
|
|
143
|
+
|
|
144
|
+
for b in bands:
|
|
145
|
+
if b.top <= b.bottom:
|
|
146
|
+
raise PlotError(
|
|
147
|
+
f"band top ({b.top}) must be above its bottom ({b.bottom})")
|