Пример #1
0
        private List <float> GetTargetCandlesLengths(int candleLength)
        {
            var candlesM1 = AtomCandleStorage.Instance.GetAllMinuteCandles(chart.Symbol);

            if (candlesM1.Count < candleLength * 50)
            {
                return(null);
            }

            var packer = new CandlePacker(new BarSettings {
                Intervals = new List <int> {
                    candleLength
                }
            });
            var lengths = new List <float>();

            foreach (var cm1 in candlesM1)
            {
                var candle = packer.UpdateCandle(cm1);
                if (candle != null)
                {
                    lengths.Add((float)Math.Log(candle.close / candle.open));
                }
            }

            return(lengths);
        }
Пример #2
0
        public override void Initialize(RobotContext grobotContext, CurrentProtectedContext protectedContextx)
        {
            base.Initialize(grobotContext, protectedContextx);
            if (Graphics.Count == 0)
            {
                Logger.DebugFormat("IchimokuRobot: настройки графиков не заданы");
                return;
            }
            if (Graphics.Count > 1)
            {
                Logger.DebugFormat("IchimokuRobot: настройки графиков должны описывать один тикер / один ТФ");
                return;
            }

            mainCandlePacker = new CandlePacker(MainTimeFrame);
            dayCandlePacker  = new CandlePacker(dayTimeFrame);
            hourCandlePacker = new CandlePacker(hourTimeFrame);

            // размер этой очереди именно periodL + periodM. Это связано с тем, что рассчитать "облако" надо для "сдвинутой" назад точки, а не для текущей.
            // А что бы это сделать, нужно отступить от "сдвинутой назад точки" ещё на periodL.
            shiftBackPoints = new RestrictedQueue <CandleData>(periodL + periodM);

            subQueue = new[] { new RestrictedQueue <CandleData>(periodMSub1), new RestrictedQueue <CandleData>(periodMSub2) };

            happenIntersection = new RestrictedQueue <bool>(m);
            ticker             = Graphics[0].a;
        }
Пример #3
0
        public override void Initialize(BacktestServerProxy.RobotContext grobotContext, CurrentProtectedContext xprotectedContext)
        {
            base.Initialize(grobotContext, xprotectedContext);
            // проверка настроек графиков
            if (Graphics.Count == 0)
            {
                Logger.DebugFormat("MultiIndexRobot: настройки графиков не заданы");
                return;
            }
            if (Graphics.Count > 1)
            {
                Logger.DebugFormat("MultiIndexRobot: настройки графиков должны описывать один тикер / один ТФ");
                return;
            }
            ticker    = Graphics[0].a;
            timeframe = Graphics[0].b;

            lastBids = new Dictionary <string, double>();

            foreach (var ind in IndexList)
            {
                ind.Initialize();
                ind.lastIndicies = new List <double>();
                ind.indexPeaks   = new List <Cortege3 <decimal, int, decimal> >();
            }

            candles      = new List <CandleData>();
            packer       = new CandlePacker(Graphics[0].b);
            tickerNames  = DalSpot.Instance.GetTickerNames();
            randomGener  = new Random(DateTime.Now.Millisecond);
            lastBidLists = new Dictionary <string, List <double> >();
            // по каждой валютной паре найти макс. количество отсчетов (из формулы индекса)
            InitLastBidLists();
        }
Пример #4
0
        public void Setup()
        {
            var barSettings = new BarSettings {
                Intervals = new List <int> {
                    60
                }, Title = "H1"
            };

            packer = new CandlePacker(barSettings);
        }
Пример #5
0
        public override void Initialize(BacktestServerProxy.RobotContext grobotContext, CurrentProtectedContext protectedContext)
        {
            base.Initialize(grobotContext, protectedContext);
            // проверка настроек графиков
            if (Graphics.Count == 0)
            {
                Logger.DebugFormat("Atracotes MTS: настройки графиков не заданы");
                return;
            }
            if (Graphics.Count > 1)
            {
                Logger.DebugFormat("Atracotes MTS: настройки графиков должны описывать один тикер / один ТФ");
                return;
            }
            ticker = Graphics[0].a;

            lastBids = new Dictionary <string, double>();

            foreach (var ind in IndexList)
            {
                ind.Initialize();
                ind.lastIndicies = new List <double>();
                ind.indexPeaks   = new List <Cortege3 <decimal, int, decimal> >();
            }

            candles = new List <CandleData>();
            packer  = new CandlePacker(Graphics[0].b);

            var levels = FiboLevels.ToFloatArrayUniform();

            fiboLevels.Clear();
            foreach (var level in levels)
            {
                try
                {
                    fiboLevels.Add(level);
                }
                catch (FormatException)
                {
                }
            }

            tickerNames  = DalSpot.Instance.GetTickerNames();
            randomGener  = new Random(DateTime.Now.Millisecond);
            lastBidLists = new Dictionary <string, List <double> >();
            // по каждой валютной паре найти макс. количество отсчетов (из формулы индекса)
            InitLastBidLists();
            //RobotTradeState = TradeState.НетПозиций;
            stopsOnPositions = StopPositionsState.Незащищены;
            TerminalLog.Instance.SaveRobotLog("Atracotes MTS: RobotTradeState = " + RobotTradeState);
        }
