Example #1
0
		protected internal virtual void OnData(DataObject obj)
		{
			Tick tick = (Tick)obj;
			if (this.bar == null)
			{
				this.bar = new Bar();
				this.bar.instrumentId = tick.instrumentId;
				this.bar.type = this.barType;
				this.bar.size = this.barSize;
				this.bar.openDateTime = this.GetBarOpenDateTime(obj);
				this.bar.dateTime = this.GetBarCloseDateTime(obj);
				this.bar.open = tick.price;
				this.bar.high = tick.price;
				this.bar.low = tick.price;
				this.bar.close = tick.price;
				this.bar.volume = (long)tick.size;
			}
			else
			{
				if (tick.price > this.bar.high)
				{
					this.bar.high = tick.price;
				}
				if (tick.price < this.bar.low)
				{
					this.bar.low = tick.price;
				}
				this.bar.close = tick.price;
				this.bar.volume += (long)tick.size;
			}
			this.bar.n += 1L;
		}
Example #2
0
		internal override void OnBar_(Bar bar)
		{
			foreach (Strategy current in this.strategiesByInstrument[bar.instrumentId])
			{
				current.OnBar_(bar);
			}
			base.OnBar_(bar);
		}
Example #3
0
		public override object Read(BinaryReader reader)
		{
			reader.ReadByte();
			Bar bar = new Bar();
			bar.dateTime = new DateTime(reader.ReadInt64());
			bar.openDateTime = new DateTime(reader.ReadInt64());
			bar.instrumentId = reader.ReadInt32();
			bar.size = reader.ReadInt64();
			bar.high = reader.ReadDouble();
			bar.low = reader.ReadDouble();
			bar.open = reader.ReadDouble();
			bar.close = reader.ReadDouble();
			bar.volume = reader.ReadInt64();
			int num = reader.ReadInt32();
			if (num != 0)
			{
				bar.fields = new IdArray<double>(num);
				for (int i = 0; i < num; i++)
				{
					bar.fields[i] = reader.ReadDouble();
				}
			}
			return bar;
		}
Example #4
0
		public virtual void OnBar(Bar bar)
		{
		}
Example #5
0
 internal virtual void OnBar_(Bar bar)
 {
     if (this.raiseEvents && this.instruments.Contains(bar.instrumentId))
     {
         this.OnBar(this.framework.InstrumentManager.GetById(bar.instrumentId), bar);
         List<Stop> list = this.stopsByInstrument[bar.instrumentId];
         if (list != null)
         {
             for (int i = 0; i < list.Count; i++)
             {
                 list[i].OnBar(bar);
             }
         }
     }
     LinkedList<Strategy> linkedList = this.strategiesByInstrument[bar.instrumentId];
     if (linkedList != null)
     {
         for (LinkedListNode<Strategy> linkedListNode = linkedList.First; linkedListNode != null; linkedListNode = linkedListNode.Next)
         {
             linkedListNode.Data.OnBar_(bar);
         }
     }
 }
Example #6
0
 protected internal virtual void OnBar(Instrument instrument, Bar bar)
 {
 }
Example #7
0
 internal void OnBar(Bar bar)
 {
     if (this.strategy != null && this.strategy.status == StrategyStatus.Running)
     {
         this.strategy.OnBar_(bar);
     }
 }
Example #8
0
 protected virtual void OnBar(Bar bar)
 {
 }
Example #9
0
		public void OnBar(Bar bar)
		{
		}
Example #10
0
		public void Clear()
		{
			this.items.Clear();
			this.min = null;
			this.max = null;
			for (int i = 0; i < this.indicators.Count; i++)
			{
				this.indicators[i].Clear();
			}
			this.indicators.Clear();
		}
Example #11
0
		public BarSeries(string name = "", string description = "")
		{
			this.name = name;
			this.description = description;
			this.items = new List<Bar>();
			this.indicators = new List<Indicator>();
			this.min = null;
			this.max = null;
		}
Example #12
0
		protected void EmitBar()
		{
			this.factory.framework.eventServer.OnEvent(this.bar);
			this.bar = null;
		}
Example #13
0
 internal void OnBarOpen(Bar bar)
 {
     if (this.traceOnBar && this.traceOnBarOpen && (this.filterBarSize < 0L || (this.filterBarSize == bar.Size && this.filterBarType == BarType.Time)))
     {
         this.currPrice = bar.Open;
         this.fillPrice = bar.Open;
         if (this.trailOnOpen)
         {
             this.trailPrice = bar.Open;
         }
         this.CheckStop();
     }
 }
Example #14
0
 internal void OnBar(Bar bar)
 {
     if (this.traceOnBar && (this.filterBarSize < 0L || (this.filterBarSize == bar.Size && this.filterBarType == BarType.Time)))
     {
         this.trailPrice = bar.Close;
         switch (this.side)
         {
         case PositionSide.Long:
             this.currPrice = bar.Low;
             this.fillPrice = bar.Low;
             if (this.trailOnHighLow)
             {
                 this.trailPrice = bar.High;
             }
             break;
         case PositionSide.Short:
             this.currPrice = bar.High;
             this.fillPrice = bar.High;
             if (this.trailOnHighLow)
             {
                 this.trailPrice = bar.Low;
             }
             break;
         }
         switch (this.fillMode)
         {
         case StopFillMode.Close:
             this.fillPrice = bar.Close;
             break;
         case StopFillMode.Stop:
             this.fillPrice = this.stopPrice;
             break;
         }
         this.CheckStop();
     }
 }
Example #15
0
		protected internal override void OnBar(Instrument instrument, Bar bar)
		{
			this.dataComponent.OnBar(bar);
			this.alphaComponent.OnBar(bar);
			this.positionComponent.OnBar(bar);
			this.reportComponent.OnBar(bar);
		}
Example #16
0
        protected override void OnBar(Instrument instrument, Bar bar)
        {
            // Add bar to bar series.
            Bars.Add(bar);

            // Add bar to group.
            Log(bar, barsGroup);

            // Add upper bollinger band value to group.
            if (bbu.Count > 0)
                Log(bbu.Last, bbuGroup);

            // Add lower bollinger band value to group.
            if (bbl.Count > 0)
                Log(bbl.Last, bblGroup);

            // Add simple moving average value bands to group.
            if (sma.Count > 0)
                Log(sma.Last, smaGroup);

            // Calculate performance.
            Portfolio.Performance.Update();

            // Add equity to group.
            Log(Portfolio.Value, equityGroup);

            // Check strategy logic.
            if (!HasPosition(instrument))
            {
                if (bbu.Count > 0 && bar.Close >= bbu.Last)
                {
                    Order enterOrder = SellOrder(Instrument, Qty, "Enter");
                    Send(enterOrder);
                }
                else if (bbl.Count > 0 && bar.Close <= bbl.Last)
                {
                    Order enterOrder = BuyOrder(Instrument, Qty, "Enter");
                    Send(enterOrder);
                }
            }
            else
                UpdateExitLimit();
        }
Example #17
0
		public Bar(Bar bar) : base(bar)
		{
			this.instrumentId = bar.instrumentId;
			this.type = bar.type;
			this.size = bar.size;
			this.openDateTime = bar.openDateTime;
			this.open = bar.open;
			this.high = bar.high;
			this.low = bar.low;
			this.close = bar.close;
			this.volume = bar.volume;
			this.openInt = bar.openInt;
		}
Example #18
0
		public void Add(Bar bar)
		{
			if (this.min == null)
			{
				this.min = bar;
			}
			else
			{
				if (bar.high < this.min.low)
				{
					this.min = bar;
				}
			}
			if (this.max == null)
			{
				this.max = bar;
			}
			else
			{
				if (bar.high > this.max.high)
				{
					this.max = bar;
				}
			}
			this.items.Add(bar);
			int index = this.items.Count - 1;
			for (int i = 0; i < this.indicators.Count; i++)
			{
				this.indicators[i].Calculate(index);
			}
		}
Example #19
0
		internal void OnBar(Bar bar)
		{
			this.bar[bar.instrumentId] = bar;
		}
Example #20
0
 public void OnBar(Bar bar)
 {
 }