public BarToOtherBarHandler(IAccount account, MarketSeries series) { this.MarketSeries = series; this.Account = account; m1 = series.Symbol.GetMarketSeries(TimeFrame.m1); logger = this.GetLogger(); }
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); }
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); }
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); }
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; } }
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)); }
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(); } }
public void OnBar(MarketSeries series) { var bar = series.Last; OnBar(series.SymbolCode, series.TimeFrame, bar); }