Need an example to use EMA on candlestick MS chart
I need to do real-time streaming data stock candlestick chart with EMA indicator.
Anyone has worked on this please post a sample code. I have created C# candlestick chart with no problem, but how to add EMA?
Developer technologies | C#
-
Daniel Zhang-MSFT • 9,656 Reputation points
2021-07-16T05:35:29.447+00:00 -
greg chu • 116 Reputation points
2021-07-16T16:36:41.497+00:00 Sorry, my question is not to calculate EMA, I think MS chart can have EMA on it, my question is how to add EMA to the candlestick chart. Any examples?
-
greg chu • 116 Reputation points
2021-07-16T16:45:23.37+00:00 Sorry, not how to calculate, I read somewhere saying I can add EMA to the candlestick chart, need a sample code ,
below is an old posting:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/af042a79-17db-4943-9d3e-a04a4403995b/candlestick-and-exponential-moving-average?forum=MSWinWebChart&prof=required -
Carsten Riedel • 11 Reputation points
2021-07-16T22:24:23.567+00:00 You need to paint the EMA in a new series of this chartarea.
.....this.Series.Add(seriesname);
List<decimal> values
this.Series[seriesname].ChartType = SeriesChartType.Line;
this.Series[seriesname].Points.Add(new System.Windows.Forms.DataVisualization.Charting.DataPoint() { YValues = new double[] { (double)values[i] }, IsEmpty = true, Color = Color.Red });
this.Series[seriesname].YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Single;And don't reinvent the wheel... take a look at... https://daveskender.github.io/Stock.Indicators/
-
greg chu • 116 Reputation points
2021-07-17T09:02:19.12+00:00 Looks like you have done what I needed before. Do you have a sample app that using Dave’s open source ? So I can download the project to help get started?
-
Carsten Riedel • 11 Reputation points
2021-07-18T06:53:13.65+00:00 Please take a look at my Attachment, created a sample for you.
Please accept the answer.115596-chart.txt
-
greg chu • 116 Reputation points
2021-07-19T03:37:43.38+00:00 Very nice of you, I will try and let you know if works, Really appreciate your help.
BTW, have you ever add Zoom in/out to MS chart? Also for real time steaming data, when data comes in, do you store it to a database and load data to chart or just update chart point by point in time when data coming in?
-
Carsten Riedel • 11 Reputation points
2021-07-19T04:54:31.43+00:00 Sorry never used Zoom, for streaming data I queried/initialized the candles from the data provider via REST API and updated the last candle from a websocket.
The reason was that the candle provider had some sort of delay before "its" candle REST API was updated, and that delay changed.
The decision whether to store data in a database depends on your purpose. For me that was an easy decision, if no live data is available it don't need to paint anything.This here will be usefull too if you update your chart frequently.
Basicly you need suspend-> Paint the updated series -> Resume.
[DllImport("user32.dll")] public static extern int SendMessage(IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam); private const int WM_SETREDRAW = 11; public static void SuspendDrawing(Control control) { SendMessage(control.Handle, WM_SETREDRAW, false, 0); } public static void ResumeDrawing(Control control) { SendMessage(control.Handle, WM_SETREDRAW, true, 0); control.Refresh(); }
-
greg chu • 116 Reputation points
2021-07-23T20:13:29.823+00:00 I see you are using the line below "DataVisualization:, which dotNet version are you using to create chart? I searched and found dotNet 5.0 does not support MS Chart control anymore, and there is a NuGet package for DataVisualization, and I downloaded the project and it was for dotNet 3
using System.Windows.Forms.DataVisualization.Charting;
-
Daniel Zhang-MSFT • 9,656 Reputation points
2021-07-30T01:40:45.343+00:00 -
greg chu • 116 Reputation points
2021-08-19T23:35:18.673+00:00 I created a .net Core 5 winform project and and install GitHub HIC.System.Windows.Forms.DataVisualization which is ported .net Core 5 DataVisualization, please see attached txt file which include the entire code. It compiled OK, but when I run and click on button the chart not showing up.
Please run and see what was wrong?
-
greg chu • 116 Reputation points
2021-08-20T01:55:02.347+00:00 Just need to add chart control to form to have chart show up. Tomorrow I will see EMA showed up on the chart.
-
greg chu • 116 Reputation points
2021-08-30T17:47:32.287+00:00 I will accept this reply as an answer, how do I accept this as an answer, not sure where to click?
-
Dave Skender • 1 Reputation point
2022-04-24T06:12:42.4+00:00 I have example usage code here:
https://daveskender.github.io/Stock.Indicators/examples/
Sign in to comment