Вчерашние свечи в CandleManager
Atom
17.02.2011
KAX


Вчера интересовался тем как в candleManager получить вчерашние свечки. (Вопросы новичка)

Вариант экспорта портфеля на купайле, не понравился, поэтому вот мой велосипед:


using Ecng.Trading.Algo.Candles;
    using Ecng.Trading.BusinessEntities;
    using Ecng.Trading.Quik;

    public class CandleHistoryManager : CandleManager
    {
        private CultureInfo _culture;
        private IEnumerable<TimeFrameCandle> _history;
        public CandleHistoryManager(QuikTrader Quik)
            : base(Quik)
        {
            _culture = new CultureInfo(System.Threading.Thread.CurrentThread.CurrentCulture.Name) { NumberFormat = { NumberDecimalSeparator = "." } };

        }

        public IEnumerable<TimeFrameCandle> GetTimeFrameCandlesHistory(Security security, TimeSpan timeframe, int candleCount)
        {
            var candleList = base.GetTimeFrameCandles(security, timeframe, candleCount).ToList<TimeFrameCandle>();             
            if (candleList.Count < candleCount)
            {
                int diff = candleCount - candleList.Count;
                string fileName = String.Format("{0}.txt", security.Id);
                if (!File.Exists(fileName)) 
                {
                    return candleList;
                }
                if (_history == null)
                {
                    _history = File.ReadAllLines(fileName).Select(line =>
                        {
                            var parts = line.Split(',');
                            var time = DateTime.ParseExact(parts[0] + parts[1], "yyyyMMddHHmmss", _culture);
                            return new TimeFrameCandle
                            {
                                OpenPrice = double.Parse(parts[2], _culture),
                                HighPrice = double.Parse(parts[3], _culture),
                                LowPrice = double.Parse(parts[4], _culture),
                                ClosePrice = double.Parse(parts[5], _culture),
                                TimeFrame = timeframe,
                                Time = time,
                                TotalVolume = int.Parse(parts[6], _culture),
                                Security = security
                            };
                        });
                }
                var neededRange = _history.OrderBy(key => key.Time).ToList<TimeFrameCandle>().GetRange((_history.Count() - diff), diff);
                candleList.InsertRange(0, neededRange);
            }
            return candleList;
        } 

Собственно алгоритм простой, если количество запрашиваемых свечек больше чем есть, читаем данные из файла. Файл можно получить на финаме. Формат простой: Дата (ГГГГММДД), Время(ЧЧММСС), Open, High, Low, Close, Volume

скриншоты и немного воды тут: http://tradecommunity.ru/blog/stocksharp/41.html


Теги:


Спасибо: Mikhail Sukhov




Добавить файлы через драг-н-дроп, , или вставить из буфера обмена.

loading
clippy