/* 按照股指的时间要求,时间划分是这样的 9:15 9:45 10:15 10:45 11:15-11:30 13:00-13:15 两个15分钟被午休隔开了 13:45 14:15 14:45 15:15 交割日时只到15:00,已经到最后一天了,少15分钟也没什么 */ public override void OnBar(Bar bar) { //只处理15分钟的 if (900 == bar.Size) { if (bars == null) bars = new BarSeries(); bars.Add(bar); //在处理11:15-11:30 13:00-13:15这两个15分钟时会合并成一个 if (bars.Count == 2) // 2 * 15min = 30 min { // get OHLC values for 30min bar double open = bars[0].Open; double high = bars.HighestHigh(); double low = bars.LowestLow(); double close = bars[1].Close; long volume = bars[0].Volume + bars[1].Volume; // todo something Bar b = new Bar(bars[0].DateTime, open, high, low, close, volume, 900 * 2); bars30min.Add(b); Console.WriteLine(b); // reset 15min bar series bars = null; } } }
public SpiderVwapBand(BarSeries input, double factor, InstrumentType instrumentType) : base(input) { _factor = factor; _instrumentType = instrumentType; this.Name = string.Format("SpiderVwapBand ({0:N4})", factor); }
protected BIAS(BarSeries series, SMA sma, int length, BarData barData) : base(series) { this.length = length; this.sma = sma; this.barData = barData; this.Name = "BIAS"; }
public DynamicBBU(ISeries series, BarSeries bars, double k, BarData barData) : base(series) { this.k = k; this.bars = bars; this.barData = barData; this.Name = "DynamicBBU"; }
protected KDJ(BarSeries series, K_Fast rsv, int length) : base(series) { this.length = length; this.rsv = rsv; this.K = new TimeSeries("K"); this.D = new TimeSeries("D"); this.Name = "KDJ(" + length + ")"; }
public SpiderVwapBandOld(ISeries input, double factor, BarSeries priceBarSeries, int barSize, InstrumentType instrumentType) : base(input) { _factor = factor; _priceBarSeries = priceBarSeries; _barSize = barSize; _instrumentType = instrumentType; this.Name = string.Format("SpiderVwapBand ({0:N4})", factor); }
public BarSeries Compress(DataEntryEnumerator enumerator) { BarSeries series = new BarSeries(); this.NewCompressedBar += (sender, args) => series.Add(args.Bar); while (enumerator.MoveNext()) this.Add(enumerator.Current); this.Flush(); return series; }
public static BarSeries GetHistoricalBars(string provider, Instrument instrument, DateTime begin, DateTime end, int size) { BarSeries barSeries = new BarSeries(); if (FreeQuant.Providers.ProviderManager.HistoricalDataProviders.Contains(provider)) { IHistoricalDataProvider provider1 = FreeQuant.Providers.ProviderManager.HistoricalDataProviders[provider]; foreach (FreeQuant.Data.Bar bar in size != 86400 ? (FreeQuant.Series.TimeSeries) FreeQuant.Instruments.DataManager.GetHistoricalBars(provider1, instrument.instrument, begin, end, (long) size) : (FreeQuant.Series.TimeSeries) FreeQuant.Instruments.DataManager.GetHistoricalDailies(provider1, instrument.instrument, begin, end)) barSeries.series.Add(bar); } return barSeries; }
public override void OnStrategyStart() { if (Instrument1 == Instrument) { //Strategy1 = this; BarSeries1 = GetBars(BarType.Time, barSize); } else if (Instrument2 == Instrument) { //Strategy2 = this; BarSeries2 = GetBars(BarType.Time, barSize); } else { Console.WriteLine("合约错误!" + Instrument); } sma = new SMA(spreadSeries, Length); Draw(spreadSeries, 2); Draw(sma, 2); }
public static BarSeries GetHistoricalBars(string provider, Instrument instrument, DateTime begin, DateTime end, int size) { BarSeries barSeries = new BarSeries(); if (SmartQuant.Providers.ProviderManager.HistoricalDataProviders.Contains(provider)) { IHistoricalDataProvider provider2 = SmartQuant.Providers.ProviderManager.HistoricalDataProviders[provider]; SmartQuant.Series.BarSeries barSeries2; if (size == 86400) { barSeries2 = SmartQuant.Instruments.DataManager.GetHistoricalDailies(provider2, instrument.instrument, begin, end); } else { barSeries2 = SmartQuant.Instruments.DataManager.GetHistoricalBars(provider2, instrument.instrument, begin, end, (long)size); } foreach (SmartQuant.Data.Bar bar in barSeries2) { barSeries.series.Add(bar); } } return barSeries; }
private void PreLoadHistoricalData(DateTime startDate, int barSize, BarSeries barsToAppendTo) { Stopwatch watch = new Stopwatch(); watch.Start(); string barName = BarNameManager.GetBarName(barSize); LoggingUtility.WriteInfo(this, string.Format("Trying to retrieve {0} data starting from {1} from IB", barName, startDate.ToShortDateString())); BarSeries historicalData = GetHistoricalBars("IB", Instrument, startDate, Clock.Now, barSize); watch.Stop(); int retrievedBarCount = historicalData.Count; LoggingUtility.WriteInfo(this, string.Format("Took {0}ms to retrieve data from IB for {1} period data. Total bars retrieved: {2}", watch.ElapsedMilliseconds, barName, retrievedBarCount)); watch.Reset(); watch.Start(); foreach (Bar currentBar in historicalData) { barsToAppendTo.Add(currentBar); SaveData(currentBar); OnBar(currentBar); } watch.Stop(); LoggingUtility.WriteInfo(this, string.Format("Took {0}ms to load data into memory for {1} data", watch.ElapsedMilliseconds, barName)); }
public override void OnStrategyStart() { base.OnStrategyStart(); // 测试用,自定义交易时间,仿真或实盘时可删除 base.TimeHelper = new TimeHelper(new int[] { 0, 2400 }, 2100, 1458); base.TargetPosition = 0; base.DualPosition.Long.Qty = 0; base.DualPosition.Short.Qty = 0; bars86400 = GetBars(BarType.Time, 86400); smd30 = new SMD(bars86400, 30); lbd = new LookBackDays(smd30, lookBackDays, floorAmt, ceilingAmt); dbbu = new DynamicBBU(lbd, bars86400, bolBandTrig, BarData.Close); Draw(smd30, 2); Draw(lbd, 3); Draw(dbbu.SMA, 0); Draw(dbbu.BBL, 0); Draw(dbbu, 0); upBandSeries = new TimeSeries("upBandSeries"); dnBandSeries = new TimeSeries("dnBandSeries"); buyPointSeries = new TimeSeries("buyPointSeries"); sellPointSeries = new TimeSeries("sellPointSeries"); upBandSeries.Color = Color.Red; dnBandSeries.Color = Color.Red; Draw(upBandSeries, 0); Draw(dnBandSeries, 0); Draw(buyPointSeries, 0); Draw(sellPointSeries, 0); base.OnStrategyStart(); }
public override void OnStrategyStart() { bars86400 = GetBars(BarType.Time, 86400); smd30 = new SMD(bars86400, 30); lbd = new LookBackDays(smd30, lookBackDays, floorAmt, ceilingAmt); dbbu = new DynamicBBU(lbd, bars86400, bolBandTrig, BarData.Close); Draw(smd30, 2); Draw(lbd, 3); Draw(dbbu.SMA, 0); Draw(dbbu.BBL, 0); Draw(dbbu, 0); upBandSeries = new TimeSeries("upBandSeries"); dnBandSeries = new TimeSeries("dnBandSeries"); buyPointSeries = new TimeSeries("buyPointSeries"); sellPointSeries = new TimeSeries("sellPointSeries"); upBandSeries.Color = Color.Red; dnBandSeries.Color = Color.Red; Draw(upBandSeries, 0); Draw(dnBandSeries, 0); Draw(buyPointSeries, 0); Draw(sellPointSeries, 0); }
public static BarSeries CompressBars(BarSeries bars, long barSize) { if (bars.Count == 0) { return new BarSeries(); } Bar bar = bars[0]; if (bar.Type == BarType.Range) { throw new ArgumentException("Cannot compress bars with type Range"); } return DataManager.CompressBars(new BarDataEnumerator(bars), bar.Type, bar.Size, barSize); }
public bool CrossesAbove(BarSeries series, Bar bar) { return(this.series.CrossesAbove(series.series, bar.bar)); }
public bool CrossesBelow(BarSeries series, Bar bar) { return(this.series.CrossesBelow(series.series, bar.bar)); }
public MACD(BarSeries series, int length1, int length2, Color color) { this.indicator = new FreeQuant.Indicators.MACD(series.series, length1, length2, color); }
public VHF(BarSeries series, int length, BarData option, Color color) { this.indicator = new FreeQuant.Indicators.VHF(series.series, length, EnumConverter.Convert(option), color); }
public MOM(BarSeries series, int length, BarData option) { this.indicator = new FreeQuant.Indicators.MOM(series.series, length, EnumConverter.Convert(option)); }
public MDM(BarSeries series, Color color) { this.indicator = new FreeQuant.Indicators.MDM(series.series, color); }
public virtual bool CrossesBelow(BarSeries series, Bar bar, BarData barData) { return(((FreeQuant.Series.TimeSeries) this.indicator).CrossesBelow((FreeQuant.Series.TimeSeries)series.series, bar.bar, (int)barData)); }
public override void OnStrategyStart() { UpSeries = new TimeSeries("Up"); DownSeries = new TimeSeries("Down"); RangeSeries = new TimeSeries("Range"); int n = N; if (StrategyType.OpenRangeBreak == strategyType) { n = 1; } bars86400 = GetBars(BarType.Time, 86400); HH = new PC(bars86400, n, BarData.High, PC.CalcType.Max, PC.UseLast.Yes); HC = new PC(bars86400, n, BarData.Close, PC.CalcType.Max, PC.UseLast.Yes); LC = new PC(bars86400, n, BarData.Close, PC.CalcType.Min, PC.UseLast.Yes); LL = new PC(bars86400, n, BarData.Low, PC.CalcType.Min, PC.UseLast.Yes); Draw(UpSeries, 0); Draw(DownSeries, 0); Draw(RangeSeries, 2); }
public void Add(BarSeries series) { series.series.Draw(); }
public virtual Cross Crosses(BarSeries series, Bar bar, BarData barData) { return(EnumConverter.Convert(((FreeQuant.Series.TimeSeries) this.indicator).Crosses((FreeQuant.Series.TimeSeries)series.series, bar.bar, (int)barData))); }
public virtual Cross Crosses(BarSeries series, Bar bar) { return(EnumConverter.Convert(this.series.Crosses((FreeQuant.Series.TimeSeries)series.series, bar.bar))); }
public MDM(BarSeries series) { this.indicator = new FreeQuant.Indicators.MDM(series.series); }
public virtual bool CrossesAbove(BarSeries series, Bar bar) { return(((FreeQuant.Series.TimeSeries) this.indicator).CrossesAbove((FreeQuant.Series.TimeSeries)series.series, bar.bar)); }
public K_Slow(BarSeries series, int length, int order, Color color) { this.indicator = new FreeQuant.Indicators.K_Slow(series.series, length, order, color); }
public MACD(BarSeries series, int length1, int length2, BarData option, Color color) { this.indicator = new FreeQuant.Indicators.MACD(series.series, length1, length2, EnumConverter.Convert(option), color); }
public VROC(BarSeries series, int length, Color color) { this.indicator = new FreeQuant.Indicators.VROC(series.series, length, color); }
public virtual bool CrossesAbove(BarSeries series, Bar bar, BarData barData) { return(this.series.CrossesAbove(series.series, bar.bar, (int)barData)); }
public virtual bool CrossesAbove(BarSeries series, Bar bar, BarData barData) { return(this.series.CrossesAbove((FreeQuant.Series.TimeSeries)series.series, bar.bar, (int)barData)); }
public virtual Cross Crosses(BarSeries series, Bar bar) { return(EnumConverter.Convert(this.series.Crosses(series.series, bar.bar))); }
public bool CrossesBelow(BarSeries series, Bar bar) { return this.series.CrossesBelow(series.series, bar.bar); }
public virtual Cross Crosses(BarSeries series, Bar bar, BarData barData) { return(EnumConverter.Convert(this.series.Crosses(series.series, bar.bar, (int)barData))); }
public bool CrossesAbove(BarSeries series, Bar bar) { return this.series.CrossesAbove(series.series, bar.bar); }
public DX(BarSeries series, int length) { this.indicator = new FreeQuant.Indicators.DX(series.series, length); }
public Cross Crosses(BarSeries series, Bar bar) { return EnumConverter.Convert(this.series.Crosses(series.series, bar.bar)); }
public override void OnStrategyStart() { base.OnStrategyStart(); // 测试用,自定义交易时间,仿真或实盘时可删除 base.TimeHelper = new TimeHelper(new int[] { 0, 2400 },2100, 1458); base.TargetPosition = 0; base.DualPosition.Long.Qty = 0; base.DualPosition.Short.Qty = 0; UpSeries = new TimeSeries("Up"); DownSeries = new TimeSeries("Down"); RangeSeries = new TimeSeries("Range"); int n = N; if (StrategyType.OpenRangeBreak == strategyType) { n = 1; } bars86400 = GetBars(BarType.Time, 86400); HH = new PC(bars86400, n, BarData.High, PC.CalcType.Max, PC.UseLast.Yes); HC = new PC(bars86400, n, BarData.Close, PC.CalcType.Max, PC.UseLast.Yes); LC = new PC(bars86400, n, BarData.Close, PC.CalcType.Min, PC.UseLast.Yes); LL = new PC(bars86400, n, BarData.Low, PC.CalcType.Min, PC.UseLast.Yes); Draw(UpSeries, 0); Draw(DownSeries, 0); Draw(RangeSeries, 2); }
public BarSeries GetRange(DateTime dateTime1, DateTime dateTime2) { BarSeries barSeries = new BarSeries(); int index = this.series.GetIndex(dateTime1, EIndexOption.Next); int index2 = this.series.GetIndex(dateTime2, EIndexOption.Prev); if (index != -1 && index2 != -1) { for (int i = index; i <= index2; i++) { barSeries.Add(new Bar(this.series[i])); } } return barSeries; }