當前位置: 首頁>>代碼示例>>C#>>正文


C# Market.TradeBar類代碼示例

本文整理匯總了C#中QuantConnect.Data.Market.TradeBar的典型用法代碼示例。如果您正苦於以下問題:C# TradeBar類的具體用法?C# TradeBar怎麽用?C# TradeBar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TradeBar類屬於QuantConnect.Data.Market命名空間,在下文中一共展示了TradeBar類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ResetsProperly

        public void ResetsProperly()
        {
            var mfi = new MoneyFlowIndex(3);
            foreach (var data in TestHelper.GetDataStream(4))
            {
                var tradeBar = new TradeBar
                {
                    Open = data.Value,
                    Close = data.Value,
                    High = data.Value,
                    Low = data.Value,
                    Volume = Decimal.ToInt64(data.Value)
                };
                mfi.Update(tradeBar);
            }
            Assert.IsTrue(mfi.IsReady);
            Assert.IsTrue(mfi.PositiveMoneyFlow.IsReady);
            Assert.IsTrue(mfi.NegativeMoneyFlow.IsReady);
            Assert.AreNotEqual(mfi.PreviousTypicalPrice, 0.0m);

            mfi.Reset();

            Assert.AreEqual(mfi.PreviousTypicalPrice, 0.0m);
            TestHelper.AssertIndicatorIsInDefaultState(mfi);
            TestHelper.AssertIndicatorIsInDefaultState(mfi.PositiveMoneyFlow);
            TestHelper.AssertIndicatorIsInDefaultState(mfi.NegativeMoneyFlow);
        }
開發者ID:reddream,項目名稱:Lean,代碼行數:27,代碼來源:MoneyFlowIndexTests.cs

示例2: ReportDailyBar

        /// <summary>
        /// Logs the OrderEvent Transaction
        /// </summary>
        public void ReportDailyBar(TradeBar tradeBar)
        {
            #region "Print"
            if(!HasPrintedHeading)
            {
                ReportHeading(_algorithm.Name);
                HasPrintedHeading = true;
            }
            StringBuilder sb = new StringBuilder();
            string msg = (string.Format(
                "{0},{1},{2},{3},{4},{5}",
                tradeBar.Time,
                barcount++,
                tradeBar.Open,
                tradeBar.High,
                tradeBar.Low,
                tradeBar.Close
                ));
            sb.Append(msg);

            foreach (var item in ColumnList)
            {
                sb.Append(",");
                sb.Append(item.Value);
            }
            _logHandler.Debug(sb.ToString());

            #endregion
        }
開發者ID:bizcad,項目名稱:LeanITrend,代碼行數:32,代碼來源:TradeBarReporter.cs

示例3: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns> A new value for this indicator </returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            var obv = Current.Value;

            if (_previousInput != null)
            {
                if (input.Value > _previousInput.Value)
                {
                    obv += input.Volume;
                    Update(input);
                }
                else if (input.Value < _previousInput.Value)
                {
                    obv -= input.Volume;
                    Update(input);
                }
            }
            else
            {
                obv = input.Volume;
                Update(input);
            }

            _previousInput = input;
            return obv;
        }
開發者ID:skyfyl,項目名稱:Lean,代碼行數:31,代碼來源:OnBalanceVolume.cs

示例4: ComputeNextValue

        /// <summary>
        /// Computes whether we have found a two bar pattern
        /// </summary>
        /// <param name="input">TradeBar - the current bar</param>
        /// <returns></returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            BarsWindow.Add(input);
            if (!IsReady) return 0;
            if (Math.Abs(BarsWindow[0].Open - BarsWindow[0].Close) > MinimumBarSize)
            {

                if (UseBody)
                {
                    if (Math.Abs(BarsWindow[0].Open - BarsWindow[1].Close) < BarDifferenceTolerance &&
                        Math.Abs(BarsWindow[0].Close - BarsWindow[1].Open) < BarDifferenceTolerance)
                    {
                        // 1 for up bar, -1 for down bar
                        return BarsWindow[0].Open < BarsWindow[0].Close ? 1m : -1m;
                    }
                }
                else
                {
                    if (Math.Abs(BarsWindow[0].High - BarsWindow[1].Low) < BarDifferenceTolerance &&
                        Math.Abs(BarsWindow[0].Low - BarsWindow[1].High) < BarDifferenceTolerance)
                    {
                        // 1 for up bar, -1 for down bar
                        return BarsWindow[0].Low < BarsWindow[0].High ? 1m : -1m;
                    }                    
                }
                
            }
            return 0;

        }
