Exemplo n.º 1
0
        public bool ReadCandlesFromFile(CandleByTicker candles, string path, out int timeframe)
        {
            timeframe = 0;
            using (var sr = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                var header = sr.ReadStruct<HstFileHeader>();
                if (!header.HasValue)
                    return false;
                var mt4StartDate = new DateTime(1970, 1, 1);
                timeframe = header.Value.period;

                while (true)
                {
                    var record = sr.ReadStruct<HstFileRecord>();
                    if (!record.HasValue) break;

                    var candle = new CandleData
                    {
                        timeOpen = mt4StartDate.AddSeconds(record.Value.ctm),
                        open = (float)record.Value.open,
                        high = (float)record.Value.high,
                        low = (float)record.Value.low,
                        close = (float)record.Value.close
                    };
                    candle.timeClose = candle.timeOpen.AddMinutes(candles.Timeframe);
                    candles.candles.Add(candle);
                }
            }
            if (candles.candles.Count > 0)
                candles.StartTime = candles.candles.Min(c => c.timeOpen);

            return true;
        }
Exemplo n.º 2
0
        public void load(string FileName)
        {
            FileStream FileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read);
            this.header = FileStream.ReadStruct<Header>();

            if (this.header.revision >= 3)
            {
                this.headerExtraRevision3 = FileStream.ReadStruct<HeaderRevision3>();
            }

            FileStream.ReadStructVector(ref dimensionTable, header.TableDimLength);
            FileStream.ReadStructVector(ref xAdjustTable, header.TableXAdjustLength);
            FileStream.ReadStructVector(ref yAdjustTable, header.TableYAdjustLength);
            FileStream.ReadStructVector(ref advanceTable, header.TableAdvanceLength);

            packedShadowCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(header.TableShadowMapLength * header.TableShadowMapBpe));

            if (header.revision == 3)
            {
                FileStream.ReadStructVector(ref charmapCompressionTable1, headerExtraRevision3.TableCompCharMapLength1);
                FileStream.ReadStructVector(ref charmapCompressionTable2, headerExtraRevision3.TableCompCharMapLength2);
            }

            packedCharMap = FileStream.ReadBytes(BitsToBytesHighAligned(header.TableCharMapLength * header.TableCharMapBpe));
            packedCharPointerTable = FileStream.ReadBytes(BitsToBytesHighAligned(header.TableCharPointerLength * header.TableCharPointerBpe));

            /*
            int BytesLeft = (int)(FileStream.Length - FileStream.Position);
            charData = new byte[BytesLeft];
            FileStream.Read(charData, 0, BytesLeft);
            */

            charData = FileStream.ReadBytes((int)(FileStream.Length - FileStream.Position));

            var NumberOfCharacters = header.TableCharPointerLength;

            charMap = new int[header.lastGlyph + 1];
            charPointer = new int[NumberOfCharacters];
            Glyphs = new Glyph[NumberOfCharacters];
            reverseCharMap = new Dictionary<int, int>();

            foreach (var Pair in BitReader.FixedBitReader(packedShadowCharMap, header.TableShadowMapBpe))
            {
                var UnicodeIndex = (int)Pair.Key + header.firstGlyph;
                var GlyphIndex = (int)Pair.Value;
                shadowCharMap[UnicodeIndex] = GlyphIndex;
                reverseShadowCharMap[GlyphIndex] = UnicodeIndex;
            }

            foreach (var Pair in BitReader.FixedBitReader(packedCharMap, header.TableCharMapBpe))
            {
                var UnicodeIndex = (int)Pair.Key + header.firstGlyph;
                var GlyphIndex = (int)Pair.Value;
                charMap[UnicodeIndex] = GlyphIndex;
                reverseCharMap[GlyphIndex] = UnicodeIndex;
            }

            foreach (var Pair in BitReader.FixedBitReader(packedCharPointerTable, header.TableCharPointerBpe))
            {
                charPointer[Pair.Key] = (int)Pair.Value;
            }

            /*
            for (int n = 0; n < NumberOfCharacters; n++)
            {
                Glyphs[n] = new Glyph().Read(this, n);
            }
            */

            Console.WriteLine(this.header.fontName);

            /*
            Console.WriteLine(this.header.fontName);
            for (int n = 0; n < 300; n++)
            {
                Console.WriteLine(GetGlyphId((char)n));
            }
            */
        }