當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。