Skip to content

bug: inconsistency between MAIDR, data and visual rendering #40

@SK-143381

Description

@SK-143381

Observed Behaviour

There is inconsistency between visually observable graph, data and MAIDR.
No matter what the open and close values are, red and green candlesticks are generating randomly. Further, upon manually changing the open close values from a static csv to observe changes, MAIDR is not able to detect bearish candles even after a manual swap. larger difference between open and close were also tested, but bearish was not being detected by MAIDR. However, upon manual modification the visual colour changed.

Expected Behaviour

The open and close values should be examined for every chart; if close is larger, the body of the candle should be green and MAIDR should successfully detect it and should the close be lower than open, the candle body should be red and MAIDR should detect that.

Reproducible Code

import pandas as pd
import mplfinance as mpf

data = {
'Date': ['2024-06-03', '2024-06-04', '2024-06-05', '2024-06-06', '2024-06-07'],
'Open': [100, 101, 102, 100, 99],
'High': [102, 103, 104, 101, 100],
'Low': [99, 100, 101, 98, 97],
'Close': [101, 102, 100, 99, 98], # First 2 are bullish (close > open), last 3 are bearish
'Volume': [1000000, 1100000, 1200000, 1300000, 900000]
}

df = pd.DataFrame(data)
df['Date'] = pd.to_datetime(df['Date'])
df = df.set_index('Date')

for col in ['Open', 'High', 'Low', 'Close']:
df[col] = df[col].astype(float)
df['Volume'] = df['Volume'].astype(int)

print("Data verification:")
for i, row in df.iterrows():
color = "GREEN (bullish)" if row['Close'] > row['Open'] else "RED (bearish)"
print(f"{i.date()}: Open={row['Open']}, Close={row['Close']} -> Should be {color}")

mpf.plot(
df,
type='candle',
mav=(3,),
volume=True,
title="Bug: Red candles appear even when Close > Open",
style='yahoo'
)

Suggestion

It might also be helpful to replace "Price ($)," with "Price ($):" to not confuse users

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions