当前位置: 首页>>代码示例>>C#>>正文


C# Candles.Candle类代码示例

本文整理汇总了C#中StockSharp.Algo.Candles.Candle的典型用法代码示例。如果您正苦于以下问题:C# Candle类的具体用法?C# Candle怎么用?C# Candle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Candle类属于StockSharp.Algo.Candles命名空间,在下文中一共展示了Candle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddCandle

			public void AddCandle(int securityIndex, Candle candle)
			{
				if (candle == null)
					throw new ArgumentNullException(nameof(candle));

				if (Candles[securityIndex] != null)
				{
					if (_isSparseBuffer)
						return;
					
					throw new ArgumentException(LocalizedStrings.Str654Params.Put(candle.OpenTime), nameof(candle));
				}

				Candles[securityIndex] = candle;

				_counter--;

				if (_isSparseBuffer)
				{
					if (candle.OpenTime < OpenTime)
					{
						OpenTime = candle.OpenTime;
						OpenTime = Candles.Where(c => c != null).Min(c => c.OpenTime);
					}

					if (candle.CloseTime > CloseTime)
					{
						CloseTime = candle.CloseTime;
						CloseTime = Candles.Where(c => c != null).Max(c => c.CloseTime);
					}
				}
			}
开发者ID:vikewoods,项目名称:StockSharp,代码行数:32,代码来源:IndexSeriesBuilder.cs

示例2: GetValue

		/// <summary>
		/// To get the part value.
		/// </summary>
		/// <param name="current">The current candle.</param>
		/// <param name="prev">The previous candle.</param>
		/// <returns>Value.</returns>
		protected override decimal GetValue(Candle current, Candle prev)
		{
			if (current.LowPrice < prev.LowPrice && current.HighPrice - prev.HighPrice < prev.LowPrice - current.LowPrice)
				return prev.LowPrice - current.LowPrice;
			else
				return 0;
		}
开发者ID:hbwjz,项目名称:StockSharp,代码行数:13,代码来源:DiMinus.cs

示例3: CandleBuffer

			public CandleBuffer(DateTimeOffset openTime, DateTimeOffset closeTime, int maxCandleCount, bool isSparseBuffer)
			{
				OpenTime = openTime;
				CloseTime = closeTime;
				Candles = new Candle[maxCandleCount];
				_counter = maxCandleCount;
				_isSparseBuffer = isSparseBuffer;
			}
开发者ID:vikewoods,项目名称:StockSharp,代码行数:8,代码来源:IndexSeriesBuilder.cs

示例4: GetPriceMovements

		/// <summary>
		/// To get price components to select the maximal value.
		/// </summary>
		/// <param name="currentCandle">The current candle.</param>
		/// <param name="prevCandle">The previous candle.</param>
		/// <returns>Price components.</returns>
		protected virtual decimal[] GetPriceMovements(Candle currentCandle, Candle prevCandle)
		{
			return new[]
			{
				Math.Abs(currentCandle.HighPrice - currentCandle.LowPrice),
				Math.Abs(prevCandle.ClosePrice - currentCandle.HighPrice),
				Math.Abs(prevCandle.ClosePrice - currentCandle.LowPrice)
			};
		}
开发者ID:zjxbetter,项目名称:StockSharp,代码行数:15,代码来源:TrueRange.cs

示例5: ProcessCandle

        protected void ProcessCandle(Candle candle)
        {
            if (Trade.GetPnL() <= -StopLossUnit)
            {
                OrderDirections direction = this.Trade.Order.Direction.Invert();
                decimal price = Security.LastTrade.Price;
                Order order = this.CreateOrder(direction, price, this.Trade.Order.Volume);

                RegisterOrder(order);
            }
        }
开发者ID:akramarev,项目名称:SampleSMA,代码行数:11,代码来源:StopLossCandleStrategy.cs

示例6: AddCandle

			public bool AddCandle(Candle candle)
			{
				if (candle == null)
					throw new ArgumentNullException(nameof(candle));

				if (!_byTime.SafeAdd(candle.OpenTime).TryAdd(candle))
					return false;

				_allCandles.AddLast(candle);
				_candleStat.Add(candle);

				_lastCandleTime = candle.OpenTime.UtcTicks;

				RecycleCandles();

				return true;
			}
开发者ID:vikewoods,项目名称:StockSharp,代码行数:17,代码来源:CandleManagerContainer.cs

示例7: OnProcess

		/// <summary>
		/// To handle the input value.
		/// </summary>
		/// <param name="input">The input value.</param>
		/// <returns>The resulting value.</returns>
		protected override IIndicatorValue OnProcess(IIndicatorValue input)
		{
			var candle = input.GetValue<Candle>();

			if (_prevCandle != null)
			{
				if (input.IsFinal)
					IsFormed = true;

				var priceMovements = GetPriceMovements(candle, _prevCandle);

				if (input.IsFinal)
					_prevCandle = candle;

				return new DecimalIndicatorValue(this, priceMovements.Max());
			}

			if (input.IsFinal)
				_prevCandle = candle;

			return new DecimalIndicatorValue(this, candle.HighPrice - candle.LowPrice);
		}
