public static IStockPaintBar CreatePaintBar(string fullName)
        {
            using (MethodLogger ml = new MethodLogger(typeof(StockPaintBarManager)))
             {
            IStockPaintBar paintBar = null;
            if (paintBarList == null)
            {
               GetPaintBarList();
            }
            try
            {
               int paramStartIndex = fullName.IndexOf('(') + 1;
               string name = fullName;
               int paramLength = 0;
               if (paramStartIndex != 0) // Else we are creating an empty indicator for the dianlog window
               {
                  paramLength = fullName.LastIndexOf(')') - paramStartIndex;
                  name = fullName.Substring(0, paramStartIndex - 1);
               }

               if (paintBarList.Contains(name))
               {
                  StockPaintBarManager sm = new StockPaintBarManager();
                  paintBar =
                      (IStockPaintBar)
                          sm.GetType()
                              .Assembly.CreateInstance(
                                  "StockAnalyzer.StockClasses.StockViewableItems.StockPaintBars.StockPaintBar_" +
                                  name);
                  if (paintBar != null)
                  {
                     if (paramLength > 0)
                     {
                        string parameters = fullName.Substring(paramStartIndex, paramLength);
                        paintBar.Initialise(parameters.Split(','));
                     }
                  }
               }
               else
               {
                  throw new StockAnalyzerException("PaintBar " + name + " doesn't not exist ! ");
               }
            }
            catch (System.Exception e)
            {
               if (e is StockAnalyzerException) throw e;
               paintBar = null;
               StockLog.Write(e);
            }
            return paintBar;
             }
        }
        public void InitZoom(int startIndex, int endIndex)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (!CheckGraphSanity()) { return; }
            if (startIndex == endIndex || startIndex < 0 || endIndex > this.dateSerie.Length - 1)
            {
               this.Deactivate("Invalid input data range...", false);
               return;
            }
            this.StartIndex = startIndex;
            this.EndIndex = endIndex;

            // Initialise transformation matrix
            this.IsInitialized = InitializeTransformMatrix();
            this.ForceRefresh();

            if (this.ZoomChanged != null)
            {
               this.ZoomChanged(startIndex, endIndex);
            }
             }
        }
        protected override void OnSizeChanged(EventArgs e)
        {
            using (MethodLogger ml = new MethodLogger(this))
            {
                if (!CheckGraphSanity()) { return; }
                try
                {
                    // Initialise graphics
                    if (this.graphic != null)
                    {
                        this.graphic.Dispose();
                    }
                    if (this.Size.Height == 1 || this.Size.Width == 1)
                    {
                        this.graphic = null;
                        return;
                    }
                    this.graphic = this.CreateGraphics();
                    RectangleF rect = this.graphic.VisibleClipBounds;
                    rect.Inflate(new SizeF(-this.XMargin, -this.YMargin));
                    this.GraphRectangle = rect;

                    // Initialise transformation Matrix
                    this.IsInitialized = InitializeTransformMatrix();
                    if (this.IsInitialized)
                    {
                        this.alternateString = string.Empty;
                    }
                    this.BackgroundDirty = true;
                }
                catch (System.Exception exception)
                {
                    StockLog.Write(exception);
                }
            }
        }
 protected override void PaintGraphTitle(Graphics aGraphic)
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     string graphTitle = "PREVIEW ";
     this.DrawString(aGraphic, graphTitle, this.axisFont, Brushes.Black, this.backgroundBrush, new PointF(1, 1), true);
      }
 }
        protected override bool InitializeTransformMatrix()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (!CheckGraphSanity()) { return false; }
            if (this.GraphRectangle.Height > 0)
            {
               minValue = float.MaxValue;
               maxValue = float.MinValue;
               this.CurveList.GetMinMax(0, dateSerie.Length - 1, ref minValue, ref maxValue, this.ScaleInvisible);

               if (minValue == maxValue || minValue == float.MaxValue || float.IsNaN(minValue) || float.IsInfinity(minValue) || maxValue == float.MinValue || float.IsNaN(maxValue) || float.IsInfinity(maxValue))
               {
                  this.Deactivate("Input data is corrupted and cannot be displayed...", false);
                  return false;
               }

               if (this.IsLogScale && minValue > 0)
               {
                  minValue -= (maxValue - minValue) * 0.025f;
               }
               else
               {
                  minValue -= (maxValue - minValue) * 0.05f;
               }
               maxValue += (maxValue - minValue) * 0.05f;

               float tmpMinValue, tmpMaxValue;
               if (this.IsLogScale)
               {
                  tmpMinValue = minValue < 0 ? (float)-Math.Log10(-minValue + 1) : (float)Math.Log10(minValue + 1);
                  tmpMaxValue = maxValue < 0 ? (float)-Math.Log10(-maxValue + 1) : (float)Math.Log10(maxValue + 1);
               }
               else
               {
                  tmpMinValue = minValue;
                  tmpMaxValue = maxValue;
               }

               float coefX = (this.GraphRectangle.Width * 0.94f) / (dateSerie.Length - 1);
               float coefY = this.GraphRectangle.Height / (tmpMaxValue - tmpMinValue);

               matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
               matrixValueToScreen.Translate(this.GraphRectangle.X + 20, tmpMaxValue * coefY + this.GraphRectangle.Y);
               matrixValueToScreen.Scale(coefX, -coefY);

               matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
               matrixScreenToValue.Invert();
            }
            else
            {
               this.Deactivate("App too small...", false);
               return false;
            }
            return true;
             }
        }
        public override void ApplyTo(StockSerie stockSerie)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            List<StockDailyValue> dailyValues = stockSerie.GenerateHeikinAshiBarFromDaily(stockSerie.Values.ToList());
            FloatSerie upVolume = new FloatSerie(stockSerie.Count);
            FloatSerie downVolume = new FloatSerie(stockSerie.Count);

            int i = -1;
            foreach (StockDailyValue dailyValue in dailyValues)
            {
               i++;
               float R = dailyValue.HIGH - dailyValue.LOW; // Bar range

               float R2 = Math.Abs(dailyValue.CLOSE - dailyValue.OPEN); // Body range

               if (R == 0 || R2 == 0)
               {
                  upVolume[i] = downVolume[i] = dailyValue.VOLUME / 2L;
                  continue;
               }

               float R1 = dailyValue.HIGH - Math.Max(dailyValue.CLOSE, dailyValue.OPEN); // Higher shade range
               float R3 = Math.Min(dailyValue.CLOSE, dailyValue.OPEN) - dailyValue.LOW; // Lower shade range

               float V = dailyValue.VOLUME;
               float V1 = V * (R1 / R);
               float V2 = V * (R2 / R);
               float V3 = V * (R3 / R);

               if (dailyValue.CLOSE > dailyValue.OPEN) // UpBar
               {
                  upVolume[i] = V2 + (V1 + V3) / 2.0f;
                  downVolume[i] = V - upVolume[i];
               }
               else // DownBar
               {
                  downVolume[i] = V2 + (V1 + V3) / 2.0f;
                  upVolume[i] = V - downVolume[i];
               }

               //V = V(R1/R) + V(R2/R) + V(R3/R);

            }

            //FloatSerie upVolume = stockSerie.GetSerie(StockDataType.UPVOLUME).Sqrt();
            //FloatSerie downVolume = stockSerie.GetSerie(StockDataType.DOWNVOLUME).Sqrt();
            FloatSerie cumulVolume = (upVolume - downVolume).Cumul();
            FloatSerie diffVolume = (cumulVolume - cumulVolume.CalculateEMA((int)this.parameters[0])).CalculateEMA((int)this.parameters[1]);
            FloatSerie fastSerie = diffVolume;

            FloatSerie fastMom = fastSerie;
            this.series[0] = fastMom;
            this.Series[0].Name = this.Name;

            FloatSerie signalSerie = fastMom.CalculateEMA(((int)this.parameters[2]));
            this.series[1] = signalSerie;
            this.Series[1].Name = this.SerieNames[1];

            if (this.series[0] != null && this.Series[0].Count > 0)
            {
               this.CreateEventSeries(stockSerie.Count);

               FloatSerie upExLimit = new FloatSerie(stockSerie.Count, this.SerieNames[1]);
               FloatSerie downExLimit = new FloatSerie(stockSerie.Count, this.SerieNames[2]);
               FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH);
               FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW);

               FloatSerie indicatorToDecorate = this.Series[0];
               float exhaustionSellLimit = indicatorToDecorate[0];
               float exhaustionBuyLimit = indicatorToDecorate[0];
               float exhaustionBuyPrice = highSerie[0];
               float exhaustionSellPrice = lowSerie[0];
               float exFadeOut = (100.0f - (float)this.parameters[3]) / 100.0f;

               float previousValue = indicatorToDecorate[0];
               float currentValue;

               for (i = 1; i < indicatorToDecorate.Count - 1; i++)
               {
                  currentValue = indicatorToDecorate[i];

                  if (currentValue < previousValue)
                  {
                     if (indicatorToDecorate.IsBottom(i))
                     {
                        if (currentValue <= exhaustionSellLimit)
                        {
                           // This is an exhaustion selling
                           exhaustionSellPrice = lowSerie[i];
                           exhaustionSellLimit = currentValue;
                        }
                        else
                        {
                           exhaustionSellLimit *= exFadeOut;
                        }
                        exhaustionBuyLimit *= exFadeOut;
                     }
                     else
                     { // trail exhaustion limit down
                        exhaustionSellLimit = Math.Min(currentValue, exhaustionSellLimit);
                        exhaustionBuyLimit *= exFadeOut;
                     }
                  }
                  else if (currentValue > previousValue)
                  {
                     if (indicatorToDecorate.IsTop(i))
                     {
                        if (currentValue >= exhaustionBuyLimit)
                        {
                           // This is an exhaustion selling
                           exhaustionBuyPrice = highSerie[i];
                           exhaustionBuyLimit = currentValue;
                        }
                        else
                        {
                           exhaustionSellLimit *= exFadeOut;
                        }
                        exhaustionBuyLimit *= exFadeOut;
                     }
                     else
                     { // trail exhaustion limit up
                        exhaustionBuyLimit = Math.Max(currentValue, exhaustionBuyLimit);
                        exhaustionSellLimit *= exFadeOut;
                     }
                  }
                  else
                  {
                     exhaustionSellLimit *= exFadeOut;
                     exhaustionBuyLimit *= exFadeOut;
                  }
                  previousValue = currentValue;
                  upExLimit[i] = exhaustionBuyLimit;
                  downExLimit[i] = exhaustionSellLimit;
               }
               upExLimit[indicatorToDecorate.Count - 1] = exhaustionBuyLimit;
               downExLimit[indicatorToDecorate.Count - 1] = exhaustionSellLimit;
               this.series[2] = upExLimit;
               this.series[3] = downExLimit;

               //for ( i = 5; i < indicatorToDecorate.Count - 1; i++)
               //{
               //    this.eventSeries[0][i] = fastMom[i - 1] == upExLimit[i - 1] && fastMom[i] < fastMom[i - 1];
               //    this.eventSeries[1][i] = fastMom[i - 1] == downExLimit[i - 1] && fastMom[i] > fastMom[i - 1];
               //}
            }
            else
            {
               for (i = 0; i < this.SeriesCount; i++)
               {
                  this.Series[i] = new FloatSerie(0, this.SerieNames[i]);
               }
            }
            for (i = 0; i < stockSerie.Count; i++)
            {
               this.eventSeries[0][i] = fastMom[i] >= signalSerie[i];
               this.eventSeries[1][i] = fastMom[i] < signalSerie[i];
            }
             }
        }
Esempio n. 7
0
        protected virtual void DrawMousePos(int mouseIndex, int y)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (this.IsInitialized)
            {
               if (mouseIndex != -1 && CurveList.Count != 0 && this.mainSerie != null)
               {
                  // GetMarquee value
                  float value = this.mainSerie[mouseIndex];
                  PointF point = new PointF(mouseIndex, value);
                  PointF point2 = GetScreenPointFromValuePoint(point);
                  this.foregroundGraphic.DrawEllipse(mousePen, point2.X - MOUSE_MARQUEE_SIZE, point2.Y - MOUSE_MARQUEE_SIZE, MOUSE_MARQUEE_SIZE * 2, MOUSE_MARQUEE_SIZE * 2);

                  string valueString;
                  if (value > 100000000)
                  {
                     valueString = (value / 1000000).ToString("0.#") + "M";
                  }
                  else
                     if (value > 1000000)
                     {
                        valueString = (value / 1000).ToString("0.#") + "K";
                     }
                     else
                     {
                        valueString = value.ToString("0.##");
                     }
                  this.DrawString(this.foregroundGraphic, valueString, axisFont, textBrush, backgroundBrush, new PointF(GraphRectangle.Right + 2, point2.Y - 8), true);
               }
            }
             }
        }
Esempio n. 8
0
        public void Undo()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (currentActionIndex >= 0)
            {
               GraphAction action = this.GraphActions.ElementAt(this.currentActionIndex);
               switch (action.ActionType)
               {
                  case GraphActionType.AddItem:
                     this.drawingItems.Remove(action.TargetItem);
                     break;
                  case GraphActionType.DeleteItem:
                     this.drawingItems.Add(action.TargetItem);
                     break;
                  case GraphActionType.CutItem:
                     this.drawingItems.Add(action.TargetItem);
                     this.drawingItems.Remove(action.TargetItem2);
                     break;
                  default:
                     break;
               }
               currentActionIndex--;

               // Redraw
               BackgroundDirty = true; // The new line becomes a part of the background
            }
             }
        }