開發者ID:bizcad,項目名稱:LeanJJN,代碼行數:35,代碼來源:TwoBarReversalIndicator.cs

示例5: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            _maximum.Update(new IndicatorDataPoint { Value = input.High });
            _minimum.Update(new IndicatorDataPoint { Value = input.Low });

            return (_maximum + _minimum) / 2;
        }
開發者ID:kaffeebrauer,項目名稱:Lean,代碼行數:12,代碼來源:MidPrice.cs

示例6: OnFiftenMinuteSPY

 //15 minute events here:
 public void OnFiftenMinuteSPY(object sender, TradeBar data)
 {
     if (!Portfolio.Invested)
     {
         SetHoldings("SPY", 1.0);
     }
 }
開發者ID:bizcad,項目名稱:LeanITrend,代碼行數:8,代碼來源:ConsolidatorAlgorithm.cs

示例7: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="window">The window of data held in this indicator</param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IReadOnlyWindow<TradeBar> window, TradeBar input)
        {
            if (!IsReady)
            {
                if (Samples >= Period - _bodyLongAveragePeriod)
                {
                    _bodyLongPeriodTotal += GetCandleRange(CandleSettingType.BodyLong, window[4]);
                }

                return 0m;
            }

            decimal value;
            if (
                // 1st long
                GetRealBody(window[4]) > GetCandleAverage(CandleSettingType.BodyLong, _bodyLongPeriodTotal, window[4]) &&
                // 1st, 2nd, 4th same color, 5th opposite
                GetCandleColor(window[4]) == GetCandleColor(window[3]) &&
                GetCandleColor(window[3]) == GetCandleColor(window[1]) &&
                (int)GetCandleColor(window[1]) == -(int)GetCandleColor(input) &&
                (
                  (
                    // when 1st is black:
                    GetCandleColor(window[4]) == CandleColor.Black &&
                    // 2nd gaps down
                    GetRealBodyGapDown(window[3], window[4]) &&
                    // 3rd has lower high and low than 2nd
                    window[2].High < window[3].High && window[2].Low < window[3].Low &&
                    // 4th has lower high and low than 3rd
                    window[1].High < window[2].High && window[1].Low < window[2].Low &&
                    // 5th closes inside the gap
                    input.Close > window[3].Open && input.Close < window[4].Close
                  )
                  ||
                  (
                    // when 1st is white:
                    GetCandleColor(window[4]) == CandleColor.White &&
                    // 2nd gaps up
                    GetRealBodyGapUp(window[3], window[4]) &&
                    // 3rd has higher high and low than 2nd
                    window[2].High > window[3].High && window[2].Low > window[3].Low &&
                    // 4th has higher high and low than 3rd
                    window[1].High > window[2].High && window[1].Low > window[2].Low &&
                    // 5th closes inside the gap
                    input.Close < window[3].Open && input.Close > window[4].Close
                  )
                )
              )
                value = (int)GetCandleColor(input);
            else
                value = 0m;

            // add the current range and subtract the first range: this is done after the pattern recognition 
            // when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)

            _bodyLongPeriodTotal += GetCandleRange(CandleSettingType.BodyLong, window[4]) -
                                    GetCandleRange(CandleSettingType.BodyLong, window[4 + _bodyLongAveragePeriod]);

            return value;
        }
