private void btn_Save(object sender, RoutedEventArgs e)
 {
     if (tb_OpeningBalance.Text == "" || tb_Sale.Text == "" || tb_Delivery.Text == "" || tb_TotalSale.Text == "" || tb_TotalCash.Text == "" || tb_Deposit.Text == "" || tb_Expence.Text == "" || tb_ClosingBalance.Text == "")
     {
         AutoClosingMessageBox.Show("Please Fill all fields", "Alert", 2000);
     }
     else
     {
         try
         {
             tbl_FinanceChart fc = new tbl_FinanceChart();
             fc.Date           = DateTime.Now;
             fc.OpeningBalance = Convert.ToInt32(tb_OpeningBalance.Text);
             fc.Sale           = Convert.ToInt32(tb_Sale.Text);
             fc.Delivery       = Convert.ToInt32(tb_Delivery.Text);
             fc.TotalSale      = Convert.ToInt32(tb_TotalSale.Text);
             fc.TotalCash      = Convert.ToInt32(tb_TotalCash.Text);
             fc.Deposit        = Convert.ToInt32(tb_Deposit.Text);
             fc.Expence        = Convert.ToInt32(tb_Expence.Text);
             fc.ClosingBalance = Convert.ToInt32(tb_ClosingBalance.Text);
             FinanceChart.insert(fc);
             Close();
             AutoClosingMessageBox.Show("Closings saved", "Success", 2000);
         }
         catch
         {
             AutoClosingMessageBox.Show("Please try again", "Fail", 2000);
         }
     }
 }
Exemple #2
0
 void initFormOperations()
 {
     foreach (tbl_FinanceChart item in FinanceChart.getAll())
     {
         dg_FinanceChart.Items.Add(item);
     }
     lbl_TotalSale.Content    = Sale.getAllTotalAmmount();
     lbl_TotalDeposit.Content = FinanceChart.getTotalDeposit();
     lbl_TotalExpence.Content = Expence.getAllTotalAmmount();
 }
