Skip to content

Improve small candlestick rendering and support custom wick color - #803

Merged
swharden merged 5 commits into
ScottPlot:masterfrom
bclehmann:doji-candlestick
Feb 20, 2021
Merged

swharden merged 5 commits into
ScottPlot:masterfrom
bclehmann:doji-candlestick

Conversation

@bclehmann

Copy link
Copy Markdown
Member

New Contributors:
please review CONTRIBUTING.md

Purpose:
Fixes the drawing of "Doji" candlesticks (i.e. open == close) #800

New Functionality:
Adds a check for the Doji case and adds a red line where otherwise the candle body would not be drawn.

OHLC[] arr = DataGen.RandomStockPrices(new Random(0), 10);
arr[5] = new OHLC(arr[5].open, arr[5].high, arr[5].low, arr[5].open, arr[5].time); // Ensure a doji session exists

plt.AddCandlesticks(arr);

Before:
image

After:
image

@bclehmann

Copy link
Copy Markdown
Member Author

Currently the body of the candle is the colour passed into ColorDown (generally red), like the rest of the candlestick. I don't know if this is preferred, after all red implies that the price went down over the session, but the point of this PR is for when the price doesn't change. Perhaps someone with more interest in technical analysis can weigh in here.

@AlgoExecutor

Copy link
Copy Markdown

That is good point @bclehmann. Often the candle wick is kept neutral. Black is often used against a white background. Here is an example with different backgrounds:
image

You could also leave it up to the user by making this color configurable and overwriting the existing settings.
I would not discard the green/red wicks completely. Some people like that. If it would be controllable via options that would be great ;)

@bclehmann

Copy link
Copy Markdown
Member Author

image

I added a WickColor field which is by default System.Drawing.Color.LightGray. If SeparateWickColor is true then this colour is used instead of either ColorUp or ColorDown. This doesn't impact OHLCs at all.

Currently SeparateWickColor is true by default, which I leave to others to decide on which they think is better. I have not added a demo to illustrate the use of SeparateWickColor because if it gets changed to being off by default that demo would likely need to be changed to reflect that.

@bclehmann

bclehmann commented Feb 19, 2021 •

Copy link
Copy Markdown
Member Author

The grey wick is making me wonder if the candle bodies should have an outline?

I tried it and got this:
image

Perhaps LightGrey is too light, but I actually quite like this.

@AlgoExecutor

Copy link
Copy Markdown

Hi @bclehmann
thank you for the quick feedback. The wicks look good 👍 . Normally they are relatively dark. Super cool if you can customize them. The outline I would make optional or very thin? Looks like the MS chart outline was no bigger than 1 px? You can see it here #800 in the reference image. If it's not complicated, you could make it customizable as well ;)

@swharden swharden changed the title Candlesticks with open == close always have a pixel-height canlde Improve small candlestick rendering and support custom wick color Feb 20, 2021
now uses a nullable Color to determine if a custom wick color should be used
@swharden

Copy link
Copy Markdown
Member

Hey @bclehmann and @AlgoExecutor, thanks for your input on this one!

  • Default styling is designed to closely mimic https://www.tradingview.com/chart

  • Customizing the wick (and border) color was a great idea, but I struggled with how to best expose this. I'm typically against using nullable value types because they can be confusing, but I think they make sense here (compared to a separate bool flag variable, or a magic color like Transparent to indicate no border).

I added some new examples to the cookbook demonstrating what it can do.

finance_color

I'm worried I'm inviting chaos into the ScottPlot community with this one... but I made a demo designed to look like TC2000 😅 We'll see how much craziness it invites...

image

I love how this example shows a clear "consolidation period" and periods of "momentum", all resulting from a random number generator 😈

As a neuroscientist, I find the combination of chart reading and pattern hallucination fascinating.

Again I'm reminded of A Random Walk Down Wall Street

@swharden
swharden merged commit 2c62965 into ScottPlot:master Feb 20, 2021
@AlgoExecutor

Copy link
Copy Markdown

Thank you both @swharden and @bclehmann for the good work! I also had to laugh about the TC2000 chart 😂. Looks like chaos is really coming - love it ;-)

You make a really good point. Reading charts is some kind of art. You just have to believe in it hard enough. Always reminds me of the tea cup pattern: https://www.investopedia.com/terms/c/cupandhandle.asp

Looks like the inventor had a deeper meaning in mind 🙃

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.

3 participants