開發者ID:kaffeebrauer,項目名稱:Lean,代碼行數:66,代碼來源:Breakaway.cs

示例8: UpdatesProperly

        public void UpdatesProperly()
        {
            var bar = new TradeBar();
            bar.UpdateTrade(10, 10);
            Assert.AreEqual(10, bar.Open);
            Assert.AreEqual(10, bar.High);
            Assert.AreEqual(10, bar.Low);
            Assert.AreEqual(10, bar.Close);
            Assert.AreEqual(10, bar.Volume);

            bar.UpdateTrade(20, 5);
            Assert.AreEqual(10, bar.Open);
            Assert.AreEqual(20, bar.High);
            Assert.AreEqual(10, bar.Low);
            Assert.AreEqual(20, bar.Close);
            Assert.AreEqual(15, bar.Volume);

            bar.UpdateTrade(5, 50);
            Assert.AreEqual(10, bar.Open);
            Assert.AreEqual(20, bar.High);
            Assert.AreEqual(5, bar.Low);
            Assert.AreEqual(5, bar.Close);
            Assert.AreEqual(65, bar.Volume);

            bar.UpdateTrade(11, 100);
            Assert.AreEqual(10, bar.Open);
            Assert.AreEqual(20, bar.High);
            Assert.AreEqual(5, bar.Low);
            Assert.AreEqual(11, bar.Close);
            Assert.AreEqual(165, bar.Volume);
        }
開發者ID:skyfyl,項目名稱:Lean,代碼行數:31,代碼來源:TradeBarTests.cs

示例9: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="window">The window of data held in this indicator</param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IReadOnlyWindow<TradeBar> window, TradeBar input)
        {
            if (!IsReady)
            {
                return 0m;
            }

            decimal value;
            if (
                // white engulfs black
                (GetCandleColor(input) == CandleColor.White && GetCandleColor(window[1]) == CandleColor.Black &&
                  input.Close > window[1].Open && input.Open < window[1].Close
                )
                ||
                // black engulfs white
                (GetCandleColor(input) == CandleColor.Black && GetCandleColor(window[1]) == CandleColor.White &&
                  input.Open > window[1].Close && input.Close < window[1].Open
                )
              )
                value = (int)GetCandleColor(input);
            else
                value = 0;

            return value;
        }
開發者ID:kaffeebrauer,項目名稱:Lean,代碼行數:31,代碼來源:Engulfing.cs

示例10: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            AroonUp.Update(input.Time, input.High);
            AroonDown.Update(input.Time, input.Low);

            return AroonUp - AroonDown;
        }
開發者ID:skyfyl,項目名稱:Lean,代碼行數:12,代碼來源:AroonOscillator.cs

示例11: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="window">The window of data held in this indicator</param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IReadOnlyWindow<TradeBar> window, TradeBar input)
        {
            if (!IsReady)
            {
                if (Samples >= Period - _equalAveragePeriod)
                {
                    _equalPeriodTotal += GetCandleRange(CandleSettingType.Equal, window[1]);
                }

                return 0m;
            }

            decimal value;
            if (
                // first black
                GetCandleColor(window[1]) == CandleColor.Black &&
                // second black
                GetCandleColor(input) == CandleColor.Black &&
                // 1st and 2nd same close
                input.Close <= window[1].Close + GetCandleAverage(CandleSettingType.Equal, _equalPeriodTotal, window[1]) &&
                input.Close >= window[1].Close - GetCandleAverage(CandleSettingType.Equal, _equalPeriodTotal, window[1])
              )
                value = 1m;
            else
                value = 0m;

            // add the current range and subtract the first range: this is done after the pattern recognition 
            // when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)

            _equalPeriodTotal += GetCandleRange(CandleSettingType.Equal, window[1]) -
                                 GetCandleRange(CandleSettingType.Equal, window[_equalAveragePeriod + 1]);

            return value;
        }
開發者ID:kaffeebrauer,項目名稱:Lean,代碼行數:40,代碼來源:MatchingLow.cs

示例12: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            _trueRange.Update(input);

            if (Samples == 1)
            {
                _previousInput = input;
                return 50m;
            }

            var buyingPressure = new IndicatorDataPoint { Value = input.Close - Math.Min(input.Low, _previousInput.Close) };

            _sumBuyingPressure1.Update(buyingPressure);
            _sumBuyingPressure2.Update(buyingPressure);
            _sumBuyingPressure3.Update(buyingPressure);

            _sumTrueRange1.Update(_trueRange.Current);
            _sumTrueRange2.Update(_trueRange.Current);
            _sumTrueRange3.Update(_trueRange.Current);

            _previousInput = input;

            if (!IsReady)
                return 50m;

            var average1 = _sumBuyingPressure1 / _sumTrueRange1;
            var average2 = _sumBuyingPressure2 / _sumTrueRange2;
            var average3 = _sumBuyingPressure3 / _sumTrueRange3;

            return 100m * (4 * average1 + 2 * average2 + average3) / 7;
        }
開發者ID:kaffeebrauer,項目名稱:Lean,代碼行數:36,代碼來源:UltimateOscillator.cs

示例13: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="window">The window of data held in this indicator</param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(IReadOnlyWindow<TradeBar> window, TradeBar input)
        {
            if (!IsReady)
            {
                return 0m;
            }

            decimal value;
            if (
               (
                  // white engulfs black
                  GetCandleColor(window[1]) == CandleColor.White && GetCandleColor(window[2]) == CandleColor.Black &&
                  window[1].Close > window[2].Open && window[1].Open < window[2].Close &&
                  // third candle higher
                  input.Close > window[1].Close
                )
                ||
                (
                  // black engulfs white
                  GetCandleColor(window[1]) == CandleColor.Black && GetCandleColor(window[2]) == CandleColor.White &&
                  window[1].Open > window[2].Close && window[1].Close < window[2].Open &&
                  // third candle lower
                  input.Close < window[1].Close
                )
              )
                value = (int)GetCandleColor(window[1]);
            else
                value = 0;

            return value;
        }
開發者ID:kaffeebrauer,項目名稱:Lean,代碼行數:37,代碼來源:ThreeOutside.cs

示例14: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The input given to the indicator</param>
        /// <returns> A new value for this indicator </returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            var obv = Current.Value;

            if (_previousInput != null && input.Value > _previousInput.Value)
            {
                if (Current.Value != 0)
                {
                    obv = input.Volume + Current.Value;
                    Update(input);

                    _previousInput = input;
                    return obv;
                }
            }

            if (_previousInput != null && input.Value < _previousInput.Value)
            {
                if (Current.Value != 0)
                {
                    obv = Current.Value - input.Volume;
                    Update(input);

                    _previousInput = input;
                    return obv;
                }
            }

            _previousInput = input;
            return obv;
        }
開發者ID:tremblayEric,項目名稱:LeanHistory,代碼行數:36,代碼來源:OnBalanceVolume.cs

示例15: ComputeNextValue

        /// <summary>
        /// Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="input">The trade bar input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override decimal ComputeNextValue(TradeBar input)
        {
            // On first iteration we can’t produce an SAR value so we save the current bar and return zero
            if (Samples == 1)
            {
                _previousBar = input;

                // return a value that's close to where we will be, returning 0 doesn't make sense
                return input.Close;
            }

            // On second iteration we initiate the position the extreme point and the SAR
            if (Samples == 2)
            {
                Init(input);
                _previousBar = input;
                return _sar;
            }

            if (_isLong)
            {
                HandleLongPosition(input);
            }
            else
            {
                HandleShortPosition(input);
            }

            _previousBar = input;

            return _outputSar;
        }
開發者ID:skyfyl,項目名稱:Lean,代碼行數:37,代碼來源:ParabolicStopAndReverse.cs


注:本文中的QuantConnect.Data.Market.TradeBar類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。