Exemple #3
0
        private void btn_CustomDateSearch(object sender, RoutedEventArgs e)
        {
            if (dp_from.SelectedDate != null && dp_to.SelectedDate != null)
            {
                DateTime tempFromDate = Convert.ToDateTime(dp_from.SelectedDate);
                DateTime tempToDate   = Convert.ToDateTime(dp_to.SelectedDate);

                DateTime fromDate = Convert.ToDateTime(tempFromDate.ToShortDateString() + " 12:00:00 AM");
                DateTime toDate   = Convert.ToDateTime(tempToDate.ToShortDateString() + " 11:59:59 PM");
                dg_FinanceChart.Items.Clear();
                foreach (tbl_FinanceChart item in FinanceChart.getAllCustomDate(fromDate, toDate))
                {
                    dg_FinanceChart.Items.Add(item);
                }
            }
        }
 void initFormOperations()
 {
     try
     {
         tb_OpeningBalance.Text = Convert.ToString(FinanceChart.getLastDayClosingBalance());
         dp_Date.Content        = DateTime.Now.ToShortDateString();
         tb_Sale.Text           = Convert.ToString(Sale.getAllTodayOnRestaurentAmmount());
         tb_Delivery.Text       = Convert.ToString(Sale.getAllTodayOnDeliveryAmmount());
         tb_TotalSale.Text      = Convert.ToString(Sale.getAllTodayOnRestaurentAmmount() + Sale.getAllTodayOnDeliveryAmmount());
         tb_TotalCash.Text      = Convert.ToString(FinanceChart.getLastDayClosingBalance() + Sale.getAllTodayOnRestaurentAmmount() + Sale.getAllTodayOnDeliveryAmmount());
         tb_Expence.Text        = Convert.ToString(Expence.getTodayTotalAmmount());
         tb_Deposit.Text        = Convert.ToString(Deposit.getAllTodayAmmount());
         int deposit        = Convert.ToInt32(tb_Deposit.Text);
         int ClosingBalance = FinanceChart.getLastDayClosingBalance() + Sale.getAllTodayOnRestaurentAmmount() + Sale.getAllTodayOnDeliveryAmmount() - Expence.getTodayTotalAmmount() - deposit;
         tb_ClosingBalance.Text = Convert.ToString(ClosingBalance);
     } catch {}
 }
 /// <summary>
 /// Add a moving average line to the FinanceChart object.
 /// </summary>
 /// <param name="m">The FinanceChart object to add the line to.</param>
 /// <param name="avgType">The moving average type (SMA/EMA/TMA/WMA).</param>
 /// <param name="avgPeriod">The moving average period.</param>
 /// <param name="color">The color of the line.</param>
 /// <returns>The LineLayer object representing line layer created.</returns>
 protected LineLayer addMovingAvg(FinanceChart m, string avgType, int avgPeriod, int color)
 {
     if (avgPeriod > 1)
     {
         if (avgType == "SMA")
         {
             return(m.addSimpleMovingAvg(avgPeriod, color));
         }
         else if (avgType == "EMA")
         {
             return(m.addExpMovingAvg(avgPeriod, color));
         }
         else if (avgType == "TMA")
         {
             return(m.addTriMovingAvg(avgPeriod, color));
         }
         else if (avgType == "WMA")
         {
             return(m.addWeightedMovingAvg(avgPeriod, color));
         }
     }
     return(null);
 }
        //
        // Create chart
        //
        private void createChart(RazorChartViewer viewer)
        {
            // Create a finance chart demo containing 100 days of data
            int noOfDays = 100;

            // To compute moving averages starting from the first day, we need to get extra data points
            // before the first day
            int extraDays = 30;

            // In this exammple, we use a random number generator utility to simulate the data. We set up
            // the random table to create 6 cols x (noOfDays + extraDays) rows, using 9 as the seed.
            RanTable rantable = new RanTable(9, 6, noOfDays + extraDays);

            // Set the 1st col to be the timeStamp, starting from Sep 4, 2002, with each row representing
            // one day, and counting week days only (jump over Sat and Sun)
            rantable.setDateCol(0, new DateTime(2002, 9, 4), 86400, true);

            // Set the 2nd, 3rd, 4th and 5th columns to be high, low, open and close data. The open value
            // starts from 100, and the daily change is random from -5 to 5.
            rantable.setHLOCCols(1, 100, -5, 5);

            // Set the 6th column as the vol data from 5 to 25 million
            rantable.setCol(5, 50000000, 250000000);

            // Now we read the data from the table into arrays
            double[] timeStamps = rantable.getCol(0);
            double[] highData   = rantable.getCol(1);
            double[] lowData    = rantable.getCol(2);
            double[] openData   = rantable.getCol(3);
            double[] closeData  = rantable.getCol(4);
            double[] volData    = rantable.getCol(5);

            // Create a FinanceChart object of width 640 pixels
            FinanceChart c = new FinanceChart(640);

            // Add a title to the chart
            c.addTitle("Finance Chart Demonstration");

            // Set the data into the finance chart object
            c.setData(timeStamps, highData, lowData, openData, closeData, volData, extraDays);

            // Add a slow stochastic chart (75 pixels high) with %K = 14 and %D = 3
            c.addSlowStochastic(75, 14, 3, 0x006060, 0x606000);

            // Add the main chart with 240 pixels in height
            c.addMainChart(240);

            // Add a 10 period simple moving average to the main chart, using brown color
            c.addSimpleMovingAvg(10, 0x663300);

            // Add a 20 period simple moving average to the main chart, using purple color
            c.addSimpleMovingAvg(20, 0x9900ff);

            // Add candlestick symbols to the main chart, using green/red for up/down days
            c.addCandleStick(0x00ff00, 0xff0000);

            // Add 20 days donchian channel to the main chart, using light blue (9999ff) as the border
            // and semi-transparent blue (c06666ff) as the fill color
            c.addDonchianChannel(20, 0x9999ff, unchecked ((int)0xc06666ff));

            // Add a 75 pixels volume bars sub-chart to the bottom of the main chart, using
            // green/red/grey for up/down/flat days
            c.addVolBars(75, 0x99ff99, 0xff9999, 0x808080);

            // Append a MACD(26, 12) indicator chart (75 pixels high) after the main chart, using 9 days
            // for computing divergence.
            c.addMACD(75, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000);

            // Output the chart
            viewer.Image = c.makeWebImage(Chart.PNG);
        }
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WPFChartViewer viewer, int chartIndex)
        {
            // Create a finance chart demo containing 100 days of data
            int noOfDays = 100;

            // To compute moving averages starting from the first day, we need to get extra data
            // points before the first day
            int extraDays = 30;

            // In this exammple, we use a random number generator utility to simulate the data. We
            // set up the random table to create 6 cols x (noOfDays + extraDays) rows, using 9 as
            // the seed.
            RanTable rantable = new RanTable(9, 6, noOfDays + extraDays);

            // Set the 1st col to be the timeStamp, starting from Sep 4, 2014, with each row
            // representing one day, and counting week days only (jump over Sat and Sun)
            rantable.setDateCol(0, new DateTime(2014, 9, 4), 86400, true);

            // Set the 2nd, 3rd, 4th and 5th columns to be high, low, open and close data. The open
            // value starts from 100, and the daily change is random from -5 to 5.
            rantable.setHLOCCols(1, 100, -5, 5);

            // Set the 6th column as the vol data from 5 to 25 million
            rantable.setCol(5, 50000000, 250000000);

            // Now we read the data from the table into arrays
            double[] timeStamps = rantable.getCol(0);
            double[] highData   = rantable.getCol(1);
            double[] lowData    = rantable.getCol(2);
            double[] openData   = rantable.getCol(3);
            double[] closeData  = rantable.getCol(4);
            double[] volData    = rantable.getCol(5);

            // Custom data series should be of the same length as the OHLC data series
            double[] buySignal  = new double[closeData.Length];
            double[] sellSignal = new double[closeData.Length];

            //
            // The following is just an arbitrary algorithm to create some meaningless buySignal and
            // sellSignal. They are just for demonstrating the charting engine. Please do not use
            // them for actual trading.
            //

            double[] sma5  = new ArrayMath(closeData).movAvg(5).result();
            double[] sma20 = new ArrayMath(closeData).movAvg(20).result();

            for (int i = 0; i < sma5.Length; ++i)
            {
                buySignal[i]  = Chart.NoValue;
                sellSignal[i] = Chart.NoValue;
                if (i > 0)
                {
                    if ((sma5[i - 1] <= sma20[i - 1]) && (sma5[i] > sma20[i]))
                    {
                        buySignal[i] = lowData[i];
                    }
                    if ((sma5[i - 1] >= sma20[i - 1]) && (sma5[i] < sma20[i]))
                    {
                        sellSignal[i] = highData[i];
                    }
                }
            }

            // Create a FinanceChart object of width 640 pixels
            FinanceChart c = new FinanceChart(640);

            // Add a title to the chart
            c.addTitle("Finance Chart with Custom Symbols");

            // Set the data into the finance chart object
            c.setData(timeStamps, highData, lowData, openData, closeData, volData, extraDays);

            // Add the main chart with 240 pixels in height
            XYChart mainChart = c.addMainChart(240);

            // Add buy signal symbols to the main chart, using cyan (0x00ffff) upward pointing
            // arrows as symbols
            ScatterLayer buyLayer = mainChart.addScatterLayer(null, buySignal, "Buy",
                                                              Chart.ArrowShape(0, 1, 0.4, 0.4), 11, 0x00ffff);

            // Shift the symbol lower by 20 pixels
            buyLayer.getDataSet(0).setSymbolOffset(0, 20);

            // Add sell signal symbols to the main chart, using purple (0x9900cc) downward pointing
            // arrows as symbols
            ScatterLayer sellLayer = mainChart.addScatterLayer(null, sellSignal, "Sell",
                                                               Chart.ArrowShape(180, 1, 0.4, 0.4), 11, 0x9900cc);

            // Shift the symbol higher by 20 pixels
            sellLayer.getDataSet(0).setSymbolOffset(0, -20);

            // Add a 5 period simple moving average to the main chart, using brown color
            c.addSimpleMovingAvg(5, 0x663300);

            // Add a 20 period simple moving average to the main chart, using purple color
            c.addSimpleMovingAvg(20, 0x9900ff);

            // Add candlestick symbols to the main chart, using green/red for up/down days
            c.addCandleStick(0x66ff66, 0xff6666);

            // Add a volume indicator chart (75 pixels high) after the main chart, using
            // green/red/grey for up/down/flat days
            c.addVolIndicator(75, 0x99ff99, 0xff9999, 0x808080);

            // Append a 14-days RSI indicator chart (75 pixels high) after the main chart. The main
            // RSI line is purple (800080). Set threshold region to +/- 20 (that is, RSI = 50 +/-
            // 25). The upper/lower threshold regions will be filled with red (ff0000)/blue
            // (0000ff).
            c.addRSI(75, 14, 0x800080, 20, 0xff0000, 0x0000ff);

            // Output the chart
            viewer.Chart = c;
        }