Esempio n. 9
0
 protected void PaintHorizontalLines(Graphics g)
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     if (this.horizontalLines != null)
     {
        foreach (HLine hLine in this.horizontalLines)
        {
           PointF levelPoint = this.GetScreenPointFromValuePoint(this.StartIndex, hLine.Level);
           g.DrawLine(hLine.LinePen, this.GraphRectangle.X, levelPoint.Y, this.GraphRectangle.Right, levelPoint.Y);
        }
     }
      }
 }
Esempio n. 10
0
 protected virtual void PaintGraphTitle(Graphics aGraphic)
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     bool first = true;
     string graphTitle = string.Empty;
     foreach (GraphCurveType curveType in this.CurveList)
     {
        if (curveType.IsVisible)
        {
           if (first)
           {
              graphTitle = curveType.DataSerie.Name;
              first = false;
           }
           else
           {
              graphTitle += "  " + curveType.ToString();
           }
        }
     }
     // Add indicators
     foreach (IStockIndicator stockIndicator in CurveList.Indicators)
     {
        graphTitle += "  " + stockIndicator.Name;
     }
     this.DrawString(aGraphic, graphTitle, this.axisFont, Brushes.Black, this.backgroundBrush, new PointF(1, 1), true);
      }
 }
Esempio n. 11
0
        protected virtual void PaintGraph()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (this.IsInitialized && this.graphic != null)
            {
               try
               {
                  // Draw the graph on the background image
                  if (BackgroundDirty)
                  {
                     // Create Bitmap graphicMain
                     backgroundBitmap = new Bitmap((int)this.graphic.VisibleClipBounds.Width, (int)this.graphic.VisibleClipBounds.Height, this.graphic);
                     Graphics tmpGraph = Graphics.FromImage(backgroundBitmap);

                     tmpGraph.Clear(this.backgroundColor);
                     PaintTmpGraph(tmpGraph);
                     PaintGraphTitle(tmpGraph);
                     PaintCopyright(tmpGraph);

                     // Draw background image
                     this.graphic.DrawImage(backgroundBitmap, 0, 0);

                     this.BackgroundDirty = false;
                     this.ForegroundDirty = true;
                  }
                  else
                  {
                     // Draw background image
                     this.graphic.DrawImage(backgroundBitmap, 0, 0);
                  }
               }
               catch (System.Exception e)
               {
                  this.Deactivate("Software Error: " + e.Message, false);
               }
            }
            else // Draw alternate text.
            {
               Graphics gr = this.CreateGraphics();
               gr.Clear(this.backgroundColor);
               gr.DrawString(this.alternateString, axisFont, Brushes.Black, 10, 20);
            }
             }
        }
Esempio n. 12
0
        protected virtual void PaintDailyBox(PointF mousePoint)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            string value = string.Empty;
            foreach (GraphCurveType curveType in this.CurveList)
            {
               if (curveType.IsVisible && !float.IsNaN(curveType.DataSerie[this.lastMouseIndex]))
               {
                  if (curveType.DataSerie.Name.Length > 6)
                  {
                     value += BuildTabbedString(curveType.DataSerie.Name, curveType.DataSerie[this.lastMouseIndex], 12) + "\r\n";
                  }
                  else
                  {
                     value += BuildTabbedString(curveType.DataSerie.Name, curveType.DataSerie[this.lastMouseIndex], 12) + "\r\n";
                  }
               }
            }
            // Add indicators
            foreach (IStockIndicator stockIndicator in CurveList.Indicators)
            {
               for (int i = 0; i < stockIndicator.SeriesCount; i++)
               {
                  if (stockIndicator.SerieVisibility[i] && stockIndicator.Series[i].Count > 0 && !float.IsNaN(stockIndicator.Series[i][this.lastMouseIndex]))
                  {
                     value += BuildTabbedString(stockIndicator.Series[i].Name, stockIndicator.Series[i][this.lastMouseIndex], 12) + "\r\n";
                  }
               }
            }
            // Remove last new line.
            if (value.Length != 0)
            {
               value = value.Remove(value.LastIndexOf("\r\n"));
            }
            if (!string.IsNullOrWhiteSpace(value))
            {
               using (Font font = new Font(new FontFamily(System.Drawing.Text.GenericFontFamilies.Monospace), 8))
               {
                  Size size = TextRenderer.MeasureText(value, font);

                  PointF point = new PointF(Math.Min(mousePoint.X + 10, GraphRectangle.Right - size.Width), GraphRectangle.Top + 5);

                  this.DrawString(this.foregroundGraphic, value, font, Brushes.Black, this.backgroundBrush, point, true);
               }
            }
             }
        }
Esempio n. 13
0
        protected override void OnSizeChanged(EventArgs e)
        {
            if (this.GetType().ToString() == "StockAnalyzerApp.CustomControl.GraphControls.GraphCloseControl")
             {
            if (this.alternateString == "App too small..." && this.FindForm().WindowState == FormWindowState.Normal)
            {
               this.Deactivate("", true);
            }
             }
             using (MethodLogger ml = new MethodLogger(this))
             {
            if (!CheckGraphSanity()) { return; }
            try
            {
               // Initialise graphics
               if (this.graphic != null)
               {
                  this.graphic.Dispose();
               }
               if (this.Size.Height == 1 || this.Size.Width == 1)
               {
                  this.graphic = null;
                  return;
               }
               this.graphic = this.CreateGraphics();
               RectangleF rect = this.graphic.VisibleClipBounds;
               rect.Inflate(new SizeF(-this.XMargin, -this.YMargin));
               this.GraphRectangle = rect;

               // Initialise transformation Matrix
               this.IsInitialized = InitializeTransformMatrix();
               if (this.IsInitialized)
               {
                  this.alternateString = string.Empty;
               }
               this.BackgroundDirty = true;
            }
            catch (System.Exception exception)
            {
               StockLog.Write(exception);
            }
             }
        }
Esempio n. 14
0
 protected override void OnPaintBackground(PaintEventArgs e)
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     PaintGraph();
      }
 }
Esempio n. 15
0
        protected virtual bool InitializeTransformMatrix()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (!CheckGraphSanity()) { return false; }
            if (this.StartIndex == this.EndIndex || this.EndIndex > this.dateSerie.Length - 1)
            {
               this.IsInitialized = false;
               InvalidSerieException e = new InvalidSerieException("Invalid input data range...");
               StockLog.Write(e);
               throw e;
            }
            if (this.GraphRectangle.Height > 0)
            {
               minValue = float.MaxValue;
               maxValue = float.MinValue;
               this.CurveList.GetMinMax(StartIndex, EndIndex, ref minValue, ref maxValue, this.ScaleInvisible);

               if (minValue == maxValue || minValue == float.MaxValue || float.IsNaN(minValue) || float.IsInfinity(minValue) || maxValue == float.MinValue || float.IsNaN(maxValue) || float.IsInfinity(maxValue))
               {
                  this.Deactivate("Input data is corrupted and cannot be displayed...", false);
                  return false;
               }

               if (this.IsLogScale && minValue > 0)
               {
                  minValue *= 0.95f;
               }
               else
               {
                  minValue -= (maxValue - minValue) * 0.1f;
               }
               maxValue += (maxValue - minValue) * 0.1f;

               float tmpMinValue, tmpMaxValue;
               if (this.IsLogScale)
               {
                  tmpMinValue = minValue < 0 ? (float)-Math.Log10(-minValue + 1) : (float)Math.Log10(minValue + 1);
                  tmpMaxValue = maxValue < 0 ? (float)-Math.Log10(-maxValue + 1) : (float)Math.Log10(maxValue + 1);
               }
               else
               {
                  tmpMinValue = minValue;
                  tmpMaxValue = maxValue;
               }

               float coefX = (this.GraphRectangle.Width * 0.96f) / (EndIndex - StartIndex);
               float coefY = this.GraphRectangle.Height / (tmpMaxValue - tmpMinValue);

               matrixValueToScreen = new System.Drawing.Drawing2D.Matrix();
               matrixValueToScreen.Translate(this.GraphRectangle.X - (StartIndex - 0.5f) * coefX, tmpMaxValue * coefY + this.GraphRectangle.Y);
               matrixValueToScreen.Scale(coefX, -coefY);

               matrixScreenToValue = (System.Drawing.Drawing2D.Matrix)matrixValueToScreen.Clone();
               matrixScreenToValue.Invert();
            }
            else
            {
               this.Deactivate("App too small...", false);
               return false;
            }
            return true;
             }
        }
Esempio n. 16
0
 public void PaintForeground()
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     if (this.graphic != null)
     {
        this.graphic.DrawImage(foregroundBitmap, 0, 0);
        this.ForegroundDirty = true;
     }
      }
 }
Esempio n. 17
0
 public void ResetDrawingMode()
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     this.DrawingMode = GraphDrawMode.Normal;
     this.DrawingStep = GraphDrawingStep.Done;
     selectedLineIndex = -1;
     this.ForegroundDirty = true;
      }
 }
Esempio n. 18
0
        protected virtual void PaintTmpGraph(Graphics aGraphic)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {

            #region Draw vertical lines
            if (this.ShowGrid)
            {
               DrawVerticalGridLines(aGraphic, false, this.StartIndex, this.EndIndex);
            }
            #endregion

            // Paint horizontal lines first
            this.PaintHorizontalLines(aGraphic);

            PointF[] points = null;
            int i = 0;
            #region DISPLAY INDICATORS
            this.mainSerie = null;
            foreach (IStockIndicator stockIndicator in CurveList.Indicators)
            {
               for (i = 0; i < stockIndicator.SeriesCount; i++)
               {
                  if (stockIndicator.SerieVisibility[i] && stockIndicator.Series[i].Count > 0)
                  {
                     points = GetScreenPoints(StartIndex, EndIndex, stockIndicator.Series[i]);
                     if (points != null)
                     {
                        // The first serie is the one to use for decorator if any. We make the best of this test to display the last value on the right
                        if (this.mainSerie == null)
                        {
                           this.mainSerie = stockIndicator.Series[i];
                           // Display values and dates
                           float lastValue = this.mainSerie.Last;
                           string lastValueString;
                           if (lastValue > 100000000)
                           {
                              lastValueString = (lastValue / 1000000).ToString("0.#") + "M";
                           }
                           else if (lastValue > 100000)
                           {
                              lastValueString = (lastValue / 1000).ToString("0.#") + "K";
                           }
                           else
                           {
                              lastValueString = lastValue.ToString("0.##");
                           }

                           aGraphic.DrawString(lastValueString, axisFont, Brushes.Black, GraphRectangle.Right + 1, Math.Max(points.Last().Y - 8, GraphRectangle.Top));
                        }
                        aGraphic.DrawLines(stockIndicator.SeriePens[i], points);
                     }
                  }
               }
            }
            #endregion
            #region DISPLAY DECORATORS
            if (CurveList.Decorator != null && this.mainSerie != null)
            {
               for (i = 0; i < CurveList.Decorator.SeriesCount; i++)
               {
                  if (CurveList.Decorator.SerieVisibility[i])
                  {
                     Pen pen = CurveList.Decorator.SeriePens[i];
                     using (Brush brush = new SolidBrush(pen.Color))
                     {
                        points = GetScreenPoints(StartIndex, EndIndex, CurveList.Decorator.Series[i]);
                        if (points != null)
                        {

                           aGraphic.DrawLines(CurveList.Decorator.SeriePens[i], points);
                        }
                     }
                  }
               }
               for (i = 0; i < CurveList.Decorator.EventCount; i++)
               {
                  if (CurveList.Decorator.EventVisibility[i] && CurveList.Decorator.IsEvent[i])
                  {
                     Pen pen = CurveList.Decorator.EventPens[i];
                     using (Brush brush = new SolidBrush(pen.Color))
                     {
                        BoolSerie decoSerie = CurveList.Decorator.Events[i];
                        for (int index = this.StartIndex; index <= this.EndIndex; index++)
                        {
                           if (decoSerie[index])
                           {
                              PointF point = new PointF(index, mainSerie[index]);
                              PointF point2 = GetScreenPointFromValuePoint(point);
                              aGraphic.FillEllipse(brush, point2.X - pen.Width * 1.5f, point2.Y - pen.Width * 1.5f, pen.Width * 3f, pen.Width * 3f);
                           }
                        }
                     }
                  }
               }
            }
            #endregion
             }
        }
Esempio n. 19
0
 protected bool CheckGraphSanity()
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     if (!this.IsInitialized || this.dateSerie == null)
     {
        if (string.IsNullOrWhiteSpace(this.alternateString))
        {
           this.Deactivate("Graph Not initialised", false);
        }
        return false;
     }
     if (this.CurveList == null || this.CurveList.GetNbVisible() == 0)
     {
        this.Deactivate("No data to display...", false);
        return false;
     }
     return true;
      }
 }
Esempio n. 20
0
 protected virtual void SetFrameMargin()
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     this.XMargin = MARGIN_SIZE * 2;
     this.YMargin = 0;
      }
 }
Esempio n. 21
0
        protected void DrawSelectionZone(System.Windows.Forms.MouseEventArgs e)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            int width = Math.Abs(e.Location.X - mouseDownPos.X);
            int height = Math.Abs(e.Location.Y - mouseDownPos.Y);
            int x = Math.Min(mouseDownPos.X, e.Location.X);
            int y = Math.Min(mouseDownPos.Y, e.Location.Y);

            // Retrieve the real values
            PointF initialValue = GetValuePointFromScreenPoint(mouseDownPos);
            PointF newValue = GetValuePointFromScreenPoint(e.Location);
            float variation = (newValue.Y - initialValue.Y) / initialValue.Y;

            // Draw selection zone and Finbonacci retracements
            float fiboY = 0.0f;
            if (e.Location.Y < mouseDownPos.Y)
            {
               // Draw selection zone
               this.foregroundGraphic.FillRectangle(greenBrush, x, y, width, height);
               this.foregroundGraphic.DrawRectangle(greenPen, x, y, width, height);

               // Draw Fibonacci
               if (height >= 30)
               {
                  foreach (float fibo in fibonacciRetracements)
                  {
                     fiboY = y + height * fibo;
                     string fiboString = fibo.ToString("P2");
                     this.DrawString(foregroundGraphic, fiboString, axisFont, Brushes.Green, this.backgroundBrush, x - 36, fiboY - 5, false);
                     if (fibo == 0.5f)
                     {
                        greenPen.Width = 2;
                     }
                     else
                     {
                        greenPen.Width = 1;
                     }
                     this.foregroundGraphic.DrawLine(greenPen, x, fiboY, x + width, fiboY);
                  }
               }
            }
            else
            {
               this.foregroundGraphic.FillRectangle(redBrush, x, y, width, height);
               this.foregroundGraphic.DrawRectangle(redPen, x, y, width, height);

               // Draw Fibonacci
               if (height >= 30)
               {
                  foreach (float fibo in fibonacciRetracements)
                  {
                     fiboY = y + height * (1.0f - fibo);
                     this.foregroundGraphic.DrawString(fibo.ToString("P2"), axisFont, Brushes.Red, x - 36, fiboY - 5);
                     if (fibo == 0.5f)
                     {
                        redPen.Width = 2;
                     }
                     else
                     {
                        redPen.Width = 1;
                     }
                     this.foregroundGraphic.DrawLine(redPen, x, fiboY, x + width, fiboY);
                  }
               }
            }
            // Display tooltip
            PointF fiboPoint = this.GetValuePointFromScreenPoint(0, e.Location.Y);
            this.DrawString(foregroundGraphic,
                "Bars:\t" + ((int)(newValue.X - initialValue.X)).ToString() + Environment.NewLine +
                "Value:\t" + fiboPoint.Y.ToString("#.###") + "   " + Environment.NewLine +
                "Var:\t" + variation.ToString("P2"),
                toolTipFont, Brushes.Black, this.backgroundBrush, new PointF(x + width + 4, y), true);

            // force the value box not to display.
            forceNoValueBoxDisplay = true;
             }
        }
Esempio n. 22
0
 public void Deactivate(string msg, bool setInitialisedTo)
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     StockLog.Write(msg);
     this.alternateString = msg;
     this.graphic = null;
     this.IsInitialized = setInitialisedTo;
     this.ForceRefresh();
      }
 }
        public override void ApplyTo(StockSerie stockSerie)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            FloatSerie fastMom = stockSerie.CalculateBuySellMomemtum((int)this.parameters[0], (bool)this.parameters[1]);
            this.series[0] = fastMom;
            this.Series[0].Name = this.Name;

            if (this.series[0] != null && this.Series[0].Count > 0)
            {
               this.CreateEventSeries(stockSerie.Count);

               FloatSerie upExLimit = new FloatSerie(stockSerie.Count, this.SerieNames[1]);
               FloatSerie downExLimit = new FloatSerie(stockSerie.Count, this.SerieNames[2]);
               FloatSerie highSerie = stockSerie.GetSerie(StockDataType.HIGH);
               FloatSerie lowSerie = stockSerie.GetSerie(StockDataType.LOW);
               for (int i = 1; i < this.SeriesCount; i++)
               {
                  this.Series[i] = new FloatSerie(stockSerie.Count, this.SerieNames[i]);
               }
               FloatSerie indicatorToDecorate = this.Series[0];
               float exhaustionSellLimit = indicatorToDecorate[0];
               float exhaustionBuyLimit = indicatorToDecorate[0];
               float exhaustionBuyPrice = highSerie[0];
               float exhaustionSellPrice = lowSerie[0];
               float exFadeOut = (100.0f - (float)this.parameters[2]) / 100.0f;

               float previousValue = indicatorToDecorate[0];
               float currentValue;

               for (int i = 1; i < indicatorToDecorate.Count - 1; i++)
               {
                  currentValue = indicatorToDecorate[i];

                  if (currentValue < previousValue)
                  {
                     if (indicatorToDecorate.IsBottom(i))
                     {
                        if (currentValue <= exhaustionSellLimit)
                        {
                           // This is an exhaustion selling
                           exhaustionSellPrice = lowSerie[i];
                           exhaustionSellLimit = currentValue;
                        }
                        else
                        {
                           exhaustionSellLimit *= exFadeOut;
                        }
                        exhaustionBuyLimit *= exFadeOut;
                     }
                     else
                     { // trail exhaustion limit down
                        exhaustionSellLimit = Math.Min(currentValue, exhaustionSellLimit);
                        exhaustionBuyLimit *= exFadeOut;
                     }
                  }
                  else if (currentValue > previousValue)
                  {
                     if (indicatorToDecorate.IsTop(i))
                     {
                        if (currentValue >= exhaustionBuyLimit)
                        {
                           // This is an exhaustion selling
                           exhaustionBuyPrice = highSerie[i];
                           exhaustionBuyLimit = currentValue;
                        }
                        else
                        {
                           exhaustionSellLimit *= exFadeOut;
                        }
                        exhaustionBuyLimit *= exFadeOut;
                     }
                     else
                     { // trail exhaustion limit up
                        exhaustionBuyLimit = Math.Max(currentValue, exhaustionBuyLimit);
                        exhaustionSellLimit *= exFadeOut;
                     }
                  }
                  else
                  {
                     exhaustionSellLimit *= exFadeOut;
                     exhaustionBuyLimit *= exFadeOut;
                  }
                  previousValue = currentValue;
                  upExLimit[i] = exhaustionBuyLimit;
                  downExLimit[i] = exhaustionSellLimit;
               }
               upExLimit[indicatorToDecorate.Count - 1] = exhaustionBuyLimit;
               downExLimit[indicatorToDecorate.Count - 1] = exhaustionSellLimit;
               this.series[1] = upExLimit;
               this.series[2] = downExLimit;

               for (int i = 5; i < indicatorToDecorate.Count - 1; i++)
               {
                  this.eventSeries[0][i] = fastMom[i - 1] == upExLimit[i - 1] && fastMom[i] < fastMom[i - 1];
                  this.eventSeries[1][i] = fastMom[i - 1] == downExLimit[i - 1] && fastMom[i] > fastMom[i - 1];
               }
            }
            else
            {
               for (int i = 0; i < this.SeriesCount; i++)
               {
                  this.Series[i] = new FloatSerie(0, this.SerieNames[i]);
               }
            }
             }
        }
Esempio n. 24
0
 public void ForceRefresh()
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     this.BackgroundDirty = true;
      }
 }
        protected override void PaintGraph()
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (this.IsInitialized && this.graphic != null)
            {
               //if (ForceNoRepaint) // Skip one go due to Windows crap refresh management
               //{
               //    ForceNoRepaint = false;
               //    return;
               //}
               // Draw the graph on the background image
               if (BackgroundDirty)
               {
                  // Create Bitmap graphicMain
                  backgroundBitmap = new Bitmap((int)this.graphic.VisibleClipBounds.Width, (int)this.graphic.VisibleClipBounds.Height, this.graphic);
                  Graphics tmpGraph = Graphics.FromImage(backgroundBitmap);

                  tmpGraph.Clear(this.BackgroundColor);
                  PaintTmpGraph(tmpGraph);
                  PaintGraphTitle(tmpGraph);

                  // Draw background image
                  this.graphic.DrawImage(backgroundBitmap, 0, 0);

                  this.ForegroundDirty = true;
                  this.BackgroundDirty = false;
               }
               else
               {
                  // Draw background image
                  this.graphic.DrawImage(backgroundBitmap, 0, 0);
               }
            }
            else // Draw alternate text.
            {
               Graphics gr = this.CreateGraphics();
               gr.Clear(SystemColors.ControlDark);
               gr.DrawString(this.alternateString, axisFont, Brushes.Black, 10, 10);
            }
             }
        }
Esempio n. 26
0
 public virtual void GraphControl_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     if (this.IsInitialized && !forceNoValueBoxDisplay)
     {
        PointF mousePoint = new PointF(e.X, e.Y);
        this.PaintDailyBox(mousePoint);
        this.PaintForeground();
     }
      }
 }
        protected override void PaintTmpGraph(Graphics aGraphic)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            #region Draw vertical lines
            if (this.ShowGrid)
            {
               DrawVerticalGridLines(aGraphic, false, 0, dateSerie.Length - 1);
            }
            #endregion

            int i = 0;
            Rectangle2D rect2D = new Rectangle2D(GraphRectangle);
            PointF[] points = null;
            foreach (GraphCurveType currentCurveType in CurveList)
            {
               if (currentCurveType.IsVisible)
               {
                  points = GetScreenPoints(0, dateSerie.Length - 1, currentCurveType.DataSerie);
                  if (points != null && points.Count() > 1)
                  {
                     aGraphic.DrawLines(currentCurveType.CurvePen, points);
                  }
               }
               i++;
            }

            this.DrawSliders(aGraphic);

            aGraphic.DrawRectangle(framePen, GraphRectangle.X, GraphRectangle.Y, GraphRectangle.Width, GraphRectangle.Height);
             }
        }
Esempio n. 28
0
        public void Initialize(GraphCurveTypeList curveList, List<HLine> horizontallines, DateTime[] dateSerie, string serieName, StockDrawingItems drawingItems, int startIndex, int endIndex)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            this.dateSerie = dateSerie;
            this.CurveList = curveList;
            this.StartIndex = startIndex;
            this.EndIndex = endIndex;
            this.serieName = serieName;
            this.drawingItems = drawingItems;
            this.horizontalLines = horizontallines;

            // Initialise undo buffer
            this.GraphActions = new List<GraphAction>();
            this.currentActionIndex = -1;

            // Initialise graphics
            this.graphic = this.CreateGraphics();
            RectangleF rect = this.graphic.VisibleClipBounds;
            rect.Inflate(new SizeF(-this.XMargin, -this.YMargin));
            this.GraphRectangle = rect;

            this.IsInitialized = true;
            this.alternateString = string.Empty;
             }
        }
Esempio n. 29
0
 public void ParseInputParameters(string[] parameters)
 {
     using (MethodLogger ml = new MethodLogger(this))
      {
     // Parse input parameters
     if (parameters.Length < this.ParameterCount)
     {
        StockLog.Write("Invalid input parameter number: " + parameters.Length + " expected: " + this.ParameterCount);
        StockLog.Write("Using default parameters");
     }
     for (int i = 0; i < parameters.Length; i++)
     {
        switch (this.ParameterTypes[i].Name)
        {
           case "Int32":
              int intParam;
              if (int.TryParse(parameters[i], out intParam))
              {
                 this.parameters[i] = intParam;
              }
              else
              {
                 throw new ArgumentException("Invalid input parameter: " + ParameterNames[i] + " type: " + this.ParameterTypes[i].ToString() + " expected");
              }
              break;
           case "Single":
              float floatParam;
              if (float.TryParse(parameters[i], NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign, CultureInfo.GetCultureInfo("en-US"), out floatParam))
              {
                 this.parameters[i] = floatParam;
              }
              else
              {
                 throw new ArgumentException("Invalid input parameter: " + ParameterNames[i] + " value: " + parameters[i] + " type: " + this.ParameterTypes[i].ToString() + " expected");
              }
              break;
           case "Boolean":
              bool boolParam;
              if (bool.TryParse(parameters[i], out boolParam))
              {
                 this.parameters[i] = boolParam;
              }
              else
              {
                 throw new ArgumentException("Invalid input parameter: " + ParameterNames[i] + " type: " + this.ParameterTypes[i].ToString() + " expected");
              }
              break;
           case "String":
              this.parameters[i] = parameters[i];
              break;
           case "StockSerie":
              this.parameters[i] = parameters[i];
              break;
           default:
              throw new NotImplementedException("This type is not yet implemented: " + this.ParameterTypes[i].ToString());
        }
     }
      }
 }
Esempio n. 30
0
        public virtual void MouseMoveOverControl(System.Windows.Forms.MouseEventArgs e, Keys key, bool mouseOverThis)
        {
            using (MethodLogger ml = new MethodLogger(this))
             {
            if (this.IsInitialized)
            {
               PointF mousePoint = new PointF(e.X, e.Y);
               if ((key & Keys.Control) != 0 && this.DrawingMode == GraphDrawMode.Normal)
               {
                  if (e.X > this.GraphRectangle.Left && e.X < this.GraphRectangle.Right)
                  {
                     DrawMouseCross(GetValuePointFromScreenPoint(mousePoint), mouseOverThis);
                     PaintForeground();
                  }
                  return;
               }

               if (!mouseOverThis) // Event come when the mouse moved over another control
               {
                  if (e.X > this.GraphRectangle.Left && e.X < this.GraphRectangle.Right)
                  {
                     // Refresh the mouse marquee
                     int currentMouseIndex = RoundToIndex(mousePoint);

                     // Display under mouse info
                     DrawMousePos(currentMouseIndex, e.Y);

                     lastMouseIndex = currentMouseIndex;
                     PaintForeground();
                  }
                  return;
               }
               else  // The mouse is moving over this control
               {
                  if (mouseDown)
                  {
                     DrawSelectionZone(e);
                  }
                  else
                  {
                     PointF mouseValuePoint = GetValuePointFromScreenPoint(mousePoint);
                     // Refresh the mouse marquee
                     int currentMouseIndex = RoundToIndex(mousePoint);

                     // Display under mouse info
                     DrawMousePos(currentMouseIndex, e.Y);

                     lastMouseIndex = currentMouseIndex;
                  }
               }
               this.PaintForeground();
            }
             }
        }