private void ProcessCandle(Candle candle)
        {
            if (ProcessState == ProcessStates.Stopping)
            {
                CancelActiveOrders();
                return;
            }

            this.AddInfoLog(LocalizedStrings.Str3634Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume, candle.Security));

            var trade = strategyTradesList.FirstOrDefault();

            strategyTradesList.Clear();

            var dict = new Dictionary <IChartElement, object>()
            {
                { strategyCandlesChart, candle },
                { strategyTradesChart, trade }
            };

            foreach (var elem in strategyIndicators)
            {
                dict.Add(elem.Item3, elem.Item2.GetCurrentValue());
            }

            strategyChart.Draw(candle.OpenTime, dict);
        }
예제 #2
0
        public static void Draw(this IChart chart, DateTimeOffset time, IDictionary <IChartElement, object> values)
        {
            if (chart == null)
            {
                throw new ArgumentNullException(nameof(chart));
            }

            chart.Draw(new[] { RefTuple.Create(time, values) });
        }
예제 #3
0
        private void ProcessCandle(Candle candle)
        {
            // strategy are stopping
            if (ProcessState == ProcessStates.Stopping)
            {
                CancelActiveOrders();
                return;
            }

            this.AddInfoLog(LocalizedStrings.Str3634Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume, candle.Security));

            // process new candle
            var longValue  = LongSma.Process(candle);
            var shortValue = ShortSma.Process(candle);

            // calc new values for short and long
            var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue();

            // crossing happened
            if (_isShortLessThenLong != isShortLessThenLong)
            {
                // if short less than long, the sale, otherwise buy
                var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy;

                // calc size for open position or revert
                var volume = Position == 0 ? Volume : Position.Abs().Min(Volume) * 2;

                // calc order price as a close price + offset
                var price = candle.ClosePrice + ((direction == Sides.Buy ? Security.PriceStep : -Security.PriceStep) ?? 1);

                RegisterOrder(this.CreateOrder(direction, price, volume));

                // or revert position via market quoting
                //var strategy = new MarketQuotingStrategy(direction, volume);
                //ChildStrategies.Add(strategy);

                // store current values for short and long
                _isShortLessThenLong = isShortLessThenLong;
            }

            var trade = _myTrades.FirstOrDefault();

            _myTrades.Clear();

            var data = new ChartDrawData();

            data
            .Group(candle.OpenTime)
            .Add(_candlesElem, candle)
            .Add(_shortElem, shortValue)
            .Add(_longElem, longValue)
            .Add(_tradesElem, trade);

            _chart.Draw(data);
        }
예제 #4
0
        public static void Draw(this IChart chart, DateTimeOffset time, IChartElement element, object value)
        {
            if (chart == null)
            {
                throw new ArgumentNullException(nameof(chart));
            }

            chart.Draw(time, new Dictionary <IChartElement, object> {
                { element, value }
            });
        }
예제 #5
0
 /// <summary>
 /// 描画処理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void GDIDrawSurface_Paint(object sender, PaintEventArgs e)
 {
     if (chart == null)
     {
         return;
     }
     //ここからグラフの更新
     drawContext.ClientRect = new RectangleF(0, 0, Width, Height);
     drawContext.PaintHandler(backSurfaceGraphics);
     chart.Draw(drawContext);
     e.Graphics.DrawImage(backSurface, new Point());
 }
예제 #6
0
        public static void Draw(this IChart chart, IEnumerable <RefPair <DateTimeOffset, IDictionary <IChartElement, object> > > values)
        {
            var data = chart.CreateData();

            foreach (var pair in values)
            {
                var item = data.Group(pair.First);

                foreach (var p in pair.Second)
                {
                    item.Add(p.Key, p.Value);
                }
            }

            chart.Draw(data);
        }
예제 #7
0
        /// <summary>
        /// To draw the candle.
        /// </summary>
        /// <param name="chart">Chart.</param>
        /// <param name="element">The chart element representing a candle.</param>
        /// <param name="candle">Candle.</param>
        public static void Draw(this IChart chart, IChartCandleElement element, Candle candle)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }

            if (candle == null)
            {
                throw new ArgumentNullException(nameof(candle));
            }

            var data = chart.CreateData();

            data
            .Group(candle.OpenTime)
            .Add(element, candle);

            chart.Draw(data);
        }