Пример #6
0
 public override void Initialize(BacktestServerProxy.RobotContext robotContext, CurrentProtectedContext protectedContext)
 {
     base.Initialize(robotContext, protectedContext);
     if (Graphics.Count == 0)
     {
         return;
     }
     ticker    = Graphics[0].a;
     pointCost = DalSpot.Instance.GetAbsValue(ticker, 1f);
     if (BrickSizeAuto)
     {
         lastPrices = new RestrictedQueue <CandleData>(AutosizePeriod);
     }
     packer = new CandlePacker(Graphics[0].b);
 }
Пример #7
0
 public override void Initialize(BacktestServerProxy.RobotContext grobotContext, CurrentProtectedContext protectedContext)
 {
     base.Initialize(grobotContext, protectedContext);
     // проверка настроек графиков
     if (Graphics.Count == 0)
     {
         Logger.DebugFormat("StopRobot: настройки графиков не заданы");
         return;
     }
     if (Graphics.Count > 1)
     {
         Logger.DebugFormat("StopRobot: настройки графиков должны описывать один тикер / один ТФ");
         return;
     }
     ticker = Graphics[0].a;
     packer = new CandlePacker(Graphics[0].b);
 }
Пример #8
0
        private List <CandleData> MakeCandlesFromM1(BarSettings timeframe, string ticker, DateTime timeStart)
        {
            var result  = new List <CandleData>();
            var minutes = candles[barSettingsCodeM1][ticker];
            var packer  = new CandlePacker(timeframe);

            foreach (var canM1 in minutes)
            {
                var candle = packer.UpdateCandle(canM1);
                if (candle != null)
                {
                    result.Add(candle);
                }
            }

            return(result.Where(c => c.timeOpen >= timeStart).ToList());
        }
Пример #9
0
        /// <summary>
        /// упаковать котировки в свечки
        /// </summary>
        public void UpdateCandles(List <CandleData> minuteCandles)
        {
            chart.StockSeries.Data.Clear();
            // родной интервал равен m1 - не производить никаких действий
            if (Timeframe.IsAtomic)
            {
                foreach (var candle in minuteCandles)
                {
                    chart.StockSeries.Data.Candles.Add(new CandleData(candle));
                }
                return;
            }

            // упаковать m1 в свечи нужного ТФ
            candlePacker = new CandlePacker(chart.Timeframe);
            foreach (var minuteCandle in minuteCandles)
            {
                // фильтровать выходные дни
                if (chart.Timeframe.Intervals[0] == 1440 &&
                    !WorkingDay.Instance.IsWorkingDay(minuteCandle.timeOpen))
                {
                    continue;
                }

                var candle = candlePacker.UpdateCandle(minuteCandle);
                if (candle != null)
                {
                    chart.StockSeries.Data.Candles.Add(candle);
                }
            }
            // добавить незавершенную свечу
            var shouldAdd = true;

            if (chart.StockSeries.Data.Candles.Count > 0)
            {
                if (chart.StockSeries.Data.Candles[chart.StockSeries.Data.Candles.Count - 1].timeOpen ==
                    candlePacker.CurrentCandle.timeOpen)
                {
                    shouldAdd = false;
                }
            }
            if (shouldAdd && candlePacker.CurrentCandle != null)
            {
                chart.StockSeries.Data.Candles.Add(candlePacker.CurrentCandle);
            }
        }
Пример #10
0
        private List <CandleData> GetCandles(string symbol, BarSettings timeframe)
        {
            var startTime = timeframe.GetDistanceTime(CandlesForScreenshot, -1, nowTime);
            var stream    = robotContext.GetMinuteCandlesPacked(symbol, startTime, nowTime);
            var packer    = new CandlePacker(timeframe);
            var candles   = new List <CandleData>(CandlesForScreenshot + 1);

            foreach (var quote in stream.GetCandles())
            {
                var candle = packer.UpdateCandle(quote.close, quote.timeOpen.AddMinutes(1));
                if (candle != null)
                {
                    candles.Add(candle);
                }
            }
            return(candles);
        }