Exemple #8
0
        //Main code for creating chart.
        //Note: the argument chartIndex is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer viewer, int chartIndex)
        {
            // Create a finance chart demo containing 100 days of data
            int noOfDays = 100;

            // To compute moving averages starting from the first day, we need to get extra data
            // points before the first day
            int extraDays = 30;

            // In this exammple, we use a random number generator utility to simulate the data. We
            // set up the random table to create 6 cols x (noOfDays + extraDays) rows, using 9 as
            // the seed.
            RanTable rantable = new RanTable(9, 6, noOfDays + extraDays);

            // Set the 1st col to be the timeStamp, starting from Sep 4, 2002, with each row
            // representing one day, and counting week days only (jump over Sat and Sun)
            rantable.setDateCol(0, new DateTime(2002, 9, 4), 86400, true);

            // Set the 2nd, 3rd, 4th and 5th columns to be high, low, open and close data. The open
            // value starts from 100, and the daily change is random from -5 to 5.
            rantable.setHLOCCols(1, 100, -5, 5);

            // Set the 6th column as the vol data from 5 to 25 million
            rantable.setCol(5, 50000000, 250000000);

            // Now we read the data from the table into arrays
            double[] timeStamps = rantable.getCol(0);
            double[] highData   = rantable.getCol(1);
            double[] lowData    = rantable.getCol(2);
            double[] openData   = rantable.getCol(3);
            double[] closeData  = rantable.getCol(4);
            double[] volData    = rantable.getCol(5);

            // Create a FinanceChart object of width 640 pixels
            FinanceChart c = new FinanceChart(640);

            // Add a title to the chart
            c.addTitle("Finance Chart Demonstration");

            // Set the data into the finance chart object
            c.setData(timeStamps, highData, lowData, openData, closeData, volData, extraDays);

            // Add the main chart with 240 pixels in height
            c.addMainChart(240);

            // Add a 5 period simple moving average to the main chart, using brown color
            c.addSimpleMovingAvg(5, 0x663300);

            // Add a 20 period simple moving average to the main chart, using purple color
            c.addSimpleMovingAvg(20, 0x9900ff);

            // Add HLOC symbols to the main chart, using green/red for up/down days
            c.addHLOC(0x008000, 0xcc0000);

            // Add 20 days bollinger band to the main chart, using light blue (9999ff) as the border
            // and semi-transparent blue (c06666ff) as the fill color
            c.addBollingerBand(20, 2, 0x9999ff, unchecked ((int)0xc06666ff));

            // Add a 75 pixels volume bars sub-chart to the bottom of the main chart, using
            // green/red/grey for up/down/flat days
            c.addVolBars(75, 0x99ff99, 0xff9999, 0x808080);

            // Append a 14-days RSI indicator chart (75 pixels high) after the main chart. The main
            // RSI line is purple (800080). Set threshold region to +/- 20 (that is, RSI = 50 +/-
            // 25). The upper/lower threshold regions will be filled with red (ff0000)/blue
            // (0000ff).
            c.addRSI(75, 14, 0x800080, 20, 0xff0000, 0x0000ff);

            // Append a 12-days momentum indicator chart (75 pixels high) using blue (0000ff) color.
            c.addMomentum(75, 12, 0x0000ff);

            // Output the chart
            viewer.Chart = c;
        }