예제 #8
0
        private void ProcessCandle(Candle candle)
        {
            // strategy are stopping
            if (ProcessState == ProcessStates.Stopping)
            {
                CancelActiveOrders();
                return;
            }

            this.AddInfoLog(LocalizedStrings.Str3634Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume, candle.Security));

            // process new candle
            var longValue  = LongSma.Process(candle);
            var shortValue = ShortSma.Process(candle);

            // calc new values for short and long
            var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue();

            // crossing happened
            if (_isShortLessThenLong != isShortLessThenLong)
            {
                // if short less than long, the sale, otherwise buy
                var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy;

                // calc size for open position or revert
                var volume = Position == 0 ? Volume : Position.Abs().Min(Volume) * 2;

                if (!SafeGetConnector().RegisteredMarketDepths.Contains(Security))
                {
                    var price = Security.GetMarketPrice(Connector, direction);

                    // register "market" order (limit order with guaranteed execution price)
                    if (price != null)
                    {
                        RegisterOrder(this.CreateOrder(direction, price.Value, volume));
                    }
                }
                else
                {
                    // register order (limit order)
                    RegisterOrder(this.CreateOrder(direction, (decimal)(Security.GetCurrentPrice(this, direction) ?? 0), volume));

                    // or revert position via market quoting
                    //var strategy = new MarketQuotingStrategy(direction, volume)
                    //{
                    //	WaitAllTrades = true,
                    //};
                    //ChildStrategies.Add(strategy);
                }

                // store current values for short and long
                _isShortLessThenLong = isShortLessThenLong;
            }

            var trade = _myTrades.FirstOrDefault();

            _myTrades.Clear();

            var dict = new Dictionary <IChartElement, object>
            {
                { _candlesElem, candle },
                { _shortElem, shortValue },
                { _longElem, longValue },
                { _tradesElem, trade }
            };

            _chart.Draw(candle.OpenTime, dict);
        }
예제 #9
0
        private void ProcessCandle(Candle candle)
        {
            // если наша стратегия в процессе остановки
            if (ProcessState == ProcessStates.Stopping)
            {
                // отменяем активные заявки
                CancelActiveOrders();
                return;
            }

            this.AddInfoLog(LocalizedStrings.Str2177Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume));

            // добавляем новую свечу
            var longValue  = LongSma.Process(candle);
            var shortValue = ShortSma.Process(candle);

            // вычисляем новое положение относительно друг друга
            var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue();

            // если произошло пересечение
            if (_isShortLessThenLong != isShortLessThenLong)
            {
                // если короткая меньше чем длинная, то продажа, иначе, покупка.
                var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy;

                // вычисляем размер для открытия или переворота позы
                var volume = Position == 0 ? Volume : Position.Abs().Min(Volume) * 2;

                if (!SafeGetConnector().RegisteredMarketDepths.Contains(Security))
                {
                    var price = Security.GetMarketPrice(Connector, direction);

                    // регистрируем псевдо-маркетную заявку - лимитная заявка с ценой гарантирующей немедленное исполнение.
                    if (price != null)
                    {
                        RegisterOrder(this.CreateOrder(direction, price.Value, volume));
                    }
                }
                else
                {
                    // регистрируем заявку (обычным способом - лимитированной заявкой)
                    RegisterOrder(this.CreateOrder(direction, (decimal)(Security.GetCurrentPrice(this, direction) ?? 0), volume));

                    // переворачиваем позицию через котирование
                    //var strategy = new MarketQuotingStrategy(direction, volume)
                    //{
                    //	WaitAllTrades = true,
                    //};
                    //ChildStrategies.Add(strategy);
                }

                // запоминаем текущее положение относительно друг друга
                _isShortLessThenLong = isShortLessThenLong;
            }

            var trade = _myTrades.FirstOrDefault();

            _myTrades.Clear();

            var dict = new Dictionary <IChartElement, object>
            {
                { _candlesElem, candle },
                { _shortElem, shortValue },
                { _longElem, longValue },
                { _tradesElem, trade }
            };

            _chart.Draw(candle.OpenTime, dict);
        }
