Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weekly Result of Indicators are Not Correct #1183

Open
hmuhdkamran opened this issue Apr 1, 2024 · 4 comments
Open

Weekly Result of Indicators are Not Correct #1183

hmuhdkamran opened this issue Apr 1, 2024 · 4 comments
Labels
user support Help a user with their implementation

Comments

@hmuhdkamran
Copy link

hmuhdkamran commented Apr 1, 2024

the problem

I am using Indicators, Super Trend, Connors RSI, Momentum and Dema, the return value of daily and monthly return accurate with trading view, while weekly result varies, I have attached the image it will elaborate it,

image

Sql Script

SELECT 
                                                fnl.symbol, 
                                                fnl.max_date AS date, 
                                                so_open.open AS open, 
                                                fnl.high, 
                                                fnl.low, 
                                                so_close.close AS close, 
                                                so_close.volume AS volume
                                            FROM (
                                                SELECT 
                                                    sd.symbol,
                                                    MAX(sd.date) AS max_date, 
                                                    MAX(sd.high) AS high,
                                                    MIN(sd.low) AS low
                                                FROM stock_data sd
                                                GROUP BY sd.symbol, strftime('%Y-%m-%W', sd.date)
                                            ) fnl
                                            JOIN stock_data so_open ON so_open.date = fnl.max_date AND so_open.symbol = fnl.symbol
                                            JOIN stock_data so_close ON so_close.date = fnl.max_date AND so_close.symbol = fnl.symbol
                                            JOIN (
                                                SELECT 
                                                    symbol, 
                                                    MAX(date) AS max_date
                                                FROM stock_data
                                                GROUP BY symbol, strftime('%Y-%m-%W', date)
                                                ORDER BY max_date DESC
                                                LIMIT 500
                                            ) recent_weeks ON recent_weeks.symbol = fnl.symbol AND recent_weeks.max_date = fnl.max_date
                                            ORDER BY fnl.max_date ASC;

the data file is of sqlite
SKL_SAZEW_1911.zip

@hmuhdkamran hmuhdkamran added the bug Something isn't working label Apr 1, 2024
@DaveSkender DaveSkender added user support Help a user with their implementation and removed bug Something isn't working labels Apr 1, 2024
@DaveSkender
Copy link
Owner

DaveSkender commented Apr 1, 2024

This is a rather complex problem as I'm sure you're aware. Before I dig in to analyze further, given how often I've dealt with comparisons to TradingView charts, the root problem is most likely going to be one of these:

  1. An error in the TradingView chart that makes it a poor basis for checking accuracy of this library.
  2. The data you're using (or the output of your custom weekly aggregation SQL script) is different than what is used in that chart. They may start the week on a different day, for example.

See related know issues and common problems:

@DaveSkender
Copy link
Owner

DaveSkender commented Apr 1, 2024

I would normally recommend using our quotes.Aggregate(PeriodSize.Week) utility; however I think it uses a rolling 7-day week instead of a fixed week with a specific day (e.g. Saturday) as the end. I'm making a note to confirm that utility's behavior and to clarify our documentation.

@hmuhdkamran
Copy link
Author

// aggregate into larger bars
IEnumerable dayBarQuotes =
minuteBarQuotes.Aggregate(PeriodSize.Week); doesn't help at all,

If you look into my query, it get the closing of Friday, and min and max value in week, and open at Monday, the same formula is working for Monthly, but not for weekly.

@DaveSkender
Copy link
Owner

DaveSkender commented Apr 2, 2024

// aggregate into larger bars IEnumerable dayBarQuotes = minuteBarQuotes.Aggregate(PeriodSize.Week); doesn't help at all,

If you look into my query, it get the closing of Friday, and min and max value in week, and open at Monday, [ … ]

I expected this. Our week uses a rolling 7-day period with an arbitrary end day. I also noticed that SQL syntax (general observation) doesn't really have a windowed way to do FIRST or LAST easily. I was tempted to do some T-SQL-ing to see if there were a simpler version of your SQL query, because it's been a while since I've written queries like this (and looked like fun), but backed off after realizing its complexity. These days, I tend to prefer handling more complex data arrangements outside of the database.

I think I've found a fix for this Aggregate(...) utility problem, made notes in the related issue:

@DaveSkender DaveSkender moved this from Maybe to In Progress in Stock Indicators for .NET Apr 2, 2024
@DaveSkender DaveSkender moved this from In Progress to Do Next in Stock Indicators for .NET Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user support Help a user with their implementation
Projects
Development

No branches or pull requests

2 participants