Exemple #9
0
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer WebChartViewer1, string img, int stockId, int timeFrameId, DateTime fromDt, DateTime toDt, int ballSize, int chartWidth, int chartHeighth, int priceType)
        {
            var stock = (from s in dataContext.stocks
                         where s.id == stockId
                         select s).FirstOrDefault();

            var timeFrame = (from t in dataContext.timeframes
                             where t.id == timeFrameId
                             select t).FirstOrDefault();

            if (timeFrame == null)
            {
                errMsg(WebChartViewer1, "Тайм фрейм отсутствуют");
                return;
            }

            var stockQuotes = from sq in dataContext.settingquotes
                              where sq.stock == stock.id &&
                              sq.datetime >= fromDt &&
                              sq.datetime <= toDt.AddDays(1) &&
                              sq.timeframe == timeFrameId &&
                              sq.numcontractsclose != 0
                              orderby sq.datetime ascending
                              select sq;

            if (stockQuotes == null || stockQuotes.Count() == 0)
            {
                errMsg(WebChartViewer1, "Данные отсутствуют");
                return;
            }

            // To compute moving averages starting from the first day, we need to get
            // extra data points before the first day
            int extraDays = 0;

            getDailyData(WebChartViewer1, stockId, timeFrameId, fromDt, toDt);


            // Create a FinanceChart object of width 640 pixels
            FinanceChart c = new FinanceChart(chartWidth);

            c.setDateLabelFormat("{value|yyyy}",
                                 "<*font=bold*>{value|mm yy}",
                                 "{value|mm/yy}",
                                 "<*font=bold*>{value|d/mm}",
                                 "{value|d}",
                                 "<*font=bold*>{value|d/mm<*br*>h:nn}",
                                 "{value|h:nn}");
            //c.setNumberLabelFormat("{={value}/1000}");


            // Add a title to the chart using 18 pts Times Bold Itatic font.
            c.addTitle("Num contracts open positions " + stock.ticker + " " + timeFrame.timeframename + " ", "Times New Roman", 12);

            // Set the data into the finance chart object
            c.setData(timeStamps, highData, lowData, openData, closeData, volData,
                      extraDays);

            // Add the main chart with 240 pixels in height
            c.addMainChart(chartHeighth - 100);

            // Add an HLOC symbols to the main chart, using green/red for up/down
            // days
            c.addCandleStick(0x00ff00, 0xff0000);

            c.setAxisOnRight(true);


            // Output the chart
            WebChartViewer1.Image = c.makeImage();
        }
 /// <summary>
 /// Add an indicator chart to the FinanceChart object. In this demo example, the indicator
 /// parameters (such as the period used to compute RSI, colors of the lines, etc.) are hard
 /// coded to commonly used values. You are welcome to design a more complex user interface
 /// to allow users to set the parameters.
 /// </summary>
 /// <param name="m">The FinanceChart object to add the line to.</param>
 /// <param name="indicator">The selected indicator.</param>
 /// <param name="height">Height of the chart in pixels</param>
 /// <returns>The XYChart object representing indicator chart.</returns>
 protected XYChart addIndicator(FinanceChart m, string indicator, int height)
 {
     if (indicator == "RSI")
     {
         return(m.addRSI(height, 14, 0x800080, 20, 0xff6666, 0x6666ff));
     }
     else if (indicator == "StochRSI")
     {
         return(m.addStochRSI(height, 14, 0x800080, 30, 0xff6666, 0x6666ff));
     }
     else if (indicator == "MACD")
     {
         return(m.addMACD(height, 26, 12, 9, 0xff, 0xff00ff, 0x8000));
     }
     else if (indicator == "FStoch")
     {
         return(m.addFastStochastic(height, 14, 3, 0x6060, 0x606000));
     }
     else if (indicator == "SStoch")
     {
         return(m.addSlowStochastic(height, 14, 3, 0x6060, 0x606000));
     }
     else if (indicator == "ATR")
     {
         return(m.addATR(height, 14, 0x808080, 0xff));
     }
     else if (indicator == "ADX")
     {
         return(m.addADX(height, 14, 0x8000, 0x800000, 0x80));
     }
     else if (indicator == "DCW")
     {
         return(m.addDonchianWidth(height, 20, 0xff));
     }
     else if (indicator == "BBW")
     {
         return(m.addBollingerWidth(height, 20, 2, 0xff));
     }
     else if (indicator == "DPO")
     {
         return(m.addDPO(height, 20, 0xff));
     }
     else if (indicator == "PVT")
     {
         return(m.addPVT(height, 0xff));
     }
     else if (indicator == "Momentum")
     {
         return(m.addMomentum(height, 12, 0xff));
     }
     else if (indicator == "Performance")
     {
         return(m.addPerformance(height, 0xff));
     }
     else if (indicator == "ROC")
     {
         return(m.addROC(height, 12, 0xff));
     }
     else if (indicator == "OBV")
     {
         return(m.addOBV(height, 0xff));
     }
     else if (indicator == "AccDist")
     {
         return(m.addAccDist(height, 0xff));
     }
     else if (indicator == "CLV")
     {
         return(m.addCLV(height, 0xff));
     }
     else if (indicator == "WilliamR")
     {
         return(m.addWilliamR(height, 14, 0x800080, 30, 0xff6666, 0x6666ff));
     }
     else if (indicator == "Aroon")
     {
         return(m.addAroon(height, 14, 0x339933, 0x333399));
     }
     else if (indicator == "AroonOsc")
     {
         return(m.addAroonOsc(height, 14, 0xff));
     }
     else if (indicator == "CCI")
     {
         return(m.addCCI(height, 20, 0x800080, 100, 0xff6666, 0x6666ff));
     }
     else if (indicator == "EMV")
     {
         return(m.addEaseOfMovement(height, 9, 0x6060, 0x606000));
     }
     else if (indicator == "MDX")
     {
         return(m.addMassIndex(height, 0x800080, 0xff6666, 0x6666ff));
     }
     else if (indicator == "CVolatility")
     {
         return(m.addChaikinVolatility(height, 10, 10, 0xff));
     }
     else if (indicator == "COscillator")
     {
         return(m.addChaikinOscillator(height, 0xff));
     }
     else if (indicator == "CMF")
     {
         return(m.addChaikinMoneyFlow(height, 21, 0x8000));
     }
     else if (indicator == "NVI")
     {
         return(m.addNVI(height, 255, 0xff, 0x883333));
     }
     else if (indicator == "PVI")
     {
         return(m.addPVI(height, 255, 0xff, 0x883333));
     }
     else if (indicator == "MFI")
     {
         return(m.addMFI(height, 14, 0x800080, 30, 0xff6666, 0x6666ff));
     }
     else if (indicator == "PVO")
     {
         return(m.addPVO(height, 26, 12, 9, 0xff, 0xff00ff, 0x8000));
     }
     else if (indicator == "PPO")
     {
         return(m.addPPO(height, 26, 12, 9, 0xff, 0xff00ff, 0x8000));
     }
     else if (indicator == "UO")
     {
         return(m.addUltimateOscillator(height, 7, 14, 28, 0x800080, 20, 0xff6666, 0x6666ff));
     }
     else if (indicator == "Vol")
     {
         return(m.addVolIndicator(height, 0x99ff99, 0xff9999, 0xc0c0c0));
     }
     else if (indicator == "TRIX")
     {
         return(m.addTRIX(height, 12, 0xff));
     }
     return(null);
 }
        /// <summary>
        /// Draw the chart according to user selection and display it in the WPFChartViewer.
        /// </summary>
        /// <param name="viewer">The WPFChartViewer object to display the chart.</param>
        private void drawChart(WPFChartViewer viewer)
        {
            // Use InvariantCulture to draw the chart. This ensures the chart will look the
            // same on any computer.
            System.Threading.Thread.CurrentThread.CurrentCulture =
                System.Globalization.CultureInfo.InvariantCulture;

            // In this demo, we just assume we plot up to the latest time. So endDate is now.
            DateTime endDate = DateTime.Now;

            // If the trading day has not yet started (before 9:30am), or if the end date is
            // on on Sat or Sun, we set the end date to 4:00pm of the last trading day
            while ((endDate.TimeOfDay.CompareTo(new TimeSpan(9, 30, 0)) < 0) || (
                       endDate.DayOfWeek == DayOfWeek.Sunday) || (endDate.DayOfWeek ==
                                                                  DayOfWeek.Saturday))
            {
                endDate = endDate.Date.AddDays(-1).Add(new TimeSpan(16, 0, 0));
            }

            // The duration selected by the user
            int durationInDays = int.Parse(((ListItem)timeRange.SelectedItem).Key);

            // Compute the start date by subtracting the duration from the end date.
            DateTime startDate;

            if (durationInDays >= 30)
            {
                // More or equal to 30 days - so we use months as the unit
                startDate = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(
                    -durationInDays / 30);
            }
            else
            {
                // Less than 30 days - use day as the unit. Note that we use trading days
                // below. For less than 30 days, the starting point of the axis is always at
                // the start of the day.
                startDate = endDate.Date;
                for (int i = 1; i < durationInDays; ++i)
                {
                    startDate = startDate.AddDays(
                        (startDate.DayOfWeek == DayOfWeek.Monday) ? -3 : -1);
                }
            }

            // The first moving average period selected by the user.
            int avgPeriod1;

            try { avgPeriod1 = int.Parse(movAvg1.Text); }
            catch { avgPeriod1 = 0; }
            avgPeriod1 = Math.Max(0, Math.Min(300, avgPeriod1));

            // The second moving average period selected by the user.
            int avgPeriod2;

            try { avgPeriod2 = int.Parse(movAvg2.Text); }
            catch { avgPeriod2 = 0; }
            avgPeriod2 = Math.Max(0, Math.Min(300, avgPeriod2));

            // We need extra leading data points in order to compute moving averages.
            int extraPoints = Math.Max(20, Math.Max(avgPeriod1, avgPeriod2));

            // Get the data series to compare with, if any.
            compareKey  = compareWith.Text.Trim();
            compareData = null;
            if (getData(compareKey, startDate, endDate, durationInDays, extraPoints))
            {
                compareData = closeData;
            }

            // The data series we want to get.
            tickerKey = tickerSymbol.Text.Trim();
            if (!getData(tickerKey, startDate, endDate, durationInDays, extraPoints))
            {
                errMsg(viewer, "Please enter a valid ticker symbol");
                return;
            }

            // We now confirm the actual number of extra points (data points that are before
            // the start date) as inferred using actual data from the database.
            extraPoints = timeStamps.Length;
            for (int i = 0; i < timeStamps.Length; ++i)
            {
                if (timeStamps[i] >= startDate)
                {
                    extraPoints = i;
                    break;
                }
            }

            // Check if there is any valid data
            if (extraPoints >= timeStamps.Length)
            {
                // No data - just display the no data message.
                errMsg(viewer, "No data available for the specified time period");
                return;
            }

            // In some finance chart presentation style, even if the data for the latest day
            // is not fully available, the axis for the entire day will still be drawn, where
            // no data will appear near the end of the axis.
            if (resolution < 86400)
            {
                // Add extra points to the axis until it reaches the end of the day. The end
                // of day is assumed to be 4:00pm (it depends on the stock exchange).
                DateTime lastTime            = timeStamps[timeStamps.Length - 1];
                int      extraTrailingPoints = (int)(new TimeSpan(16, 0, 0).Subtract(
                                                         lastTime.TimeOfDay).TotalSeconds / resolution);

                if (extraTrailingPoints > 0)
                {
                    DateTime[] extendedTimeStamps = new DateTime[timeStamps.Length +
                                                                 extraTrailingPoints];
                    Array.Copy(timeStamps, 0, extendedTimeStamps, 0, timeStamps.Length);
                    for (int i = 0; i < extraTrailingPoints; ++i)
                    {
                        extendedTimeStamps[i + timeStamps.Length] = lastTime.AddSeconds(
                            resolution * i);
                    }
                    timeStamps = extendedTimeStamps;
                }
            }

            //
            // At this stage, all data is available. We can draw the chart as according to
            // user input.
            //

            //
            // Determine the chart size. In this demo, user can select 4 different chart
            // sizes. Default is the large chart size.
            //
            int width           = 780;
            int mainHeight      = 255;
            int indicatorHeight = 80;

            string selectedSize = ((ListItem)chartSize.SelectedItem).Key;

            if (selectedSize == "S")
            {
                // Small chart size
                width           = 450;
                mainHeight      = 160;
                indicatorHeight = 60;
            }
            else if (selectedSize == "M")
            {
                // Medium chart size
                width           = 620;
                mainHeight      = 215;
                indicatorHeight = 70;
            }
            else if (selectedSize == "H")
            {
                // Huge chart size
                width           = 1000;
                mainHeight      = 320;
                indicatorHeight = 90;
            }

            // Create the chart object using the selected size
            FinanceChart m = new FinanceChart(width);

            // Set the data into the chart object
            m.setData(timeStamps, highData, lowData, openData, closeData, volData, extraPoints);

            //
            // We configure the title of the chart. In this demo chart design, we put the
            // company name as the top line of the title with left alignment.
            //
            m.addPlotAreaTitle(Chart.TopLeft, tickerKey);

            // We displays the current date as well as the data resolution on the next line.
            string resolutionText = "";

            if (resolution == 30 * 86400)
            {
                resolutionText = "Monthly";
            }
            else if (resolution == 7 * 86400)
            {
                resolutionText = "Weekly";
            }
            else if (resolution == 86400)
            {
                resolutionText = "Daily";
            }
            else if (resolution == 900)
            {
                resolutionText = "15-min";
            }

            m.addPlotAreaTitle(Chart.BottomLeft, "<*font=Arial,size=8*>" + m.formatValue(
                                   DateTime.Now, "mmm dd, yyyy") + " - " + resolutionText + " chart");

            // A copyright message at the bottom left corner the title area
            m.addPlotAreaTitle(Chart.BottomRight,
                               "<*font=arial.ttf,size=8*>(c) Advanced Software Engineering");

            //
            // Add the first techical indicator according. In this demo, we draw the first
            // indicator on top of the main chart.
            //
            addIndicator(m, ((ListItem)indicator1.SelectedItem).Key, indicatorHeight);

            //
            // Add the main chart
            //
            m.addMainChart(mainHeight);

            //
            // Set log or linear scale according to user preference
            //
            m.setLogScale(logScale.IsChecked.GetValueOrDefault());

            //
            // Set axis labels to show data values or percentage change to user preference
            //
            if (percentageScale.IsChecked.GetValueOrDefault())
            {
                m.setPercentageAxis();
            }

            //
            // Draw any price line the user has selected
            //
            string mainType = ((ListItem)chartType.SelectedItem).Key;

            if (mainType == "Close")
            {
                m.addCloseLine(0x000040);
            }
            else if (mainType == "TP")
            {
                m.addTypicalPrice(0x000040);
            }
            else if (mainType == "WC")
            {
                m.addWeightedClose(0x000040);
            }
            else if (mainType == "Median")
            {
                m.addMedianPrice(0x000040);
            }

            //
            // Add comparison line if there is data for comparison
            //
            if ((compareData != null) && (compareData.Length > extraPoints))
            {
                m.addComparison(compareData, 0x0000ff, compareKey);
            }

            //
            // Add moving average lines.
            //
            addMovingAvg(m, ((ListItem)avgType1.SelectedItem).Key, avgPeriod1, 0x663300);
            addMovingAvg(m, ((ListItem)avgType2.SelectedItem).Key, avgPeriod2, 0x9900ff);

            //
            // Draw candlesticks or OHLC symbols if the user has selected them.
            //
            if (mainType == "CandleStick")
            {
                m.addCandleStick(0x33ff33, 0xff3333);
            }
            else if (mainType == "OHLC")
            {
                m.addHLOC(0x008800, 0xcc0000);
            }

            //
            // Add parabolic SAR if necessary
            //
            if (parabolicSAR.IsChecked.GetValueOrDefault())
            {
                m.addParabolicSAR(0.02, 0.02, 0.2, Chart.DiamondShape, 5, 0x008800, 0x000000);
            }

            //
            // Add price band/channel/envelop to the chart according to user selection
            //
            string selectedBand = ((ListItem)priceBand.SelectedItem).Key;

            if (selectedBand == "BB")
            {
                m.addBollingerBand(20, 2, 0x9999ff, unchecked ((int)(0xc06666ff)));
            }
            else if (selectedBand == "DC")
            {
                m.addDonchianChannel(20, 0x9999ff, unchecked ((int)(0xc06666ff)));
            }
            else if (selectedBand == "Envelop")
            {
                m.addEnvelop(20, 0.1, 0x9999ff, unchecked ((int)(0xc06666ff)));
            }

            //
            // Add volume bars to the main chart if necessary
            //
            if (volumeBars.IsChecked.GetValueOrDefault())
            {
                m.addVolBars(indicatorHeight, 0x99ff99, 0xff9999, 0xc0c0c0);
            }

            //
            // Add additional indicators as according to user selection.
            //
            addIndicator(m, ((ListItem)indicator2.SelectedItem).Key, indicatorHeight);
            addIndicator(m, ((ListItem)indicator3.SelectedItem).Key, indicatorHeight);
            addIndicator(m, ((ListItem)indicator4.SelectedItem).Key, indicatorHeight);

            //
            // output the chart
            //
            viewer.Chart = m;

            //
            // tooltips for the chart
            //
            viewer.ImageMap = m.getHTMLImageMap("", "", "title='" + m.getToolTipDateFormat()
                                                + " {value|P}'");
        }
        private void FrmTrackFinance_Load(object sender, EventArgs e)
        {
            // Create a finance chart demo containing 100 days of data
            int noOfDays = 100;

            // To compute moving averages starting from the first day, we need to get extra data points before
            // the first day
            int extraDays = 30;

            // In this exammple, we use a random number generator utility to simulate the data. We set up the
            // random table to create 6 cols x (noOfDays + extraDays) rows, using 9 as the seed.
            RanTable rantable = new RanTable(9, 6, noOfDays + extraDays);

            // Set the 1st col to be the timeStamp, starting from Sep 4, 2011, with each row representing one
            // day, and counting week days only (jump over Sat and Sun)
            rantable.setDateCol(0, new DateTime(2011, 9, 4), 86400, true);

            // Set the 2nd, 3rd, 4th and 5th columns to be high, low, open and close data. The open value
            // starts from 100, and the daily change is random from -5 to 5.
            rantable.setHLOCCols(1, 100, -5, 5);

            // Set the 6th column as the vol data from 5 to 25 million
            rantable.setCol(5, 50000000, 250000000);

            // Now we read the data from the table into arrays
            double[] timeStamps = rantable.getCol(0);
            double[] highData   = rantable.getCol(1);
            double[] lowData    = rantable.getCol(2);
            double[] openData   = rantable.getCol(3);
            double[] closeData  = rantable.getCol(4);
            double[] volData    = rantable.getCol(5);

            // Create a FinanceChart object of width 720 pixels
            FinanceChart c = new FinanceChart(720);

            // Add a title to the chart
            c.addTitle("Finance Chart Demonstration");

            // Disable default legend box, as we are using dynamic legend
            c.setLegendStyle("normal", 8, Chart.Transparent, Chart.Transparent);

            // Set the data into the finance chart object
            c.setData(timeStamps, highData, lowData, openData, closeData, volData, extraDays);

            // Add the main chart with 240 pixels in height
            c.addMainChart(240);

            // Add a 10 period simple moving average to the main chart, using brown color
            c.addSimpleMovingAvg(10, 0x663300);

            // Add a 20 period simple moving average to the main chart, using purple color
            c.addSimpleMovingAvg(20, 0x9900ff);

            // Add candlestick symbols to the main chart, using green/red for up/down days
            c.addCandleStick(0x00ff00, 0xff0000);

            // Add 20 days bollinger band to the main chart, using light blue (9999ff) as the border and
            // semi-transparent blue (c06666ff) as the fill color
            c.addBollingerBand(20, 2, 0x9999ff, unchecked ((int)0xc06666ff));

            // Add a 75 pixels volume bars sub-chart to the bottom of the main chart, using green/red/grey for
            // up/down/flat days
            c.addVolBars(75, 0x99ff99, 0xff9999, 0x808080);

            // Append a 14-days RSI indicator chart (75 pixels high) after the main chart. The main RSI line
            // is purple (800080). Set threshold region to +/- 20 (that is, RSI = 50 +/- 25). The upper/lower
            // threshold regions will be filled with red (ff0000)/blue (0000ff).
            c.addRSI(75, 14, 0x800080, 20, 0xff0000, 0x0000ff);

            // Append a MACD(26, 12) indicator chart (75 pixels high) after the main chart, using 9 days for
            // computing divergence.
            c.addMACD(75, 26, 12, 9, 0x0000ff, 0xff00ff, 0x008000);

            // Include track line with legend for the latest data values
            trackFinance(c, ((XYChart)c.getChart(0)).getPlotArea().getRightX());

            // Assign the chart to the WinChartViewer
            winChartViewer1.Chart = c;
        }
        //Main code for creating chart.
        //Note: the argument img is unused because this demo only has 1 chart.
        public void createChart(WinChartViewer WebChartViewer1, string img, int stockId, int timeFrameId, DateTime fromDt, DateTime toDt, int ballSize, int chartWidth, int chartHeighth, int priceType)
        {
            var stock = (from s in dataContext.stocks
                         where s.id == stockId
                         select s).FirstOrDefault();

            if (stock == null)
            {
                errMsg(WebChartViewer1, "Инструмент не найден");
                return;
            }

            var quotes = (from q in dataContext.volquotes
                          where q.stock == stockId &&
                          q.timeframe == timeFrameId &&
                          q.datetime >= fromDt &&
                          q.datetime <= toDt.AddDays(1)
                          orderby q.datetime ascending
                          select q);

            VolQuotesLst = quotes.ToList();

            if (quotes == null || quotes.Count() == 0)
            {
                errMsg(WebChartViewer1, "Данные отсутствуют");
                return;
            }

            var timeFrame = (from t in dataContext.timeframes
                             where t.id == timeFrameId
                             select t).FirstOrDefault();

            if (timeFrame == null)
            {
                errMsg(WebChartViewer1, "Тайм фрейм отсутствуют");
                return;
            }

            string tickerKey = stock.ticker.Trim();

            // The data series we want to get.
            if (!getData(fromDt, toDt))
            {
                errMsg(WebChartViewer1, "Инструмент не найден");
                return;
            }

            //-------------


            // Create the chart object using the selected size
            FinanceChart m = new FinanceChart(chartWidth);

            string[] monthNames = { "Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек" };
            m.setMonthNames(monthNames);

            m.setDateLabelFormat("{value|yyyy}",
                                 "<*font=bold*>{value|mmm yy}",
                                 "{value|mm/yy}",
                                 "<*font=bold*>{value|d mmm}",
                                 "{value|d}",
                                 "<*font=bold*>{value|d mmm<*br*>h:nna}",
                                 "{value|h:nna}");



            // Set the data into the chart object
            m.setData(timeStamps, highData, lowData, openData, closeData, VolumeData,
                      0);

            //
            // We configure the title of the chart. In this demo chart design, we put the
            // company name as the top line of the title with left alignment.
            //
            m.addPlotAreaTitle(Chart.TopLeft, tickerKey);
            m.addPlotAreaTitle(Chart.BottomLeft, "<*font=Arial,size=8*>" + m.formatValue(
                                   fromDt, "dd MMM, yyyy") + " - " + m.formatValue(
                                   toDt, "dd MMM, yyyy"));

            // A copyright message at the bottom left corner the title area
            m.addPlotAreaTitle(Chart.BottomRight,
                               " ");

            //--
            int mainHeight      = 350;
            int indicatorHeight = 110;

            //
            // Add the main chart
            //
            XYChart MainChart = m.addMainChart(mainHeight);

            //---------------------

            m.addCandleStick(0x33ff33, 0xff3333);
            m.addVolBars(indicatorHeight, 0x99ff99, 0xff9999, 0xc0c0c0);

            // Output the chart
            WebChartViewer1.Image = m.makeImage();
        }
        /// <summary>
        /// Create a financial chart according to user selections. The user selections are
        /// encoded in the query parameters.
        /// </summary>
        public BaseChart drawChart()
        {
            // In this demo, we just assume we plot up to the latest time. So end date is now.
            DateTime endDate = DateTime.Now;

            // If the trading day has not yet started (before 9:30am), or if the end date is on on Sat or
            // Sun, we set the end date to 4:00pm of the last trading day
            while ((endDate.TimeOfDay.CompareTo(new TimeSpan(9, 30, 0)) < 0) || (endDate.DayOfWeek ==
                                                                                 DayOfWeek.Sunday) || (endDate.DayOfWeek == DayOfWeek.Saturday))
            {
                endDate = endDate.Date.AddDays(-1).Add(new TimeSpan(16, 0, 0));
            }

            // The duration selected by the user
            int durationInDays = int.Parse(Request["TimeRange"]);

            // Compute the start date by subtracting the duration from the end date.
            DateTime startDate = endDate;

            if (durationInDays >= 30)
            {
                // More or equal to 30 days - so we use months as the unit
                startDate = new DateTime(endDate.Year, endDate.Month, 1).AddMonths(-durationInDays / 30);
            }
            else
            {
                // Less than 30 days - use day as the unit. The starting point of the axis is always at
                // the start of the day (9:30am). Note that we use trading days, so we skip Sat and Sun
                // in counting the days.
                startDate = endDate.Date;
                for (int i = 1; i < durationInDays; ++i)
                {
                    if (startDate.DayOfWeek == DayOfWeek.Monday)
                    {
                        startDate = startDate.AddDays(-3);
                    }
                    else
                    {
                        startDate = startDate.AddDays(-1);
                    }
                }
            }

            // The moving average periods selected by the user.
            int avgPeriod1 = 0;

            try { avgPeriod1 = int.Parse(Request["movAvg1"]);; }
            catch { avgPeriod1 = 0;; }
            int avgPeriod2 = 0;

            try { avgPeriod2 = int.Parse(Request["movAvg2"]);; }
            catch { avgPeriod2 = 0;; }

            if (avgPeriod1 < 0)
            {
                avgPeriod1 = 0;
            }
            else if (avgPeriod1 > 300)
            {
                avgPeriod1 = 300;
            }

            if (avgPeriod2 < 0)
            {
                avgPeriod2 = 0;
            }
            else if (avgPeriod2 > 300)
            {
                avgPeriod2 = 300;
            }

            // We need extra leading data points in order to compute moving averages.
            int extraPoints = 20;

            if (avgPeriod1 > extraPoints)
            {
                extraPoints = avgPeriod1;
            }
            if (avgPeriod2 > extraPoints)
            {
                extraPoints = avgPeriod2;
            }

            // Get the data series to compare with, if any.
            string compareKey = Request["CompareWith"].Trim();

            compareData = null;
            if (getData(compareKey, startDate, endDate, durationInDays, extraPoints))
            {
                compareData = closeData;
            }

            // The data series we want to get.
            string tickerKey = Request["TickerSymbol"].Trim();

            if (!getData(tickerKey, startDate, endDate, durationInDays, extraPoints))
            {
                return(errMsg("Please enter a valid ticker symbol"));
            }

            // We now confirm the actual number of extra points (data points that are before the start
            // date) as inferred using actual data from the database.
            extraPoints = timeStamps.Length;
            for (int i = 0; i < timeStamps.Length; ++i)
            {
                if (timeStamps[i] >= startDate)
                {
                    extraPoints = i;
                    break;
                }
            }

            // Check if there is any valid data
            if (extraPoints >= timeStamps.Length)
            {
                // No data - just display the no data message.
                return(errMsg("No data available for the specified time period"));
            }

            // In some finance chart presentation style, even if the data for the latest day is not fully
            // available, the axis for the entire day will still be drawn, where no data will appear near
            // the end of the axis.
            if (resolution < 86400)
            {
                // Add extra points to the axis until it reaches the end of the day. The end of day is
                // assumed to be 16:00 (it depends on the stock exchange).
                DateTime lastTime            = timeStamps[timeStamps.Length - 1];
                int      extraTrailingPoints = (int)(new TimeSpan(16, 0, 0).Subtract(lastTime.TimeOfDay
                                                                                     ).TotalSeconds / resolution);
                if (extraTrailingPoints > 0)
                {
                    DateTime[] extendedTimeStamps = new DateTime[timeStamps.Length + extraTrailingPoints
                                                    ];
                    Array.Copy(timeStamps, 0, extendedTimeStamps, 0, timeStamps.Length);
                    for (int i = 0; i < extraTrailingPoints; ++i)
                    {
                        extendedTimeStamps[i + timeStamps.Length] = lastTime.AddSeconds(resolution * (i +
                                                                                                      1));
                    }
                    timeStamps = extendedTimeStamps;
                }
            }

            //
            // At this stage, all data are available. We can draw the chart as according to user input.
            //

            //
            // Determine the chart size. In this demo, user can select 4 different chart sizes. Default
            // is the large chart size.
            //
            int width           = 780;
            int mainHeight      = 255;
            int indicatorHeight = 80;

            string size = Request["ChartSize"];

            if (size == "S")
            {
                // Small chart size
                width           = 450;
                mainHeight      = 160;
                indicatorHeight = 60;
            }
            else if (size == "M")
            {
                // Medium chart size
                width           = 620;
                mainHeight      = 215;
                indicatorHeight = 70;
            }
            else if (size == "H")
            {
                // Huge chart size
                width           = 1000;
                mainHeight      = 320;
                indicatorHeight = 90;
            }

            // Create the chart object using the selected size
            FinanceChart m = new FinanceChart(width);

            // Set the data into the chart object
            m.setData(timeStamps, highData, lowData, openData, closeData, volData, extraPoints);

            //
            // We configure the title of the chart. In this demo chart design, we put the company name as
            // the top line of the title with left alignment.
            //
            m.addPlotAreaTitle(Chart.TopLeft, tickerKey);

            // We displays the current date as well as the data resolution on the next line.
            string resolutionText = "";

            if (resolution == 30 * 86400)
            {
                resolutionText = "Monthly";
            }
            else if (resolution == 7 * 86400)
            {
                resolutionText = "Weekly";
            }
            else if (resolution == 86400)
            {
                resolutionText = "Daily";
            }
            else if (resolution == 900)
            {
                resolutionText = "15-min";
            }

            m.addPlotAreaTitle(Chart.BottomLeft, "<*font=Arial,size=8*>" + m.formatValue(DateTime.Now,
                                                                                         "mmm dd, yyyy") + " - " + resolutionText + " chart");

            // A copyright message at the bottom left corner the title area
            m.addPlotAreaTitle(Chart.BottomRight,
                               "<*font=Arial,size=8*>(c) Advanced Software Engineering");

            //
            // Add the first techical indicator according. In this demo, we draw the first indicator on
            // top of the main chart.
            //
            addIndicator(m, Request["Indicator1"], indicatorHeight);

            //
            // Add the main chart
            //
            m.addMainChart(mainHeight);

            //
            // Set log or linear scale according to user preference
            //
            if (Request["LogScale"] == "1")
            {
                m.setLogScale(true);
            }

            //
            // Set axis labels to show data values or percentage change to user preference
            //
            if (Request["PercentageScale"] == "1")
            {
                m.setPercentageAxis();
            }

            //
            // Draw any price line the user has selected
            //
            string mainType = Request["ChartType"];

            if (mainType == "Close")
            {
                m.addCloseLine(0x000040);
            }
            else if (mainType == "TP")
            {
                m.addTypicalPrice(0x000040);
            }
            else if (mainType == "WC")
            {
                m.addWeightedClose(0x000040);
            }
            else if (mainType == "Median")
            {
                m.addMedianPrice(0x000040);
            }

            //
            // Add comparison line if there is data for comparison
            //
            if (compareData != null)
            {
                if (compareData.Length > extraPoints)
                {
                    m.addComparison(compareData, 0x0000ff, compareKey);
                }
            }

            //
            // Add moving average lines.
            //
            addMovingAvg(m, Request["avgType1"], avgPeriod1, 0x663300);
            addMovingAvg(m, Request["avgType2"], avgPeriod2, 0x9900ff);

            //
            // Draw candlesticks or OHLC symbols if the user has selected them.
            //
            if (mainType == "CandleStick")
            {
                m.addCandleStick(0x33ff33, 0xff3333);
            }
            else if (mainType == "OHLC")
            {
                m.addHLOC(0x008800, 0xcc0000);
            }

            //
            // Add parabolic SAR if necessary
            //
            if (Request["ParabolicSAR"] == "1")
            {
                m.addParabolicSAR(0.02, 0.02, 0.2, Chart.DiamondShape, 5, 0x008800, 0x000000);
            }

            //
            // Add price band/channel/envelop to the chart according to user selection
            //
            string bandType = Request["Band"];

            if (bandType == "BB")
            {
                m.addBollingerBand(20, 2, 0x9999ff, unchecked ((int)0xc06666ff));
            }
            else if (bandType == "DC")
            {
                m.addDonchianChannel(20, 0x9999ff, unchecked ((int)0xc06666ff));
            }
            else if (bandType == "Envelop")
            {
                m.addEnvelop(20, 0.1, 0x9999ff, unchecked ((int)0xc06666ff));
            }

            //
            // Add volume bars to the main chart if necessary
            //
            if (Request["Volume"] == "1")
            {
                m.addVolBars(indicatorHeight, 0x99ff99, 0xff9999, 0xc0c0c0);
            }

            //
            // Add additional indicators as according to user selection.
            //
            addIndicator(m, Request["Indicator2"], indicatorHeight);
            addIndicator(m, Request["Indicator3"], indicatorHeight);
            addIndicator(m, Request["Indicator4"], indicatorHeight);

            return(m);
        }