예제 #10
0
        private void ProcessCandle(Candle candle)
        {
            // если наша стратегия в процессе остановки
            if (ProcessState == ProcessStates.Stopping)
            {
                // отменяем активные заявки
                CancelActiveOrders();
                return;
            }

            this.AddInfoLog(LocalizedStrings.Str2177Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume));

            // добавляем новую свечу
            var longValue  = LongATR.Process(candle);
            var shortValue = ShortATR.Process(candle);

            if (Position < 0)
            {
                if (maxPrice > candle.ClosePrice)
                {
                    maxPrice = candle.ClosePrice;
                }
            }
            // вычисляем новое положение относительно друг друга
            // var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue();
            if (-maxPrice + candle.ClosePrice > protectLevel && needProtect)
            {
                var price = Security.GetMarketPrice(Connector, Sides.Buy);

                // регистрируем псевдо-маркетную заявку - лимитная заявка с ценой гарантирующей немедленное исполнение.
                if (price != null)
                {
                    RegisterOrder(this.CreateOrder(Sides.Buy, price.Value, Volume));
                    needProtect = false;
                }
            }
            // если индикаторы заполнились
            if (LongATR.Container.Count >= LongATR.Length)
            {
                if (LongATR.GetCurrentValue <int>() > ShortATR.GetCurrentValue <int>() && Position == 0)
                {
                    // если короткая меньше чем длинная, то продажа, иначе, покупка.
                    var direction = Sides.Sell;

                    // вычисляем размер для открытия или переворота позы
                    var volume = Volume;

                    if (!SafeGetConnector().RegisteredMarketDepths.Contains(Security))
                    {
                        var price = Security.GetMarketPrice(Connector, direction);

                        // регистрируем псевдо-маркетную заявку - лимитная заявка с ценой гарантирующей немедленное исполнение.
                        if (price != null)
                        {
                            RegisterOrder(this.CreateOrder(direction, price.Value, volume));
                            needProtect  = true;
                            protectLevel = LongATR.GetCurrentValue <int>() * 3;
                        }
                    }
                    else
                    {
                        // переворачиваем позицию через котирование
                        var strategy = new MarketQuotingStrategy(direction, volume)
                        {
                            WaitAllTrades = true,
                        };
                        ChildStrategies.Add(strategy);
                    }
                }
            }


            _myTrades.Clear();

            var dict = new Dictionary <IChartElement, object>
            {
                { _candlesElem, candle },
            };

            _chart.Draw(candle.OpenTime, dict);
        }
        public void OnSaveToPDFButtonClicked()
        {
            double? additionalMaterialQuantity = _view.AdditionalMaterialQuantity;
            bool additionalMaterialQuantityIsGreaterThanZeroAndSmallerThanOne100 = (additionalMaterialQuantity > 0 &&
                                                                                    additionalMaterialQuantity < 100);
            if ((!(additionalMaterialQuantity.HasValue && additionalMaterialQuantityIsGreaterThanZeroAndSmallerThanOne100))
                ||
                !_someCountingsFinished)
            {
                MessageBox.Show("Ilość materiału dodatkowego nie jest liczba z zakresu od 0 od 100.\nUpewnij się że przeprowadzono obliczenia.");
                return;
            }

            int widthForA4 = (int)((float)_view.DrawPanelWidth * 0.6);
            int heightForA4 = (int)((float)_view.DrawPanelHeight * 0.6);

            Bitmap bitmap = new Bitmap(widthForA4, heightForA4);

            _chart = new Chart(Graphics.FromImage(bitmap),
                _dataConnector.GetDeLongImages(),
                _dataConnector.GetDeLongChartSizingData());
            _chart.ResizeTo(widthForA4, heightForA4);
            _chart.Draw();
            CountPointsAndLinesPositionAndDraw();

            _dataConnector.SaveMainChartForPDF(bitmap);

            _chart = new Chart(Graphics.FromHwnd(_view.DrawPanelCanvas),
                _dataConnector.GetDeLongImages(),
                _dataConnector.GetDeLongChartSizingData());
            _chart.ResizeTo(_view.DrawPanelWidth, _view.DrawPanelHeight);
            _chart.Draw();
            CountPointsAndLinesPositionAndDraw();

            var schaefflerDeLongMinimapForm = new SchaefflerMinimapForm(MinimapCombination.SchaefflerDeLong, _view.AdditionalMaterialQuantity.Value, true);

            PdfGenerator = new PDFGenerator(PdfFor.DeLong, _dataConnector.GetFirstBasisMarerialForSchaeffler(), _dataConnector.GetSecondBasisMarerialForSchaeffler(), _dataConnector.GetAdditionalMaterialForSchaeffler(), (double)_view.AdditionalMaterialQuantity, "null", "null",_view.NewMaterialMicrophaseTextBox, _view.NewMaterialFerriteQuantityTextBox, _view.NewMaterialFerriteNumberTextBox, "null", "null");
        }