Esempio n. 1
0
        private void _tabIndex_SpreadChangeEvent(List <Candle> candles)
        {
            if (Regime.ValueString == "Off")
            {
                return;
            }
            if (candles.Count < 0 || _tab1.IsConnected == false ||
                _tab2.IsConnected == false)
            {
                return;
            }
            if (_LastCandleTime != candles[candles.Count - 1].TimeStart)
            {
                _LastCandleTime = candles[candles.Count - 1].TimeStart;
            }
            else
            {
                return;
            }

            _envelop.Process(candles);
            _lastUp    = _envelop.ValuesUp.Last();
            _lastDown  = _envelop.ValuesDown.Last();
            _lastClose = candles.Last().Close;

            _lastMa1 = MaDay1.DataSeries[0].Values.Last();
            _lastMa2 = MaDay2.DataSeries[0].Values.Last();

            if (_lastUp == 0 || _lastDown == 0 || _lastClose == 0 || _lastMa1 == 0 || _lastMa2 == 0)
            {
                return;
            }

            List <Position> positions1 = _tab1.PositionsOpenAll;
            List <Position> positions2 = _tab2.PositionsOpenAll;

            decimal pr1  = _tab1.CandlesAll[_tab1.CandlesAll.Count - 1].Close;
            decimal pr2  = _tab2.CandlesAll[_tab2.CandlesAll.Count - 1].Close;
            decimal vol1 = GetVol(GetBalance(_tab1) / GetPrice(_tab1, pr1), 1);
            decimal vol2 = GetVol(GetBalance(_tab2) / GetPrice(_tab2, pr2), 2);

            if (vol1 == 0 || vol2 == 0)
            {
                return;
            }

            if (positions1.Count == 0 && positions2.Count == 0)
            {
                LogicOpenPosition();
            }
            else
            {
                LogicClosePosition(candles);
            }
        }
Esempio n. 2
0
        private void _tab_CandleFinishedEvent(List <Candle> candles)
        {
            if (stopPositions.Count != 0)
            {
                Filltabel_multi(null);
            }
            _tab.BuyAtStopCancel();
            _tab.SellAtStopCancel();
            CanselOldOrders();

            _envelop.Process(candles);
            _atr.Process(candles);
            _lastUp    = _envelop.ValuesUp[_envelop.ValuesUp.Count - 1];
            _lastDown  = _envelop.ValuesDown[_envelop.ValuesDown.Count - 1];
            _lastClose = candles.Last().Close;
            _lastAtr   = _atr.Values[_atr.Values.Count - 1];

            if (_LastCandleTime != candles[candles.Count - 1].TimeStart)
            {
                _LastCandleTime = candles[candles.Count - 1].TimeStart;
            }
            else
            {
                return;
            }
            if (!ValidateParams())
            {
                return;
            }

            LogicClosePOsition();

            if (Regime.ValueString == "OnlyClosePosition")
            {
                return;
            }

            if (CanTrade())
            {
                LogicOpenPosition(candles);
            }
        }
Esempio n. 3
0
        // trade logic
        private void Logic()
        {
            while (true)
            {
                Thread.Sleep(5 * 1000);
                if (!_tab.IsConnected)
                {
                    continue;
                }
                if (_tab.Connector.MyServer.ServerType == ServerType.Tester ||
                    _tab.Connector.MyServer.ServerType == ServerType.Optimizer)
                {
                    return;
                }


                if (_isDisposed)
                {
                    continue;
                }

                if (Regime.ValueString == "Off")
                {
                    continue;
                }

                if (_sma.Values == null ||
                    _sma.Lenght + 3 > _sma.Values.Count)
                {
                    continue;
                }

                if (_lastMa == 0 || _lastUp == 0 || _lastDown == 0)
                {
                    _envelop.Process(_tab.CandlesAll);
                    _lastUp   = _envelop.ValuesUp[_envelop.ValuesUp.Count - 1];
                    _lastDown = _envelop.ValuesDown[_envelop.ValuesDown.Count - 1];
                    _lastMa   = _sma.Values.Last();
                }
                if (_lastUp == 0 || _lastDown == 0)
                {
                    continue;
                }
                if (_tab.CandlesAll == null || _tab.CandlesAll.Count == 0)
                {
                    continue;
                }

                decimal spread    = GetSpread();
                decimal minspread = GetMinSpread();

                if (spread > minspread || _tab.PositionsOpenAll.Count > 1)
                {
                    CanselAllOrders();
                }

                if (spread <= minspread)
                {
                    List <Position> positions = _tab.PositionsOpenAll;
                    if (positions == null || positions.Count == 0)
                    {
                        LogicOpenPosition(_tab.CandlesAll);
                    }
                }
            }
        }