matplotlib / matplotlib/mplfinance
Feature Request: Add ability to add rectangles representing price range in mplfinance
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.4k
- Forks
- 678
- PR merge metrics
- No merged PRs in 30d
Description
Drawing Supply/Demand zones is a common price action methodology to analyze charts. Typically involves drawing a rectangle from a high and low point in a group of candles. Typically this rectangle can be bounded to a time-frame occupied by the said candles or extend to the right. See for example: https://www.flowbank.com/en/research/price-action-trading-strategy-supply-demand-zones
**Solution Proposal**
Like hlines, vlines, alines, tlines - create a first class object rectangle, specifying the 4 point coordinates. Ideally rectangles should take a list of dicts representing each rectangle. All style options like edgecolor, fillcolor, alpha, linewidths should be available for customization. A bonus would be to have an annotation capability to write a text in the rectangle describing the drawing.
**Alternatives Tried**
Tried to leverage alines to draw this using the linewidths. So for example if I needed to draw a rectangle with coordinates between price 250 and 270 from a specific date to today, I tried to draw the aline at 260 with a linewidths of 10. But what I realized is that linewidths doesn't represent the y axis scale but some arbitrary value. So it wasn't possible to draw the desired rectangle. By adjusting the linewidths, I was either overshooting or undercutting the rectangle I needed. Also it was only a trial and error. My suspicion is that if the scale of the figure changed, the linewidths would need to be calibrated again.
Hope my description of the above problem is clear enough
Example
In this example I'm trying to draw a line between a low point of 950.5 and high point of 1072.38. To approximately match the two end points, I drew the aline at the mid point of 1011.44, however arrived at a width of 91.41 by a trial and error, even though the width according to the y-axis would have been 60.94 (in each direction) or 121.88 (total width)
`{'alines': [(Timestamp('2021-12-06 05:00:00+0000', tz='UTC'), 1011.44), (Timestamp('2021-12-08 05:00:00+0000', tz='UTC'), 1011.44)], 'colors': ['c'], 'alpha': 0.4, 'linewidths': 91.41000000000008}`

Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading how mplfinance handles hlines, vlines, alines, and tlines, then inspect Matplotlib's rectangle support and coordinate handling. Done means users can provide rectangle coordinates, style options such as edgecolor, fillcolor, alpha, and linewidths, and optionally annotate rectangles without relying on trial-and-error line widths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- matplotlib, python
- Domain
- data-visualization
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100