public override void Update(Subject subject)
        {
            StockReader sr = subject as StockReader;

            Console.WriteLine("Open  Price:" + sr.Open.ToString());
            Console.WriteLine("High  Price:" + sr.High.ToString());
            Console.WriteLine("Low   Price:" + sr.Low.ToString());
            Console.WriteLine("Close Price:" + sr.Close.ToString());
        }
        static void Main(string[] args)
        {
            StockReader       sr      = new StockReader();
            DisplayStockPrice display = new DisplayStockPrice();
            MovingAverage     sma20   = new MovingAverage(20);

            sr.Attach(display);
            sr.Attach(sma20);
            sr.StartRead("stock.csv");
        }
Ejemplo n.º 3
0
        public override void Update(Subject subject)
        {
            StockReader sr = subject as StockReader;

            if (count == Periods)
            {
                count = 0;
            }
            if (filled)
            {
                values[count] = sr.Close;
                Console.WriteLine($"Moving Average({Periods}) :{values.Average()}");
            }
            else
            {
                if (count == Periods - 1)
                {
                    filled = true;
                }
                values[count] = sr.Close;
            }
            count++;
        }