コード例 #1
0
 public BarToOtherBarHandler(IAccount account, MarketSeries series)
 {
     this.MarketSeries = series;
     this.Account      = account;
     m1     = series.Symbol.GetMarketSeries(TimeFrame.m1);
     logger = this.GetLogger();
 }
コード例 #2
0
        public static double MaximumOffset(this MarketSeries series, int periods, int offset = 2)
        {
            var    s   = series.High;
            double max = double.MinValue;

            for (int i = offset; i < periods; i++)
            {
                var val = s.Last(i);
                if (val > max)
                {
                    max = val;
                }
            }
            return(max);
        }
コード例 #3
0
        public static double MinimumOffset(this MarketSeries series, int periods, int offset = 2)
        {
            var    s   = series.Low;
            double min = double.MaxValue;

            for (int i = offset; i < periods; i++)
            {
                var val = s.Last(i);
                if (val < min)
                {
                    min = val;
                }
            }
            return(min);
        }
コード例 #4
0
ファイル: MarketSeries.cs プロジェクト: Mendelone/Trading
        public static MarketSeries ImportFromFile(string symbolCode, TimeFrame timeFrame, string path, DateTime?startDate = null, DateTime?endDate = null)
        {
            var series = new MarketSeries(null, symbolCode, timeFrame);

            series.ImportFromFile(path, startDate, endDate);
            GC.Collect();

            if (series != null && series.OpenTime.Count > 0)
            {
                Console.WriteLine($"Imported {timeFrame} {symbolCode} ({series.OpenTime.Count} data points from {series.OpenTime[0]} to {series.OpenTime.LastValue})");
            }
            else
            {
                Console.WriteLine($"Could not import {timeFrame} {symbolCode}");
            }
            return(series);
        }
コード例 #5
0
        private void RaiseTimeFrameBar(TimedBar bar, bool finishedBar = true)
        {
            lock (M1BarToTimeFrameBarLock)
            {
                //var bar = tickToMinuteBars[symbolCode];
                if (!bar.IsValid)
                {
                    return;
                }

                var partial = finishedBar ? "" : " PARTIAL";
                Debug.WriteLine($"[M1 to {MarketSeries.ToString()}] {bar}{partial}");

                ((IMarketSeriesInternal)this.MarketSeries).OnBar(bar, finishedBar);

                bar = TimedBar.New;
            }
        }
コード例 #6
0
        public MarketSeries GetMarketSeries(string symbolCode, TimeFrame timeFrame, DateTime?startDate = null, DateTime?endDate = null)
        {
            string file = null;

            if (!Directory.Exists(RootDir))
            {
                throw new ArgumentException($"Historical data source directory missing: {RootDir}");
            }

            file = Path.Combine(RootDir, symbolCode + "_" + timeFrame.Name.ToUpper() + "_UTC+0_00.csv");

            if (!File.Exists(file))
            {
                file = null;

                var dir = SymbolTimeFrameDir(symbolCode, timeFrame);
                if (!Directory.Exists(dir))
                {
                    return(null);
                }

                long   longestLength = -1;
                string longestPath   = null;
                foreach (var path in Directory.GetFiles(dir, "*.csv"))
                {
                    var length = new FileInfo(path).Length;
                    if (length > longestLength)
                    {
                        longestLength = length;
                        longestPath   = path;
                    }
                }

                if (longestPath == null)
                {
                    return(null);
                }

                file = longestPath;
            }

            return(MarketSeries.ImportFromFile(symbolCode, timeFrame, file, startDate, endDate));
        }
コード例 #7
0
        public static DataSeriesType GetDataSeries(this MarketSeries marketSeries, BarComponent source)
        {
            switch (source)
            {
            case BarComponent.Open:
                return(marketSeries.Open);

            case BarComponent.High:
                return(marketSeries.High);

            case BarComponent.Low:
                return(marketSeries.Low);

            case BarComponent.Close:
                return(marketSeries.Close);

            default:
                throw new ArgumentException();
            }
        }
コード例 #8
0
        public void OnBar(MarketSeries series)
        {
            var bar = series.Last;

            OnBar(series.SymbolCode, series.TimeFrame, bar);
        }