Пример #11
0
 public override void Initialize(BacktestServerProxy.RobotContext grobotContext,
                                 Contract.Util.BL.CurrentProtectedContext protectedContextx)
 {
     base.Initialize(grobotContext, protectedContextx);
     if (Graphics.Count == 0)
     {
         Logger.DebugFormat("TailBodyRobot: настройки графиков не заданы");
         return;
     }
     if (Graphics.Count > 1)
     {
         Logger.DebugFormat("TailBodyRobot: настройки графиков должны описывать один тикер / один ТФ");
         return;
     }
     packer    = new CandlePacker(Graphics[0].b);
     ticker    = Graphics[0].a;
     pointCost = 1.0 / DalSpot.Instance.GetPrecision10(ticker);
 }
Пример #12
0
 public override void Initialize(BacktestServerProxy.RobotContext grobotContext,
                                 Contract.Util.BL.CurrentProtectedContext protectedContextx)
 {
     base.Initialize(grobotContext, protectedContextx);
     if (Graphics.Count == 0)
     {
         Logger.DebugFormat("CaymanRobot: настройки графиков не заданы");
         return;
     }
     if (Graphics.Count > 1)
     {
         Logger.DebugFormat("CaymanRobot: настройки графиков должны описывать один тикер / один ТФ");
         return;
     }
     packer = new CandlePacker(Graphics[0].b);
     ticker = Graphics[0].a;
     ReadCaymanHistory();
 }
Пример #13
0
 public override void Initialize(BacktestServerProxy.RobotContext grobotContext, CurrentProtectedContext protectedContext)
 {
     base.Initialize(grobotContext, protectedContext);
     // проверка настроек графиков
     if (Graphics.Count == 0)
     {
         Logger.DebugFormat("FibonacciRobot: настройки графиков не заданы");
         return;
     }
     if (Graphics.Count > 1)
     {
         Logger.DebugFormat("FibonacciRobot: настройки графиков должны описывать один тикер / один ТФ");
         return;
     }
     ticker     = Graphics[0].a;
     packer     = new CandlePacker(Graphics[0].b);
     candles    = new List <CandleData>();
     pointPrice = 1M / DalSpot.Instance.GetPrecision10(ticker);
     //fiboDistanceAbs = FiboReachDistancePoint*pointPrice;
     markedZigZagPivots = new List <int>();
 }
Пример #14
0
        public override void Initialize(BacktestServerProxy.RobotContext grobotContext, Contract.Util.BL.CurrentProtectedContext protectedContextx)
        {
            base.Initialize(grobotContext, protectedContextx);
            if (Graphics.Count == 0)
            {
                Logger.DebugFormat("RobotMA: настройки графиков не заданы");
                return;
            }
            if (Graphics.Count > 1)
            {
                Logger.DebugFormat("RobotMA: настройки графиков должны описывать один тикер / один ТФ");
                return;
            }
            packer     = new CandlePacker(Graphics[0].b);
            ticker     = Graphics[0].a;
            stopLoss   = null;
            takeProfit = null;


            extremumRangeQueue = new RestrictedQueue <CandleData>(ExtremumRange * 2 + 1);
            extremumQueue      = new RestrictedQueue <Cortege3 <float, bool, DateTime> >(4);
        }
Пример #15
0
        public override void Initialize(BacktestServerProxy.RobotContext grobotContext)
        {
            base.Initialize(grobotContext);
            // проверка настроек графиков
            if (Graphics.Count == 0)
            {
                Logger.DebugFormat("OscillatorBasedRobot: настройки графиков не заданы");
                return;
            }
            if (Graphics.Count > 1)
            {
                Logger.DebugFormat("OscillatorBasedRobot: настройки графиков должны описывать один тикер / один ТФ");
                return;
            }
            ticker = Graphics[0].a;

            try
            {
                formulaResolver      = new ExpressionResolver(indexFormula);
                formulaVariableNames = formulaResolver.GetVariableNames();
                lastBids             = new Dictionary <string, float>();
                lastIndicies         = new RestrictedQueue <float>(CandlesInIndexHistory);
                candles      = new RestrictedQueue <CandleData>(CandlesInIndexHistory);
                packer       = new CandlePacker(Graphics[0].b);
                indexPeaks   = new List <Cortege3 <float, int, float> >();
                tickerNames  = DalSpot.Instance.GetTickerNames();
                randomGener  = new Random(DateTime.Now.Millisecond);
                lastBidLists = new Dictionary <string, RestrictedQueue <float> >();
                // по каждой валютной паре найти макс. количество отсчетов (из формулы индекса)
                InitLastBidLists();
            }
            catch (Exception ex)
            {
                Logger.ErrorFormat("OscillatorBasedRobot: ошибка парсинга выражения \"{0}\": {1}",
                                   indexFormula, ex);
                formulaResolver = null;
            }
        }