开发者ID:zjxbetter,项目名称:StockSharp,代码行数:27,代码来源:TrueRange.cs

示例8: ProcessCandle

		private void ProcessCandle(Candle candle)
		{
			// если наша стратегия в процессе остановки
			if (ProcessState == ProcessStates.Stopping)
			{
				// отменяем активные заявки
				CancelActiveOrders();
				return;
			}

			// добавляем новую свечу
			LongSma.Process(candle);
			ShortSma.Process(candle);

			// вычисляем новое положение относительно друг друга
			var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue();

			// если произошло пересечение
			if (_isShortLessThenLong != isShortLessThenLong)
			{
				// если короткая меньше чем длинная, то продажа, иначе, покупка.
				var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy;

				// вычисляем размер для открытия или переворота позы
				var volume = Position == 0 ? Volume : Position.Abs() * 2;

				// регистрируем заявку (обычным способом - лимитированной заявкой)
				//RegisterOrder(this.CreateOrder(direction, (decimal)Security.GetCurrentPrice(direction), volume));

				// переворачиваем позицию через котирование
				var strategy = new MarketQuotingStrategy(direction, volume);
				ChildStrategies.Add(strategy);

				// запоминаем текущее положение относительно друг друга
				_isShortLessThenLong = isShortLessThenLong;
			}
		}
开发者ID:reddream,项目名称:StockSharp,代码行数:37,代码来源:SmaStrategy.cs

示例9: ProcessCandle

		private void ProcessCandle(Candle candle)
		{
			// strategy are stopping
			if (ProcessState == ProcessStates.Stopping)
			{
				CancelActiveOrders();
				return;
			}

			// process new candle
			LongSma.Process(candle);
			ShortSma.Process(candle);

			// calc new values for short and long
			var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue();

			// crossing happened
			if (_isShortLessThenLong != isShortLessThenLong)
			{
				// if short less than long, the sale, otherwise buy
				var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy;

				// calc size for open position or revert
				var volume = Position == 0 ? Volume : Position.Abs() * 2;

				// register order (limit order)
				RegisterOrder(this.CreateOrder(direction, (decimal)(Security.GetCurrentPrice(this, direction) ?? 0), volume));

				// or revert position via market quoting
				//var strategy = new MarketQuotingStrategy(direction, volume);
				//ChildStrategies.Add(strategy);

				// store current values for short and long
				_isShortLessThenLong = isShortLessThenLong;
			}
		}
开发者ID:reddream,项目名称:StockSharp,代码行数:36,代码来源:SmaStrategy.cs

示例10: ProcessCandle

		private void ProcessCandle(CandleSeries series, Candle candle)
		{
			// возможно была задержка в получении данных и обработаны еще не все данные
			if (!_isStarted)
				this.GuiAsync(() => IsStarted = true);

			_timer.Activate();

			_candlesCount++;

			// ограничиваем кол-во передаваемых свечек, чтобы не фризился интерфейс
			if (_candlesCount % 100 == 0)
				System.Threading.Thread.Sleep(200);

			var candleSeries = (CandleSeries)_bufferedChart.GetSource(_candleElement);

			if (series == candleSeries)
			{
				var values = new Dictionary<IChartElement, object>();

				lock (_syncRoot)
				{
					foreach (var element in _bufferedChart.Elements.Where(e => _bufferedChart.GetSource(e) == series))
					{
						if (_skipElements.Contains(element))
							continue;

						element.DoIf<IChartElement, ChartCandleElement>(e => values.Add(e, candle));
						element.DoIf<IChartElement, ChartIndicatorElement>(e => values.Add(e, CreateIndicatorValue(e, candle)));
					}
				}

				_bufferedChart.Draw(candle.OpenTime, values);

				if (series.Security is ContinuousSecurity)
				{
					// для непрерывных инструментов всегда приходят данные по одной серии
					// но инструмент у свечки будет равен текущему инструменту
					ProcessContinuousSourceElements(candle);
				}
			}
			else
			{
				// для индексов будут приходить отдельные свечки для каждого инструмента
				ProcessIndexSourceElements(candle);
			}
		}
开发者ID:kknet,项目名称:StockSharp,代码行数:47,代码来源:CompositeSecurityPanel.xaml.cs

示例11: ProcessCandle

		public IEnumerable<Candle> ProcessCandle(Candle candle)
		{
			return GetFormedBuffers(candle)
				.Select(buffer =>
				{
					var openPrice = TryCalculate(buffer, c => c.OpenPrice);

					if (openPrice == null)
						return null;

					var indexCandle = candle.GetType().CreateInstance<Candle>();

					indexCandle.Security = _security;
					indexCandle.Arg = CloneArg(candle.Arg, _security);
					indexCandle.OpenTime = buffer.OpenTime;
					indexCandle.CloseTime = buffer.CloseTime;

					indexCandle.TotalVolume = Calculate(buffer, c => c.TotalVolume);
					indexCandle.TotalPrice = Calculate(buffer, c => c.TotalPrice);
					indexCandle.OpenPrice = (decimal)openPrice;
					indexCandle.OpenVolume = Calculate(buffer, c => c.OpenVolume ?? 0);
					indexCandle.ClosePrice = Calculate(buffer, c => c.ClosePrice);
					indexCandle.CloseVolume = Calculate(buffer, c => c.CloseVolume ?? 0);
					indexCandle.HighPrice = Calculate(buffer, c => c.HighPrice);
					indexCandle.HighVolume = Calculate(buffer, c => c.HighVolume ?? 0);
					indexCandle.LowPrice = Calculate(buffer, c => c.LowPrice);
					indexCandle.LowVolume = Calculate(buffer, c => c.LowVolume ?? 0);

					// если некоторые свечи имеют неполные данные, то и индекс будет таким же неполным
					if (indexCandle.OpenPrice == 0 || indexCandle.HighPrice == 0 || indexCandle.LowPrice == 0 || indexCandle.ClosePrice == 0)
					{
						var nonZeroPrice = indexCandle.OpenPrice;

						if (nonZeroPrice == 0)
							nonZeroPrice = indexCandle.HighPrice;

						if (nonZeroPrice == 0)
							nonZeroPrice = indexCandle.LowPrice;

						if (nonZeroPrice == 0)
							nonZeroPrice = indexCandle.LowPrice;

						if (nonZeroPrice != 0)
						{
							if (indexCandle.OpenPrice == 0)
								indexCandle.OpenPrice = nonZeroPrice;

							if (indexCandle.HighPrice == 0)
								indexCandle.HighPrice = nonZeroPrice;

							if (indexCandle.LowPrice == 0)
								indexCandle.LowPrice = nonZeroPrice;

							if (indexCandle.ClosePrice == 0)
								indexCandle.ClosePrice = nonZeroPrice;
						}
					}

					if (indexCandle.HighPrice < indexCandle.LowPrice)
					{
						var high = indexCandle.HighPrice;

						indexCandle.HighPrice = indexCandle.LowPrice;
						indexCandle.LowPrice = high;
					}

					if (indexCandle.OpenPrice > indexCandle.HighPrice)
						indexCandle.HighPrice = indexCandle.OpenPrice;
					else if (indexCandle.OpenPrice < indexCandle.LowPrice)
						indexCandle.LowPrice = indexCandle.OpenPrice;

					if (indexCandle.ClosePrice > indexCandle.HighPrice)
						indexCandle.HighPrice = indexCandle.ClosePrice;
					else if (indexCandle.ClosePrice < indexCandle.LowPrice)
						indexCandle.LowPrice = indexCandle.ClosePrice;

					indexCandle.State = CandleStates.Finished;

					return indexCandle;
				})
				.Where(c => c != null);
		}
开发者ID:vikewoods,项目名称:StockSharp,代码行数:82,代码来源:IndexSeriesBuilder.cs

示例12: AddCandle

				public void AddCandle(Candle candle)
				{
					if (_firstTime == null)
						_firstTime = candle.OpenTime;

					lock (_candles.SyncRoot)
					{
						if ((candle.OpenTime.Date - _firstTime.Value.Date).TotalDays >= 3)
						{
							_firstTime = candle.OpenTime;
							FlushCandles(_candles.CopyAndClear());
						}

						_candles.Add(candle);
					}
				}
开发者ID:jsonbao,项目名称:StockSharp,代码行数:16,代码来源:StrategyService.cs

示例13: CreateIndicatorValue

		private IIndicatorValue CreateIndicatorValue(ChartIndicatorElement element, Candle candle)
		{
			var indicator = _indicators.TryGetValue(element);

			if (indicator == null)
				throw new InvalidOperationException(LocalizedStrings.IndicatorNotFound.Put(element));

			return indicator.Process(candle);
		}
开发者ID:reddream,项目名称:StockSharp,代码行数:9,代码来源:TerminalStrategy.cs

示例14: ProcessCandles

		public void ProcessCandles(Candle candle)
		{
			Chart.Draw(_candleElement, candle);
		}
开发者ID:reddream,项目名称:StockSharp,代码行数:4,代码来源:CandlesWindow.xaml.cs

示例15: OnProcessCandle

		private void OnProcessCandle(Candle candle)
		{
			if (candle.State == CandleStates.Finished)
				NewCandle(candle);
		}
开发者ID:RakotVT,项目名称:StockSharp,代码行数:5,代码来源:CandleSeriesIndicatorSource.cs


注:本文中的StockSharp.Algo.Candles.Candle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。