/*
        按照股指的时间要求,时间划分是这样的
        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);
 }
Example #3
0
 protected BIAS(BarSeries series, SMA sma, int length, BarData barData)
     : base(series)
 {
     this.length = length;
     this.sma = sma;
     this.barData = barData;
     this.Name = "BIAS";
 }
Example #4
0
 public DynamicBBU(ISeries series, BarSeries bars, double k, BarData barData)
     : base(series)
 {
     this.k = k;
     this.bars = bars;
     this.barData = barData;
     this.Name = "DynamicBBU";
 }
Example #5
0
 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);
 }
Example #7
0
		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;
		}
Example #8
0
		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);
        }
Example #10
0
		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);
        }
Example #14
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);
		}
Example #15
0
 public bool CrossesAbove(BarSeries series, Bar bar)
 {
     return(this.series.CrossesAbove(series.series, bar.bar));
 }
Example #16
0
 public bool CrossesBelow(BarSeries series, Bar bar)
 {
     return(this.series.CrossesBelow(series.series, bar.bar));
 }
Example #17
0
File: MACD.cs Project: heber/FreeOQ
		public MACD(BarSeries series, int length1, int length2, Color color)
		{
			this.indicator = new FreeQuant.Indicators.MACD(series.series, length1, length2, color);
		}
Example #18
0
File: VHF.cs Project: heber/FreeOQ
		public VHF(BarSeries series, int length, BarData option, Color color)
		{
			this.indicator = new FreeQuant.Indicators.VHF(series.series, length, EnumConverter.Convert(option), color);
		}
Example #19
0
File: MOM.cs Project: heber/FreeOQ
		public MOM(BarSeries series, int length, BarData option)
		{
			this.indicator = new FreeQuant.Indicators.MOM(series.series, length, EnumConverter.Convert(option));
		}
Example #20
0
File: MDM.cs Project: heber/FreeOQ
		public MDM(BarSeries series, Color color)
		{
			this.indicator = new FreeQuant.Indicators.MDM(series.series, color);
		}
Example #21
0
 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);
        }
Example #23
0
 public void Add(BarSeries series)
 {
     series.series.Draw();
 }
Example #24
0
 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)));
 }
Example #25
0
 public virtual Cross Crosses(BarSeries series, Bar bar)
 {
     return(EnumConverter.Convert(this.series.Crosses((FreeQuant.Series.TimeSeries)series.series, bar.bar)));
 }
Example #26
0
File: MDM.cs Project: heber/FreeOQ
		public MDM(BarSeries series)
		{
			this.indicator = new FreeQuant.Indicators.MDM(series.series);
		}
Example #27
0
 public virtual bool CrossesAbove(BarSeries series, Bar bar)
 {
     return(((FreeQuant.Series.TimeSeries) this.indicator).CrossesAbove((FreeQuant.Series.TimeSeries)series.series, bar.bar));
 }
Example #28
0
		public void Add(BarSeries series)
		{
			series.series.Draw();
		}
Example #29
0
		public K_Slow(BarSeries series, int length, int order, Color color)
		{
			this.indicator = new FreeQuant.Indicators.K_Slow(series.series, length, order, color);
		}
Example #30
0
File: MACD.cs Project: heber/FreeOQ
		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);
		}
Example #31
0
File: VROC.cs Project: heber/FreeOQ
		public VROC(BarSeries series, int length, Color color)
		{
			this.indicator = new FreeQuant.Indicators.VROC(series.series, length, color);
		}
Example #32
0
 public virtual bool CrossesAbove(BarSeries series, Bar bar, BarData barData)
 {
     return(this.series.CrossesAbove(series.series, bar.bar, (int)barData));
 }
Example #33
0
 public virtual bool CrossesAbove(BarSeries series, Bar bar, BarData barData)
 {
     return(this.series.CrossesAbove((FreeQuant.Series.TimeSeries)series.series, bar.bar, (int)barData));
 }
Example #34
0
 public virtual Cross Crosses(BarSeries series, Bar bar)
 {
     return(EnumConverter.Convert(this.series.Crosses(series.series, bar.bar)));
 }
Example #35
0
		public bool CrossesBelow(BarSeries series, Bar bar)
		{
			return this.series.CrossesBelow(series.series, bar.bar);
		}
Example #36
0
 public virtual Cross Crosses(BarSeries series, Bar bar, BarData barData)
 {
     return(EnumConverter.Convert(this.series.Crosses(series.series, bar.bar, (int)barData)));
 }
Example #37
0
		public bool CrossesAbove(BarSeries series, Bar bar)
		{
			return this.series.CrossesAbove(series.series, bar.bar);
		}
Example #38
0
File: DX.cs Project: heber/FreeOQ
		public DX(BarSeries series, int length)
		{
			this.indicator = new FreeQuant.Indicators.DX(series.series, length);
		}
Example #39
0
		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);
        }
Example #41
0
		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;
		}