Пример #16
0
        public void TestGetLastCandleClose()
        {
            packer = new CandlePacker(new BarSettings()
            {
                Intervals = new EditableList <int> {
                    5
                }
            });

            DateTime candleOpenTime;
            int      nextCandlePeriod;
            var      time      = new DateTime(2014, 6, 18, 9, 5, 0);
            var      timeClose = packer.GetLastCandleClose(time, out candleOpenTime, out nextCandlePeriod);

            Assert.AreEqual(time, candleOpenTime, "GetLastCandleClose() - время начала свечи должно быть равно текущему");
            Assert.AreEqual(time.AddMinutes(5), timeClose, "GetLastCandleClose() - время закрытия свечи должно быть равно текущему + 5 минут");

            var timeShifted = new DateTime(2014, 6, 18, 9, 5, 0, 10, DateTimeKind.Unspecified);

            timeClose = packer.GetLastCandleClose(timeShifted, out candleOpenTime, out nextCandlePeriod);
            Assert.AreEqual(time, candleOpenTime, "GetLastCandleClose(+10ms) - время начала свечи должно быть равно текущему");
            Assert.AreEqual(time.AddMinutes(5), timeClose, "GetLastCandleClose(+10ms) - время закрытия свечи должно быть равно текущему + 5 минут");
        }
Пример #17
0
        public override void Initialize(BacktestServerProxy.RobotContext grobotContext, CurrentProtectedContext protectedContextx)
        {
            base.Initialize(grobotContext, protectedContextx);
            if (Graphics.Count == 0)
            {
                Logger.DebugFormat("RobotMA: настройки графиков не заданы");
                return;
            }
            if (Graphics.Count > 1)
            {
                Logger.DebugFormat("RobotMA: настройки графиков должны описывать один тикер / один ТФ");
                return;
            }
            packer    = new CandlePacker(Graphics[0].b);
            ticker    = Graphics[0].a;
            maDifSign = 0;
            queueSlow = new RestrictedQueue <float>(RangeSlowMA);
            queueFast = new RestrictedQueue <float>(RangeFastMA);

            virtualDeal    = null;
            prevSign       = 0;
            virtualResults = new RestrictedQueue <float>(PeriodVirtualResults);
        }
Пример #18
0
        private void PackCandles()
        {
            // длина хвостика, измеренная на 1-й, второй, ... час
            tailLengthByHour = tailHours.ToDictionary(h => h, h => new List <decimal>());

            var allCandles = AtomCandleStorage.Instance.GetAllMinuteCandles(chart.Symbol);

            minuteCandles = allCandles.SkipWhile(c => c.timeOpen < startTime).ToList();
            var packer = new CandlePacker(new BarSettings {
                Intervals = new List <int> {
                    1440
                }
            });

            dailyCandles = new List <CandleData>();
            pointCost    = DalSpot.Instance.GetPrecision10(chart.Symbol);

            var highOnHour = tailHours.ToDictionary(h => h, h => 0M);
            var lowOnHour  = tailHours.ToDictionary(h => h, h => 0M);

            foreach (var c in minuteCandles)
            {
                var candle = packer.UpdateCandle(c);
                var hour   = c.timeClose.Hour;

                if (candle != null)
                {
                    dailyCandles.Add(candle);
                    // заполнить "дырки" в часах
                    for (var i = tailHours.Length - 2; i <= 0; i--)
                    {
                        if (highOnHour[tailHours[i]] == 0)
                        {
                            highOnHour[tailHours[i]] = highOnHour[tailHours[i + 1]];
                        }
                        if (lowOnHour[tailHours[i]] == 0)
                        {
                            lowOnHour[tailHours[i]] = lowOnHour[tailHours[i + 1]];
                        }
                    }
                    // заполнить массив "хвостиков"
                    foreach (var h in tailHours)
                    {
                        var tailList = tailLengthByHour[h];
                        if (candle.open < candle.close)
                        {
                            tailList.Add(((decimal)candle.open - lowOnHour[h]) * pointCost);
                        }
                        else
                        {
                            tailList.Add((highOnHour[h] - (decimal)candle.open) * pointCost);
                        }
                    }
                    // обнулить хвостики
                    foreach (var h in tailHours)
                    {
                        highOnHour[h] = 0;
                        lowOnHour[h]  = 0;
                    }
                }

                foreach (var tailHour in tailHours)
                {
                    if (hour >= tailHour)
                    {
                        continue;
                    }
                    if ((decimal)c.high > highOnHour[tailHour] || highOnHour[tailHour] == 0)
                    {
                        highOnHour[tailHour] = (decimal)c.high;
                    }
                    if ((decimal)c.low < lowOnHour[tailHour] || lowOnHour[tailHour] == 0)
                    {
                        lowOnHour[tailHour] = (decimal)c.low;
                    }
                }
            }
        }