Wednesday, September 21, 2011

See stock on your screen.

Preface

I think that if you intrested in stock trading , and you want to see the graph of you favorite stock,
you will like this blog for sure !


Please see the GUI of our next program.
We will build a program that will display a stock data. In the progran you will enter Ticker Name, From Date, End Date and the program display the data in a graph.We will use  Yahoo download component  that I posted in other blog.




Desing

As every good design we will start with UML


As we see in the picture we defined an Interface that called "ZedGraph" . Zedgraph expose common properties of our Graph object . Please see below several of them :
  • Description - A description of what this demo is showing.
  • Title - Graph Title
Than we will define base graph "BaseGraph" for all stock graphes. The class is abstract so no one can instance it. The class is implemented the interface that we created above so he must impement
properties that we defined in interface. The main public function of the class is "AddLine" . The function
know how to display the data in the graph.

In order to show the data we must created a class that will be inherited from the base.
So we will create class "SingleGraph". The graph will inherit from "BaseGraph" and the class will be responsible for charting.

In our window form class in order to show the graph we will implement following code

     YahooHistoryDownloader yahoo = new YahooHistoryDownloader();
            List<StockDownloader.Bar> list = yahoo.GetBarHistory(stockName, from, toDate);
            if (list.Count > 0)
            {
                singleGraph.ClearGraph();
                singleGraph.AddLine(singleGraph.GraphPane, list, Action.Add, Color.Red, stockName);
                singleGraph.ZedGraphControl.AxisChange();
                singleGraph.ZedGraphControl.Refresh();


Our task is complete I prepare for you code that you can play with it .


Code can be downloaded from this location.

Summary

We wanted to see the stock data and see how our stock do today.
So we created simple design how to do it and implement it as window form.
In my next blogs we will define stock with indicator, so it will be other graph type and
more intresting.

    No comments:

    Post a Comment