Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to get Exponential Moving Average and show it in datagridview
by all index and by single index

thank you
Posted
Updated 20-Feb-15 14:13pm
v12
Comments
Tomas Takac 22-Dec-14 17:12pm    
First, you need to separate out the code that calculates the EMA form the code which displays it in the grid. Secondly, this is too complicated, I looked on Wikipedia and calculating EMA isn't that complicated, seems to be pretty straightforward actually.
Tomas Takac 23-Dec-14 4:22am    
I think I see your problem now, you want to calculate EMA for 3,5,...,100,200 days for each row, right? Well that's a lot of work, O(n^2) I believe. Anyway, you need to structure your code differently. First parse the input into a list of objects, then calculate EMA, then bind the resulting list to the grid. I'll be able to put that into an answer later on, but do not expect a complete solution from me or anybody else here.

1 solution

The main problem is that you operate on DataGridViewCells instead of data. I'd suggest to separate code for calculations from UI.

Steps to do:

  1. Create custom class[^], let's say: CEM with public fields (Item, Data, Close, Sma, Ema).
  2. Create List<CEM>[^] and provide method to load data into it.
  3. Sort[^] List<CEM> on Date field
  4. Calculate Sma and Ema fields. Use List<CEM> index[^] for calculations or use Linq[^] methods.
  5. Finally, load data into DataGridView


That's all. Try!
 
Share this answer
 
Comments
[no name] 23-Dec-14 9:51am    
+5 good advices.
Bruno

Sorry I need to add this:
"Calculating Exponential Moving Average from comma text file". Is it different from "Calculating Exponential Moving Average from excel file" or any datasource....?
Maciej Los 23-Dec-14 10:57am    
Thank you, Bruno.
The type of data source is not important (Excel, comma separated file, binary file, etc.). It's quite simple for implementation.
[no name] 23-Dec-14 11:05am    
that was my intention to express ;)
Maciej Los 24-Dec-14 2:38am    
Explain what?
Link is broken and moves to this question.
myproject235 24-Dec-14 3:02am    
Calculating Exponential Moving Average in excel

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900