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
Candlestick chart #81
Comments
Firstly, that looks pretty good!
|
Hi @ddovod. Thanks for the suggestion! This is actually the first time I've heard of a candlestick plot. Your implementation looks quite good! I'd rather avoid explicitly adding Now, I'm think we might could add a generic plotter such as: PlotRects(const char* label_id, const float* xs, const float* ys, const float* widths, const float* heights, ... ) This might seem a little strange, but it would enable you to create your own void PlotCandlestickChart(const char* label_id, const float* xs, const float* opens, const float* closes, const float* lows, const float* highs, int count, int offset, int stride) {
PlotErrorBars(label_id, ...); // render your highs/lows
PlotRects(label_id, ...); // render your open/closes
// these will appear as one series in the legend because they have the same label_id
} This would also open up the possibility of supporting box plots and could even replace the underlying implementation for The tricky party is doing the two colors like you have. You could pre-sort the data and do two passes, such that you'd have a green rising and red falling entry in the legend. I know this is not ideal, but I don't see an easier path forward right now. As @ChiefyChief23 said, time labels are being worked on. I've been dragging my feet merging @Prinkesh's PR, but hopefully I will get to it soon. Regarding hover, it's been requested for other plot types and ultimately I would like to provide a generic solution. It's not something I've had time to think about yet. It should be possible to do this outside of ImPlot's source yourself, using some of the built-in helper functions, though this would admittedly be a little cumbersome. Let me know your thoughts. |
heh, i have a similar todo issue open in uPlot [0] to extract generic bar/box distribution, sizing & drawing logic so it can be re-used for ohlc/candlesticks [1], box/whisker plots [2], bars [3] and x-aligned heatmaps [4]. will be interesting to see what you guys end up with :) my current thoughts are:
/highjack [0] leeoniya/uPlot#184 |
Thanks, Leon! I'll keep an eye on your progress as well. |
Yep, that's an option I'm thinking about, but it sounds limiting Hi @epezent
It would be great if you come up with some generic solution, but please keep in mind that the visual appearance of the whiskers on error bars and shadows on candles are different enough to not use one code to draw them (note the T-shaped parts of the error bars and I-shaped parts of the candle chart). But, again, generic and probably customizable solution would be awesome to have |
@epezent For generic-ness in order to get the CandleSticks we could over lay PlotRects over a new function called PlotStems. Plot stems could just be a vertical line and the declaration could be something similar to PlotStems(const char* label_id, const float* xs, const float* y_mins, const float* y_maxs, ... ); So this would effectively just draw a vertical line along a given x position between two y values. Which could also have a Horizontal version PlotStemsH so as well as being able to create CandleStick plots we could do plots similar to that below, thoughts? @ddovod It is kind of limiting. After sleeping on it I kind of had an idea, have you ever seen the progress spinners within imgui? Well using that idea instead of showing different characters within a sequence what if it showed a sequence of colours? Then there is no limiting factor? So the legend as time goes by would switch to the colours used to render the given line?? |
@ddovod , I had the same idea of using pie charts. The rendering code already exists for Regarding the stems, Actually, now that I look back at the Error Bars demo, it seems that you could in fact accomplish Candlesticks with the current API using only void PlotCandlestickChart(const char* label_id, const float* xs, const float* opens, const float* closes, const float* lows, const float* highs, int count, int offset, int stride) {
PushStyleVar(ImPlotStyleVar_ErrorBarSize,0); // no whiskers
PushStyleVar(ImPlotStyleVar_ErrorBarWeight,1); // thin error bar for high/low
PlotErrorBars(label_id, ...); // render your highs/lows
PushStyleVar(ImPlotStyleVar_ErrorBarWeight,10); // thick error bar for open/close
PlotErrorBars(label_id, ...); // render your open/closes
PopStyleVar(3);
} |
@ddovod, could you provide a test data set that I could play around with. Preferably formatted as float arrays that can be passed to the prototype function signature above. |
@epezent you can pull some OHLC data from my demo: i had to fake/random the volume bars since i could not find any reliable free source for daily gold volume. |
@epezent Sounds good, both subdivided rectangles and drawing candlesticks using error bars. I would like to have a separate function for candlesticks just for convenience to not force everybody make one in their code, this type of chart is widely used. |
@ddovod , I'll definitely consider it. This at least has me thinking about how we can extract common rendering patterns and expose those for users to implement their own custom plotters. |
@ddovod , I haven't decided whether or not candlesticks belong in the public API yet (I'm leaning toward no), but I did want you to know that I've added an example of creating a custom The two-tone legend icon still isn't resolved, and I'm still dragging on incorporating time formatted axes, but hopefully this is a step in the right direction. Let me know your thoughts. |
@ddovod , for fun I added an example of custom tooltips to the demo: |
@epezent Wow, looks great! Thanks a lot, I'll definitely take a look |
This site is worth checking out |
Sorry for posting here in this closed issue, but it seems to be the best fit instead of opening a new issue. (and first of all: thank you for the amazing library, just discovered it a week ago) For testing purposes I loaded a local CSV file with EURUSD M1 data. Is there any way to "just" skip the data gaps? |
@jahnf I know it's been over a year since this question, but did you find a solution? I have the exact same issue. |
@ddovod @epezent Sorry if this has already been answered, but how can I use this implementation of a candlestick chart with imgui? To be more specific, I plan on using a C# .NET wrapper around imgui called ImGui.NET. I find it unclear from reading whether or not candlestick charts are natively supported by implot, or if it's necessary to modify the implot code to achieve that. It would be nice to have both candlestick and line charts for representing price data for trading, whether it's stocks, crypto, forex or futures |
Hi. Thank you very much for such an amazing library!
Would you mind to implement a candlestick chart? It would be great to have a function with signature like
I have a very basic implementation which looks like this
The implementation is very straightforward and based on the error bars code, but I can share it here if you want.
Let me explain some problems I've faced here:
Please let me know if I can help somehow.
Thanks!
The text was updated successfully, but these errors were encountered: