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

Candlestick plotter #538

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open

Candlestick plotter #538

wants to merge 19 commits into from

Conversation

przmv
Copy link
Collaborator

@przmv przmv commented Jan 28, 2015

Candlestick chart with optional bars compression annually, quarterly, monthly, weekly or daily.

(function() {
"use strict";

Date.prototype.getWeek = function() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please not modify built-in objects.

@danvk
Copy link
Owner

danvk commented Mar 6, 2015

This is cool, but it could really benefit from some documentation. What assumptions does it make about the data?

@przmv
Copy link
Collaborator Author

przmv commented Mar 23, 2015

@danvk: This is cool, but it could really benefit from some documentation. What assumptions does it make about the data?

@danielkrizian could you please write some documentation for this plugin since you are more competent in this question. Thanks!

@danielkrizian
Copy link

What assumptions does it make about the data?

Candlesticks are traditional way of displaying price ranges as well as trend in which a financial stock traded during a day (or week, month, etc.), from the stock exchange open till close during the period, marking the highest and lowest price reached during that period and color-coding the trend.

The data argument is a table containing a date column and columns with names Open,High,Low and Close (case-insensitive, order doesn't matter). High value is always the highest of the four, Low value is always the lowest. If Close is higher than Open for that period, the candlestick will be green, otherwise it will be red.
Note that in order to keep the chart legible and not too clunky, the candlestick plotter algorithm will not necessarily plot one candlestick for each date in the data, but will attempt to compress the periodicity of the data so that only 20-50 candlesticks are displayed on each redraw ( @pshevtsov please confirm). For example, weekly candlestick is formed from daily data by treating Monday's Open as week's Open, Friday's Close as week's Close, the highest (lowest) of the daily Highs (Lows) as weekly High (Low) respectively.

image

http://en.wikipedia.org/wiki/Candlestick_chart#/media/File:Candlestick_chart_scheme_03-en.svg

@coveralls
Copy link

Coverage Status

Coverage remained the same at 90.97% when pulling f1069a5 on pshevtsov:candlestick-plotter into 57894b1 on danvk:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 90.97% when pulling fe2562e on pshevtsov:candlestick-plotter into 57894b1 on danvk:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 90.97% when pulling 06e4ae3 on pshevtsov:candlestick-plotter into 57894b1 on danvk:master.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7; IE=EmulateIE9">
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this—it's a relic of when dygraphs supported canvas emulation.

@danvk
Copy link
Owner

danvk commented Apr 21, 2015

I'd like to merge this. I have three comments which should be easy to address:

  1. Any reason to put the data handler in src/datahandlers rather than src/extras? I'd prefer the latter.
  2. The vertical lines would look crisper if you did the standard draw-on-half-pixel trick.
  3. You should include some documentation about assumptions, either in tests/candlestick.html or one of the JS files. For example, I'd like the documentation to include answers to the following questions:
    1. Does the candlestick plotter work require that you use the Compress data handler?
    2. Do the series have to be named in a particular way or appear in a particular order?

@coveralls
Copy link

Coverage Status

Coverage remained the same at 90.9% when pulling 1cc4cd6 on pshevtsov:candlestick-plotter into 9fc0dc8 on danvk:master.

@przmv
Copy link
Collaborator Author

przmv commented May 17, 2015

@danvk do you have any more questions or suggestions about this PR? Thanks!

@danvk
Copy link
Owner

danvk commented Oct 26, 2015

Sorry this has been pending for so long. I'll be happy to merge it if you guys add a unit test (e.g. in auto_tests). During my recent module refactor (see #674) I was reminded of the value of having unit tests, even for "extras".

@przmv
Copy link
Collaborator Author

przmv commented Nov 27, 2015

Hello @danvk !

I've changed the Candlestick plotter code to adapt using ES6 modules, added one more demo and created a couple of test cases. Hope it is good enough now to merge. Please let me know if you have any suggestions/notes.

Cheers

@przmv
Copy link
Collaborator Author

przmv commented Dec 27, 2015

@danvk any feedback of this PR? Thanks.

@przmv
Copy link
Collaborator Author

przmv commented Feb 26, 2016

If nobody has any objections, I'd like to merge this PR.

@algoquant
Copy link

@pshevtsov Do you have a simple example of R code for creating a candlestick plot using your branch of dygraphs?

@przmv
Copy link
Collaborator Author

przmv commented Sep 4, 2016

@algoquant Please check rstudio/dygraphs#128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants