Exemplo n.º 1
0
        public void TestAddingToPLManager1()
        {
            LineDrawingManager manager  = new LineDrawingManager();
            PolyLine           polyLine = new PolyLine();

            polyLine.AddPoint(new System.Windows.Point(1, 3));
            polyLine.AddPoint(new System.Windows.Point(2, 4));
            manager.AddPl(polyLine);

            Assert.IsTrue(manager.Polylines.Contains(polyLine));
        }
Exemplo n.º 2
0
        public void TestAddingToPolyLine()
        {
            PolyLine polyLine = new PolyLine(null);

            polyLine.AddPoint(new System.Windows.Point(1, 3));
            Assert.IsTrue(polyLine.Pc.Contains(new System.Windows.Point(1, 3)));
        }
Exemplo n.º 3
0
        public void TestIOManager1()
        {
            List <PolyLine> lines    = new List <PolyLine>();
            string          path     = @"Data.xml";
            PolyLine        polyLine = new PolyLine();

            polyLine.AddPoint(new System.Windows.Point(1, 2));
            lines.Add(polyLine);
            PolyLineIOManager.Save(lines, path);
            FileStream fileStream = new FileStream(path, FileMode.Open);

            Assert.IsTrue(1 == 1);
        }
Exemplo n.º 4
0
        public void ParameterPlot(Func <double, PointD> Function, double start, double end, int slices, Action <PolyLine> PolyLineSetter = null)
        {
            #region 主要計算
            PolyLine polyline = new PolyLine();

            if (start > end)
            {
                double newEnd = start;
                start = end;
                end   = newEnd;
            }
            double dx = (end - start) / slices;
            if (Function != null)
            {
                for (double x = start; x <= end; x += dx)
                {
                    polyline.AddPoint(Function(x));
                }
                if (PolyLineSetter != null)
                {
                    PolyLineSetter(polyline);
                }
                else
                {
                    polyline.Color = System.Drawing.Color.LawnGreen;
                }
            }
            #endregion

            Action BeginPlot = () =>
            {
                #region
                if (Window != null)
                {
                    Window.View.AddSomeThing2Show(polyline);
                }
                #endregion
            };

            //因為牽扯到視窗元素,所以需委托應用程式的STA執行緒來執行
            Application.Current.Dispatcher.BeginInvoke(BeginPlot);
        }
Exemplo n.º 5
0
        private void Draw(double[] Xcoord, double[] Ycoord)
        {
            int id = ActiveLayer.GetLargestID();
            //int id = ActiveLayer.Elements.Count;
            //int id = 4;
            //int id = ActiveLayer.ElementKeys[ActiveLayer.ElementKeys.Count];
            //int id = ActiveLayer.Selection.ElementKeys.Count;
            //MessageBox.Show("Selected id = " + id.ToString(), "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);

            PolyLine pLine = ActiveLayer.Elements.GetElement(id).PolyLine;

            //MessageBox.Show("Selected element = " + ActiveLayer.Elements.GetElement(id).Key.ToString(), "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);

            pLine.Fill(4, ref Xcoord[0], ref Ycoord[0]);
            pLine.AddPoint(Xcoord[0], Ycoord[0]);

            //ActiveLayer.Elements.GetElement(ActiveLayer.ElementKeys[id]).SetPolyLine(pLine);

            #region debug
            MessageBox.Show(ActiveLayer.Elements.GetElement(ActiveLayer.ElementKeys[1]).SetPolyLine(pLine).ToString(), "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //MessageBox.Show(el.SetPolyLine(pLine).ToString(), "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            #endregion
        }
Exemplo n.º 6
0
        // додавання нових точок
        /// <summary>
        /// Canvas MouseRightButtonDown.
        /// </summary>
        /// <param name="sender">Just Object.</param>
        /// <param name="e">MouseButtonEventArgs e.</param>
        private void Canvas_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (this.CreationModeOn)
                {
                    Point p = Mouse.GetPosition(this);
                    if (p != null)
                    {
                        this.DrawingManager.Polylines.Last().AddPoint(p);
                    }
                }
                else
                {
                    PolyLine pl = new PolyLine();
                    Point    p  = Mouse.GetPosition(this);
                    if (p != null)
                    {
                        pl.AddPoint(p);
                        this.CreationModeOn = true;
                    }

                    this.DrawingManager.AddPl(pl);
                    this.doneButton.Visibility = Visibility.Visible;
                    this.editButton.IsEnabled  = false;
                }

                this.List.SelectedIndex = this.List.Items.Count - 1;
                this.List.Items.Refresh();
                this.LinesDrawer.Items.Refresh();
            }
            catch (Exception)
            {
                MessageBox.Show("Unexpected error occured");
            }
        }
Exemplo n.º 7
0
//===========================================================================
        protected override void NewBar()
        {   //_wprInd.ReInit();
            DTime = Bars[Bars.Range.To - 1].Time;
            ci    = Bars.Range.To - 1;
//===========================================================================
            if (first)
            {
                first = false;

                iFT = TimeToIndex(dt1, Timeframe);

                if (tu)
                {
                    nkz4  = Bars[iFT].High - ((NKZ - 5 - (NKZ * kf)) * Instrument.Point);
                    nkz2  = Bars[iFT].High - (((NKZ * 2) - (NKZ * 2 * kf)) * Instrument.Point);
                    nkz4v = Bars[iFT].High - ((NKZ - 5) * Instrument.Point);
                    nkz2v = Bars[iFT].High - ((NKZ * 2) * Instrument.Point);
                }
                if (td)
                {
                    nkz4  = Bars[iFT].Low + ((NKZ - 5 - (NKZ * kf)) * Instrument.Point);
                    nkz2  = Bars[iFT].Low + (((NKZ * 2) - (NKZ * 2 * kf)) * Instrument.Point);
                    nkz4v = Bars[iFT].Low + ((NKZ - 5) * Instrument.Point);
                    nkz2v = Bars[iFT].Low + (((NKZ * 2)) * Instrument.Point);
                }

                nkz4  = Math.Round(nkz4, Instrument.PriceScale);
                nkz2  = Math.Round(nkz2, Instrument.PriceScale);
                nkz4v = Math.Round(nkz4v, Instrument.PriceScale);
                nkz2v = Math.Round(nkz2v, Instrument.PriceScale);

                zmax = Bars[iFT].High;
                zmin = Bars[iFT].Low;

                toolPolyLine   = Tools.Create <PolyLine>(); toolPolyLine.Color = Color.Aqua;
                toolRectangle  = Tools.Create <Rectangle>(); toolRectangle.BorderColor = Color.Aqua; toolRectangle.Color = Color.DarkSeaGreen;
                toolRectangle1 = Tools.Create <Rectangle>(); toolRectangle1.BorderColor = Color.Aqua; toolRectangle1.Color = Color.DarkSeaGreen;

                toolPolyLine.AddPoint(new ChartPoint(Bars[iFT].Time, Bars[iFT].High));
                toolPolyLine.AddPoint(new ChartPoint(Bars[iFT].Time, nkz2v));

                toolRectangle.Point1 = new ChartPoint(Bars[iFT].Time, nkz4);
                toolRectangle.Point2 = new ChartPoint(Bars[Bars.Range.To - 1].Time.AddHours(24), nkz4v);

                toolRectangle1.Point1 = new ChartPoint(Bars[iFT].Time, nkz2);
                toolRectangle1.Point2 = new ChartPoint(Bars[Bars.Range.To - 1].Time.AddHours(24), nkz2v);
                Print("First - dt1={0} iFT={1}", dt1, iFT);
            }
//=== КОРЕКЦИЯ ====================================================================
            if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Closed)
            {
                posGuidBuy = Guid.Empty;
            }
            if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Closed)
            {
                posGuidSell = Guid.Empty;
            }
//=== Трелинг  =======================================================================================================================
            TrailActiveOrders();
//=== Сигналы =====================================================================
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] < 0 && _ftoInd.FisherSeries[Bars.Range.To - 1] > 0)
            {
                FsU = true;
            }
            else
            {
                FsU = false;
            }
            if (_ftoInd.FisherSeries[Bars.Range.To - 2] > 0 && _ftoInd.FisherSeries[Bars.Range.To - 1] < 0)
            {
                FsD = true;
            }
            else
            {
                FsD = false;
            }
            //== Касание зоны 1\4 ===============================
            if (tu && Bars[ci].Low < nkz4)
            {
                nu = true;
            }
            if (td && Bars[ci].High > nkz4)
            {
                nd = true;
            }
            //===== Зигзаг  =====================================
            if (_wprInd.MainIndicatorSeries[Bars.Range.To - 1] > 0)
            {
                zz3 = zz2;   zz2 = zz1;   zz1 = _wprInd.MainIndicatorSeries[Bars.Range.To - 1];
                if (zz3 < zz2 && zz2 > zz1)
                {
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                }                                                                                                    // ВВЕРХУ
                if (zz3 > zz2 && zz2 < zz1)
                {
                    zzd5 = zzd4; zzd4 = zzd3; zzd3 = zzd2; zzd2 = zzd1; zzd1 = zz2;
                }                                                                                                    // ВНИЗУ
            }
//=== Торговля ====================================================================

            if (posGuidBuy == Guid.Empty && tu && FsU && nu && Bars[ci].Low > nkz2)
            {
                var result107 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Buy, 0.1, Instrument.Bid, -1,
                                                         Stops.InPips(SL1, null), null, mgB);
                if (result107.IsSuccessful)
                {
                    posGuidBuy = result107.Position.Id;
                }
            }

            if (posGuidSell == Guid.Empty && td && FsD && nd && Bars[ci].High < nkz2)
            {
                var result207 = Trade.OpenMarketPosition(Instrument.Id, ExecutionRule.Sell, 0.1, Instrument.Ask, -1,
                                                         Stops.InPips(SL1, null), null, mgS);
                if (result207.IsSuccessful)
                {
                    posGuidSell = result207.Position.Id;
                }
            }
        }
Exemplo n.º 8
0
//===============================================================================================================================
        protected override void NewBar()
        {
            DTime = Bars[Bars.Range.To - 1].Time;
            ci    = Bars.Range.To - 1;
            if (first)
            {
                first = false;

                iFT = TimeToIndex(dt1, Timeframe);
                if (tu)
                {
                    nkz4  = Bars[iFT].High - ((NKZ - 5 - (NKZ * kf)) * Instrument.Point);
                    nkz2  = Bars[iFT].High - (((NKZ * 2) - (NKZ * 2 * kf)) * Instrument.Point);
                    nkz4v = Bars[iFT].High - ((NKZ - 5) * Instrument.Point);
                    nkz2v = Bars[iFT].High - ((NKZ * 2) * Instrument.Point);
                }
                if (td)
                {
                    nkz4  = Bars[iFT].Low + ((NKZ - 5 - (NKZ * kf)) * Instrument.Point);
                    nkz2  = Bars[iFT].Low + (((NKZ * 2) - (NKZ * 2 * kf)) * Instrument.Point);
                    nkz4v = Bars[iFT].Low + ((NKZ - 5) * Instrument.Point);
                    nkz2v = Bars[iFT].Low + (((NKZ * 2)) * Instrument.Point);
                }
                zmax = Bars[iFT].High;
                zmin = Bars[iFT].Low;
            }

            if (dt0 != dt1)
            {
                Tools.Remove(toolPolyLine);
                Tools.Remove(toolRectangle);
                Tools.Remove(toolRectangle1);

                nkz4  = Math.Round(nkz4, Instrument.PriceScale);
                nkz2  = Math.Round(nkz2, Instrument.PriceScale);
                nkz4v = Math.Round(nkz4v, Instrument.PriceScale);
                nkz2v = Math.Round(nkz2v, Instrument.PriceScale);

//=== КОРЕКЦИЯ ====================================================================
                if (posGuidBuy != Guid.Empty && Trade.GetPosition(posGuidBuy).State == PositionState.Closed)
                {
                    posGuidBuy = Guid.Empty;
                }
                if (posGuidSell != Guid.Empty && Trade.GetPosition(posGuidSell).State == PositionState.Closed)
                {
                    posGuidSell = Guid.Empty;
                }
//=== Трелинг  =======================================================================================================================
                TrailActiveOrders();
//=== Торговля ====================================================================
                if (posGuidBuy == Guid.Empty && tu)
                {
                    var result = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.BuyLimit, 0.1,
                                                           nkz4, 0,
                                                           Stops.InPips(250, null), null, null, mgB);
                    if (result.IsSuccessful)
                    {
                        posGuidBuy = result.Position.Id;
                    }
                }

                if (posGuidSell == Guid.Empty && td)
                {
                    var result1 = Trade.OpenPendingPosition(Instrument.Id, ExecutionRule.SellLimit, 0.1,
                                                            nkz4, 0,
                                                            Stops.InPips(250, null), null, null, mgS);
                    if (result1.IsSuccessful)
                    {
                        posGuidSell = result1.Position.Id;
                    }
                }


                toolPolyLine   = Tools.Create <PolyLine>(); toolPolyLine.Color = Color.Aqua;
                toolRectangle  = Tools.Create <Rectangle>(); toolRectangle.BorderColor = Color.Aqua; toolRectangle.Color = Color.DarkSeaGreen;
                toolRectangle1 = Tools.Create <Rectangle>(); toolRectangle1.BorderColor = Color.Aqua; toolRectangle1.Color = Color.DarkSeaGreen;

                toolPolyLine.AddPoint(new ChartPoint(Bars[iFT].Time, Bars[iFT].High));
                toolPolyLine.AddPoint(new ChartPoint(Bars[iFT].Time, nkz2v));

                toolRectangle.Point1 = new ChartPoint(Bars[iFT].Time, nkz4);
                toolRectangle.Point2 = new ChartPoint(Bars[Bars.Range.To - 1].Time.AddHours(24), nkz4v);

                toolRectangle1.Point1 = new ChartPoint(Bars[iFT].Time, nkz2);
                toolRectangle1.Point2 = new ChartPoint(Bars[Bars.Range.To - 1].Time.AddHours(24), nkz2v);

                dt0 = dt1;
            }
        }