예제 #1
0
        public override string GetStr()
        {
            //IDataProvider idp = Manager.Canvas.BackChart.DataProvider;
            //double[] dd = idp["DATE"];
            FormulaChart BackChart = Manager.Canvas.Chart;
            //int Bar1 = FormulaChart.FindIndex(dd,ControlPoints[0].X);
            //int Bar2 = FormulaChart.FindIndex(dd,ControlPoints[1].X);
            int Bar1 = BackChart.DateToIndex(ControlPoints[0].X);
            int Bar2 = BackChart.DateToIndex(ControlPoints[1].X);

            return((Bar2 - Bar1) + "(T)");
        }
예제 #2
0
 public override string GetStr()
 {
     if (lineType == SingleLineType.Horizontal)
     {
         PointF p     = ToPointF(ControlPoints[0]);
         double Value = Area.AxisY.GetValueFromY(p.Y);
         return(Value.ToString(DataFormat));
     }
     else
     {
         FormulaChart BackChart = Manager.Canvas.Chart;
         int          i         = BackChart.DateToIndex(ControlPoints[0].X);
         DateTime     D         = BackChart.IndexToDate(i);
         return(D.ToString(DataFormat));
     }
 }
예제 #3
0
        /// <summary>
        /// Replace format
        /// {D:yyyy-MM-dd}
        /// {C:f2}
        /// {0:f2}
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public string ReplaceTag(ObjectPoint op, string s)
        {
            while (true)
            {
                int i1 = s.IndexOf('{');
                int i2 = s.IndexOf('}');
                if (i2 > i1)
                {
                    string s1 = s.Substring(i1 + 1, i2 - i1 - 1);
                    int    i  = s1.IndexOf(':');
                    string s3 = "";
                    string s2 = s1;
                    if (i > 0)
                    {
                        s2 = s1.Substring(0, i);
                        s3 = s1.Substring(i + 1);
                    }

                    FormulaChart  BackChart = Manager.Canvas.Chart;
                    IDataProvider idp       = BackChart.DataProvider;
                    double[]      dd        = idp["DATE"];
                    int           Bar       = BackChart.DateToIndex(op.X);
                    if (string.Compare(s2, "D") == 0)
                    {
                        if (s3 == "")
                        {
                            s3 = "yyyy-MM-dd";
                        }
                        s2 = BackChart.IndexToDate(Bar).ToString(s3);
                    }
                    else
                    {
                        FormulaData fd = null;
                        try
                        {
                            i = int.Parse(s2);
                            if (i < Area.FormulaDataArray.Count)
                            {
                                dd = Area.FormulaDataArray[i].Data;
                            }
                        }
                        catch
                        {
                            fd = Area.FormulaDataArray[s2];
                            if (object.Equals(fd, null))
                            {
                                foreach (FormulaData f in Area.FormulaDataArray)
                                {
                                    dd = f[s2];
                                    if (dd != null)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                dd = fd.Data;
                            }
                        }
                        if (dd != null && Bar < dd.Length)
                        {
                            if (s3 == "")
                            {
                                s3 = "f2";
                            }
                            s2 = dd[Bar].ToString(s3);
                        }
                        else
                        {
                            s2 = "NaN";
                        }
                    }
                    s = s.Substring(0, i1) + s2 + s.Substring(i2 + 1);
                }
                else
                {
                    break;
                }
            }
            return(s);
        }
예제 #4
0
        public void SetSnapLine(int PointIndex, bool OpenStart, bool OpenEnd)
        {
            FormulaChart BackChart = Manager.Canvas.Chart;

            if (BackChart == null)
            {
                return;
            }
            IDataProvider idp = BackChart.DataProvider;

            if (idp == null)
            {
                return;
            }

            if (PointIndex < ControlPoints.Length)
            {
                int Bar  = BackChart.DateToIndex(ControlPoints[PointIndex].X);
                int Bar1 = BackChart.DateToIndex(BackChart.StartTime);
                int Bar2 = BackChart.DateToIndex(BackChart.EndTime);
                if (!OpenStart)
                {
                    Bar1 = Bar;
                }
                if (!OpenEnd)
                {
                    Bar2 = Bar;
                }
                FormulaData fd = Area.FormulaDataArray[0];
                double[][]  dd = new double[][] { fd["L"], fd["H"] };
                if (dd[0] == null)
                {
                    dd[0] = fd.Data;
                }
                if (dd[1] == null)
                {
                    dd[1] = fd.Data;
                }
                if (Bar1 >= dd[0].Length)
                {
                    Bar1 = dd[0].Length - 1;
                }
                if (Bar2 >= dd[0].Length)
                {
                    Bar2 = dd[0].Length - 1;
                }

                if (Bar1 >= 0 && Bar2 >= 0)
                {
                    double A = float.MaxValue;
                    double B = ControlPoints[PointIndex].Y;
                    double C = B;
                    for (int i = Bar1; i <= Bar2; i++)
                    {
                        for (int j = 0; j < dd.Length; j++)
                        {
                            double k = Math.Abs(dd[j][i] - B);
                            if (k < A)
                            {
                                A = k;
                                C = dd[j][i];
                            }
                        }
                    }
                    double M = (Area.AxisY.MaxY - Area.AxisY.MinY);
                    if (A / M < snapPercent)
                    {
                        ControlPoints[PointIndex].Y = C;
                    }
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Make control points snap to price
        /// </summary>
        /// <param name="snap"></param>
        public void SetSnapPrice(SnapType snap)
        {
            if (snap == SnapType.Price)
            {
                FormulaChart  BackChart = Manager.Canvas.Chart;
                IDataProvider idp       = BackChart.DataProvider;
                int           i1        = 0;
                int           i2        = 1;
                if (ControlPointNum == 1)
                {
                    i2 = 0;
                }

                int Bar1 = BackChart.DateToIndex(ControlPoints[i1].X);
                int Bar2 = BackChart.DateToIndex(ControlPoints[i2].X);
                if (Bar1 > Bar2)
                {
                    Swap(ref Bar1, ref Bar2);
                }

                FormulaData fd  = Area.FormulaDataArray[0];
                double[]    dd1 = fd["L"];
                if (dd1 == null)
                {
                    dd1 = fd.Data;
                }
                double[] dd2 = fd["H"];
                if (dd2 == null)
                {
                    dd2 = fd.Data;
                }
                if (Bar1 >= dd1.Length)
                {
                    Bar1 = dd1.Length - 1;
                }
                if (Bar2 >= dd1.Length)
                {
                    Bar2 = dd1.Length - 1;
                }

                float A = float.MaxValue;
                float B = float.MinValue;
                for (int i = Bar1; i <= Bar2; i++)
                {
                    A = Math.Min(A, (float)dd1[i]);
                    B = Math.Max(B, (float)dd2[i]);
                }
                if (ControlPointNum > 1)
                {
                    if (ControlPoints[0].Y < ControlPoints[1].Y)
                    {
                        Swap(ref A, ref B);
                    }
                    ControlPoints[0].Y = B;
                    ControlPoints[1].Y = A;
                }
                else
                {
                    if (ControlPoints[0].Y < A)
                    {
                        ControlPoints[0].Y = A;
                    }
                    else if (ControlPoints[0].Y > B)
                    {
                        ControlPoints[0].Y = B;
                    }
                }
            }
        }
예제 #6
0
        public override void CalcPoint()
        {
            if (Area.FormulaDataArray.Count == 0)
            {
                return;
            }
            fd = Area.FormulaDataArray[0];
            //IDataProvider idp = Manager.Canvas.BackChart.DataProvider;
            //double[] dd = idp["DATE"];
            FormulaChart BackChart = Manager.Canvas.Chart;
            int          i1        = 0;
            int          i2        = 1;

            if (ControlPoints[0].X > ControlPoints[1].X)
            {
                i1 = 1;
                i2 = 0;
            }
            //Bar1 = FormulaChart.FindIndex(dd,ControlPoints[i1].X);
            //Bar2 = FormulaChart.FindIndex(dd,ControlPoints[i2].X);
            Bar1 = BackChart.DateToIndex(ControlPoints[i1].X);
            Bar2 = BackChart.DateToIndex(ControlPoints[i2].X);

            if (regressionType != RegressionType.UpDownTrend)
            {
                FormulaBase.CalcLinearRegression(fd, Bar2, Bar2 - Bar1, out A, out B);
            }
            else
            {
                A = ControlPoints[i1].Y;
                B = (ControlPoints[i2].Y - ControlPoints[i1].Y) / (Bar2 - Bar1);
            }

            ObjectPoint opStart = ControlPoints[i1];
            ObjectPoint opEnd   = ControlPoints[i2];

            opStart.Y = A;
            opEnd.Y   = A + B * (Bar2 - Bar1);

            scLines.Clear();
            if (centerLine)
            {
                scLines.Add(opStart, opEnd);
            }
            float Delta;

            if (regressionType == RegressionType.Channel ||
                regressionType == RegressionType.AsynChannel ||
                regressionType == RegressionType.UpDownTrend)
            {
                float dtUp   = CalcDelta(fd, A, B, Bar1, Bar2, "H", true);
                float dtDown = CalcDelta(fd, A, B, Bar1, Bar2, "L", false);
                if (regressionType == RegressionType.Channel)
                {
                    Delta = Math.Max(Math.Abs(dtUp), Math.Abs(dtDown));
                }
                else
                {
                    Delta = -dtUp;
                }
                if (upLine)
                {
                    AddLine(opStart, opEnd, Delta);
                }

                if (regressionType != RegressionType.Channel)
                {
                    Delta = dtDown;
                }
                if (downLine)
                {
                    AddLine(opStart, opEnd, -Delta);
                }
            }
            else if (regressionType == RegressionType.StdChannel ||
                     regressionType == RegressionType.StdErrorChannel)
            {
                Delta = Std(regressionType == RegressionType.StdErrorChannel);
                AddLine(opStart, opEnd, Delta);
                AddLine(opStart, opEnd, -Delta);
            }

            pfStart = new PointF[scLines.Count];
            pfEnd   = new PointF[scLines.Count];
            for (int j = 0; j < scLines.Count; j++)
            {
                ObjectSegment os = scLines[j];
                if (!double.IsNaN(os.op1.Y) && !double.IsNaN(os.op2.Y))
                {
                    pfStart[j] = ToPointF(os.op1);
                    pfEnd[j]   = ToPointF(os.op2);
                }
                else
                {
                    pfStart[j] = PointF.Empty;
                    pfEnd[j]   = PointF.Empty;
                }
            }
            OpenStartEnd(openStart, openEnd);
        }
예제 #7
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            int    Height = 800;
            int    Width  = 600;
            Bitmap B;

            try
            {
                long Start = DateTime.Now.Ticks;

                ExchangeIntraday ei        = null;
                DateTime         StartTime = DateTime.Today.AddMonths(-6);
                DateTime         EndTime   = DateTime.Today;

                string Param = Request.QueryString["Span"];
                if (Param != null && Param != "")
                {
                    DataCycle dc;
                    if (Param.Length > 2)
                    {
                        dc = DataCycle.Parse(Param);
                    }
                    else
                    {
                        dc = new DataCycle(DataCycleBase.MONTH, Tools.ToIntDef(Param, 6));
                    }
                    StartTime = EndTime - dc;
                    //StartTime = EndTime.AddMonths(-Tools.ToIntDef(Param,6));
                }

                Param = Request.QueryString["E"];
                if (Param != null && Param != "")
                {
                    ei = ExchangeIntraday.GetExchangeIntraday(Param);
                }

                //Create financial chart instance
                FormulaChart fc = new FormulaChart();

                string Main = Request.QueryString["Main"];
                if (Main == null || Main == "")
                {
                    fc.AddArea("MAIN", 3);
                }
                else
                {
                    fc.AddArea(Main, 3);
                }

                string QuoteCode = Request.QueryString["Code"];
                if (QuoteCode == null)
                {
                    QuoteCode = "";
                }

                DataManagerBase dmb;
                Param = Request.QueryString["Provider"];
                if (Param == null)
                {
                    Param = "";
                }
                if (string.Compare(Param, "DB", true) == 0)
                {
                    //Create DBDataManager , Get stock data from sql server.
                    dmb = new DBDataManager();
                    ((DBDataManager)dmb).AutoYahooToDB =
                        Request.QueryString["His"] != "0" && Config.AutoYahooToDB == 1;
                }
                else if (Param.StartsWith("MS("))
                {
                    dmb = new MSDataManager(Param.Substring(3, Param.Length - 4));
                }
                else if (Param == "" || string.Compare(Param, "Yahoo", true) == 0)
                {
                    //Create YahooDataManager , Get stock data from yahoo.
                    dmb = new YahooDataManager();
                    Utils.SetYahooCacheRoot(dmb);
                    if (Config.IncludeTodayQuote == 1)
                    {
                        ((DataManagerBase)dmb).DownloadRealTimeQuote = true;
                    }
                }
                else
                {
                    string ManagerName = "WebDemos." + Param + "DataManager";
                    Type   t           = Type.GetType(ManagerName);
                    if (t == null)
                    {
                        throw new Exception(ManagerName + " not found!");
                    }
                    dmb = (DataManagerBase)Activator.CreateInstance(t);
                    if (dmb is IntraDataManagerBase)
                    {
                        if (ei == null)
                        {
                            ei = ExchangeIntraday.GetExchangeIntraday(Utils.GetExchange(QuoteCode));
                        }

                        CacheDataManagerBase cdmb = (CacheDataManagerBase)dmb;
                        cdmb.CacheTimeSpan     = TimeSpan.FromMilliseconds(Config.IntradayCacheTime * 1000);
                        cdmb.EnableMemoryCache = true;
                        //((CacheDataManagerBase)dmb).EnableFileCache = false;

                        StartTime = ei.GetCurrentTradingDay();
                        EndTime   = StartTime.AddSeconds(3600 * 24 - 1);
                        QuoteCode = Utils.GetPart1(QuoteCode);
                    }
                    dmb.EndTime   = Utils.ToDateDef(Request.QueryString["End"], EndTime);
                    dmb.StartTime = Utils.ToDateDef(Request.QueryString["Start"], StartTime);
                }
                if (Request.QueryString["RT"] == "1")
                {
                    ((DataManagerBase)dmb).DownloadRealTimeQuote = true;
                }

                int MainIndex = 0;

                if (Config.SymbolCase == "Upper")
                {
                    QuoteCode = QuoteCode.ToUpper();
                }
                else if (Config.SymbolCase == "Lower")
                {
                    QuoteCode = QuoteCode.ToLower();
                }

                string[] QuoteCodes = QuoteCode.Split(',');
                string   Over       = "";
                QuoteCode = QuoteCodes[0];
                for (int i = 1; i < QuoteCodes.Length; i++)
                {
                    if (Over != "")
                    {
                        Over += ";";
                    }
                    Over += "Compare(" + QuoteCodes[i] + ")";
                }

                Param = Request.QueryString["IND"];
                string[] Inds = null;
                if (Param != null && Param != "")
                {
                    Inds = Param.Split(';');
                }

                //Set stock chart size
                Param = Request.QueryString["Size"];
                try
                {
                    if (Param != null && Param != "")
                    {
                        int i = Param.IndexOf('*');
                        if (i > 0)
                        {
                            Width  = int.Parse(Param.Substring(0, i));
                            Height = int.Parse(Param.Substring(i + 1));
                        }
                        else
                        {
                            Width  = int.Parse(Param);
                            Height = Width * 3 / 4;
                            if (Inds != null && Inds.Length > 1)
                            {
                                Height += Height / 5 * (Inds.Length - 2);
                            }
                            Height += 36;
                        }
                    }
                }
                catch
                {
                }

                CommonDataProvider DataProvider = (CommonDataProvider)dmb[QuoteCode];

                Param = Request.QueryString["Adj"];
                DataProvider.Adjusted = Param != "0";

                if (DataProvider == null)
                {
                    throw new Exception(QuoteCode + " not found!");
                }
                if (dmb is IntraDataManagerBase)
                {
                    fc.FixedTime = object.Equals(Request.QueryString["Fix"], "1");
                    if (fc.FixedTime)
                    {
                        DataProvider.IntradayInfo = ei;
                    }
                }

                if (DataProvider.Count == 0)
                {
                    throw new Exception("No data found!");
                }
                fc[MainIndex].Formulas[0].Name = QuoteCode;

                //Add MA lines to main stock view
                Param = Request.QueryString["MA"];
                if (Param != null && Param != "")
                {
                    foreach (string s in Param.Split(';'))
                    {
                        if (s != "")
                        {
                            fc[MainIndex].AddFormula("FML.MA(" + s + ")");
                        }
                    }
                }

                //Add EMA lines to main stock view
                Param = Request.QueryString["EMA"];
                if (Param != null && Param != "")
                {
                    foreach (string s in Param.Split(';'))
                    {
                        if (s != "")
                        {
                            fc[MainIndex].AddFormula("FML.EMA(" + s + ")");
                        }
                    }
                }

                //Add override lines to main stock view
                Param = Request.QueryString["OVER"];
                if (Param != null && Param != "")
                {
                    if (Over != "")
                    {
                        Param = Param + ";" + Over;
                    }
                }
                else
                {
                    Param = Over;
                }

//				if (dmb is IntraDataManagerBase)
//				{
//					string s = DataProvider.GetStringData("LastPrice");
//					if (s!=null && s!="")
//					{
//						double d = double.Parse(s);
//
//						s = "DotLine("+d.ToString("f"+FormulaHelper.TestBestFormat(d,0))+")";
//						if (Param!=null && Param!="")
//							Param +=";"+s;
//						else Param = s;
//					}
//				}

                if (Param != null && Param != "")
                {
                    //foreach(string s in Param.Split(';'))
                    string[] ss = Param.Split(';');
                    for (int i = 0; i < ss.Length; i++)
                    {
                        string s = ss[i];
                        if (s != "")
                        {
                            if (s.ToUpper() == "AREABB")
                            {
                                fc[MainIndex].InsertFormula(0, "FML." + s);
                            }
                            else
                            {
                                fc[MainIndex].AddFormula("FML." + s);
                            }
                        }
                    }
                }

                //Add indicators to stock chart
                if (Inds != null)
                {
                    foreach (string s in Inds)
                    {
                        if (s != "")
                        {
                            int k = s.IndexOf("{U}");
                            if (k > 0)
                            {
                                fc.InsertArea(MainIndex, "FML." + s.Substring(0, k));
                                MainIndex++;
                            }
                            else
                            {
                                fc.AddArea("FML." + s);
                            }
                        }
                    }
                }

                //Apply build-in stock chart skin
                Param = Request.QueryString["Skin"];
                if (Param == null || Param == "")
                {
                    Param = Config.DefaultSkin;
                }
                FormulaSkin fs = FormulaSkin.GetSkinByName(Param);
                if (fs != null)
                {
                    if (Config.YAxisFormat != "")
                    {
                        fs.AxisY.Format = Config.YAxisFormat;
                    }

                    Param = Request.QueryString["LastX"];
                    if (Param == "1" || Config.ShowXAxisInLastArea)
                    {
                        fs.ShowXAxisInLastArea = true;
                    }

                    fc.SetSkin(fs);
                }

                Param = Request.QueryString["LatestValueType"];
                try
                {
                    if (Param == null || Param == "")
                    {
                        Param = Config.LatestValueType;
                    }
                    fc.LatestValueType = (LatestValueType)Enum.Parse(typeof(LatestValueType), Param, true);
                }
                catch
                {
                }

                //Add compare line to other stocks
                Param = Request.QueryString["COMP"];
                if (Param != null && Param != "")
                {
                    foreach (string s in Param.Split(';', ','))
                    {
                        if (s != "")
                        {
                            fc[MainIndex].AddFormula("COMPARE(" + s + ")");
                        }
                    }
                    fc[MainIndex].AxisY.ShowAsPercent = true;
                    fc[MainIndex].AxisY.Format        = "p1";
                    fc.LatestValueType = LatestValueType.None;
                }

                //Set stock chart time period
                fc.EndTime             = Utils.ToDateDef(Request.QueryString["End"], EndTime);
                fc.StartTime           = Utils.ToDateDef(Request.QueryString["Start"], StartTime);
                DataProvider.DataCycle = DataCycle.Parse(Request.QueryString["Cycle"]);

                //Set X-Axis format
                string XFormat = Request.QueryString["XFormat"];
                if (XFormat != null && XFormat != "")
                {
                    fc.AxisXFormat = XFormat;
                    fc.AllXFormats = null;
                }

                //Set Y-Axis format
                string YFormat = Request.QueryString["YFormat"];
                if (YFormat != null && YFormat != "")
                {
                    fc.AxisYFormat = YFormat;
                }

                //Set X-Axis cycle
                string XCycle = Request.QueryString["XCycle"];
                if (XCycle != null && XCycle != "")
                {
                    fc.DataCycle = DataCycle.Parse(XCycle);
                }

                //Set render type : Bar , Candle or Line
                Param = Request.QueryString["Type"];
                if (Param != null && Param != "")
                {
                    StockRenderType srt;
                    if (Param.Length == 1)
                    {
                        srt = (StockRenderType)int.Parse(Param);
                    }
                    else
                    {
                        srt = (StockRenderType)Enum.Parse(typeof(StockRenderType), Param, true);
                    }
                    fc[MainIndex].StockRenderType = srt;
                }

                //Set Scale type : Normal or Log
                Param = Request.QueryString["Scale"];
                if (Param != null && Param != "")
                {
                    ScaleType st;
                    if (Param.Length == 1)
                    {
                        st = (ScaleType)int.Parse(Param);
                    }
                    else
                    {
                        st = (ScaleType)Enum.Parse(typeof(ScaleType), Param, true);
                    }
                    fc[MainIndex].AxisY.Scale = st;
                }

                //Bottom margin
                Param = Request.QueryString["BMargin"];
                if (Param != null && Param != "")
                {
                    fc[MainIndex].BottomMargin = Tools.ToDoubleDef(Param, 0);
                }

                //Bind stock data
                fc.DataProvider = DataProvider;

                bool IsCompare = false;
                for (int i = 1; i < fc[MainIndex].FormulaDataArray.Count; i++)
                {
                    if (!fc[MainIndex].AxisY.ShowAsPercent &&
                        fc[MainIndex][i].ParentFormula.FormulaName.StartsWith("COMPARE"))
                    {
                        //FormulaAxisY fay = fc[MainIndex].AddNewAxisY(AxisPos.Left);
                        FormulaData fd = fc[MainIndex][i];
                        fd.Transform = Transform.Normal;
                        fc[MainIndex][i].ParentFormula.AxisYIndex = 1;
                        IsCompare = true;
                        //fd.AxisYIndex = 1;
                        break;
                    }
                }
                fc.ExtendYAxis(TwoYAxisType.AreaDifferent);

                for (int i = 0; i < fc[MainIndex].AxisYs.Count; i++)
                {
                    if (fc[MainIndex].IsMain(i) || IsCompare)
                    {
                        fc[MainIndex].AxisYs[i].AutoMultiply = false;
                    }
                }

                fc[MainIndex].AxisY.MajorTick.ShowLine = Config.ShowMainAreaLineY;
                fc[MainIndex].AxisX.MajorTick.ShowLine = Config.ShowMainAreaLineX;

                //Set indicator line width
                Param = Request.QueryString["Width"];
                if (Param != null && Param != "")
                {
                    float LineWidth = float.Parse(Param);
                    for (int i = 0; i < fc.Areas.Count; i++)
                    {
                        fc[i].LinePen.Width = LineWidth;
                    }
                }
                fc[MainIndex].RemoveAutoMultiplyForStockYAxis();                // AxisY.AutoMultiply = false;

                if (Request.QueryString["SV"] == "0")
                {
                    fc.ShowValueLabel = false;
                }
                fc.StickRenderType = Config.StickRenderType;


                bool b1 = Request.QueryString["HideX"] == "1";
                bool b2 = Request.QueryString["HideY"] == "1";
                foreach (FormulaArea fa in fc.Areas)
                {
                    fa.AxisY.Visible = fa.AxisY.Visible && !b2;
                    fa.AxisX.Visible = fa.AxisX.Visible && !b1;
                }

                Rectangle Rect = new Rectangle(0, 0, Width, Height);
                Param = Request.QueryString["Layout"];
                if (Param == null || Param == "")
                {
                    Param = "Default";
                }
                string[] Layouts = Param.Split(';', ',');
                Layout   L       = Layout.ParseString(Config.Read(Layouts[0] + "Layout", "ChartRect=(0,0,0,0)"), Rect);    //,DataProvider);
                for (int j = 1; j < Layouts.Length; j++)
                {
                    L.Merge(Layout.ParseString(Config.Read(Layouts[j] + "Layout", "ChartRect=(0,0,0,0)"), Rect));                //,DataProvider));
                }
                L.CompanyName       = Config.CompanyName;
                L.URL               = Config.URL;
                L.StartTick         = Start;
                fc.Rect             = L.ChartRect;
                fc.PriceLabelFormat = "{CODE}";
                fc.NativePaint     += new NativePaintHandler(fc_NativePaint);
                B = fc.GetBitmap(Width, Height, fc.Rect);

                Graphics g = Graphics.FromImage(B);

                int X = Tools.ToIntDef(Request.QueryString["X"], 0);
                int Y = Tools.ToIntDef(Request.QueryString["Y"], 0);
                if (X > 0 && Y > 0)
                {
                    fc.SetCursorPos(X, Y);
                    fc.Rect            = new Rectangle(0, 0, Width, Height);
                    fc.ShowCursorLabel = true;
                    fc.DrawCursor(g, X, Y);
                }
                else
                {
                    int Pos = fc.DateToIndex(fc.EndTime);
                    if (Pos >= DataProvider.Count)
                    {
                        Pos = DataProvider.Count - 1;
                    }
                    fc.CursorPos = Pos;
                }
                L.Render(g, Rect, fc, Point.Empty, fc.CursorPos);            //-1 ; fc.CursorPos
            }
            catch (Exception ex)
            {
                B = new Bitmap(Width, Height);
                Graphics g = Graphics.FromImage(B);

                g.Clear(Color.White);

                StringFormat sf = new StringFormat();
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                g.DrawString(ex.ToString() /*.Message*/, new Font("Verdana", 12),
                             new SolidBrush(Color.FromArgb(196, Color.Black)), new Rectangle(0, 0, Width, Height), sf);
            }

            //Create stock image to Bitmap
            Response.ContentType = "Image/" + Config.ImageFormat;

            //Create chart stream
            MemoryStream ms = new MemoryStream();

            if (Config.ImageFormat == "Gif")
            {
                Type tQuantization = (Type)Application["Quantization"];
                if (tQuantization == null)
                {
                    Assembly[] ass = AppDomain.CurrentDomain.GetAssemblies();
                    foreach (Assembly a in ass)
                    {
                        if (a.FullName.StartsWith("ImageQuantization"))
                        {
                            tQuantization = a.GetType("ImageQuantization.OctreeQuantizer");
                        }
                    }
                    Application["Quantization"] = tQuantization;
                }

                if (tQuantization != null)
                {
                    object[] os;
                    if (Config.TransparentColor.IsEmpty)
                    {
                        os = new object[] { B, ms, Config.GifColors }
                    }
                    ;
                    else
                    {
                        os = new object[] { B, ms, Config.GifColors, Config.TransparentColor }
                    };

                    tQuantization.InvokeMember("Save",
                                               BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, os);
                }

                if (ms.Length == 0)
                {
                    B.Save(ms, ImageFormat.Png);
                }
            }
            else if (Config.ImageFormat == "Png")
            {
                B.Save(ms, ImageFormat.Png);
            }
            else if (Config.ImageFormat == "Jpeg")
            {
                B.Save(ms, ImageFormat.Jpeg);
            }

            //Output the chart stream to web browser
            ms.WriteTo(Response.OutputStream);
        }