예제 #1
0
        public void Indicators_Make_TrueRange_for_rts()
        {
            List <Bar> bars = new List <Bar>();

            bars.Add(new Bar(new DateTime(2013, 10, 11, 0, 0, 0), 148630, 149220, 148600, 149140, 35));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 11, 0, 0), 149170, 149310, 148380, 148800, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 12, 0, 0), 148800, 148810, 147470, 147900, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 13, 0, 0), 147910, 148370, 147800, 148250, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 14, 0, 0), 148240, 148340, 147920, 148130, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 15, 0, 0), 148110, 148290, 148000, 148260, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 16, 0, 0), 148260, 148260, 147940, 147980, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 17, 0, 0), 147990, 148110, 147670, 147680, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 18, 0, 0), 147680, 147940, 147110, 147920, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 11, 19, 0, 0), 147920, 148030, 147550, 147810, 38));

            IEnumerable <double> result = TrueRange.Values(bars);

            Assert.AreEqual(10, result.Count());

            Assert.AreEqual(620, result.ElementAt(0));
            Assert.AreEqual(930, result.ElementAt(1));
            Assert.AreEqual(1340, result.ElementAt(2));
            Assert.AreEqual(570, result.ElementAt(3));
            Assert.AreEqual(420, result.ElementAt(4));
            Assert.AreEqual(290, result.ElementAt(5));
            Assert.AreEqual(320, result.ElementAt(6));
            Assert.AreEqual(440, result.ElementAt(7));
            Assert.AreEqual(830, result.ElementAt(8));
            Assert.AreEqual(480, result.ElementAt(9));
        }
예제 #2
0
        /// <summary>
        /// Обработчик появления новых данных
        /// Вычисляет среднюю за период
        /// Вычисляет отклонение источника от средней за период
        /// </summary>
        ///// <param name="item">Bar</param>
        //public override void OnEvent(long id)
        public void Do(long id)
        {
            ///вычисляем новые занчения
            ///Input
            var    input      = Input.Value.ToList <Bar>();
            double iTrueRange = TRx.Indicators.BarSource.Indicator.TrueRange_i(
                input, input.Count - 1);

            TrueRange.Add(iTrueRange);

            ///вызываем обработчики значений
            foreach (var handler in HandlersTrueRange)
            {
                handler.Invoke(TrueRange.Last());
            }

            ///упаковка посчитанных значений
            ValueTrueRange.Add(new ValueDouble()
            {
                Id = id,
                //DateTime = item.DateTime,
                //TODO 4. сейчас отрисовывается по имени MaFast, надо переделать на стороне отрисовки
                Name  = "TrueRange",
                Value = iTrueRange
            });

            ///отправка посчитанных значений
            foreach (var handler in HandlersValueTrueRange)
            {
                handler.Invoke(ValueTrueRange.Last());
            }
        }
예제 #3
0
 protected override void Initialize()
 {
     // Initialize and create nested indicators
     // tr = CreateDataSeries();
     tri  = Indicators.TrueRange();
     TRMA = Indicators.MovingAverage(TrResult, Periods, MovingAverageType.Simple);
 }
예제 #4
0
        public override void GetAll(IIndicatorValues Ind)
        {
            int period = (int)this.IndicatorParameters.List[0];

            if (!Ind.TrueRange(period).IsPopulated)
            {
                int oldCurrentBar = Ind.Bar.CurrentBar;
                for (int i = 1; i <= Ind.Bar.MaxBar; i++)
                {
                    Ind.Bar.CurrentBar = i;

                    object prototype = null;
                    if (i == 1)
                    {
                        prototype = new TrueRange();
                    }
                    else
                    {
                        prototype = (TrueRange)Ind.TrueRange(period)[1].Clone();
                    }

                    Get(ref prototype, Ind);

                    Ind.TrueRange(period)[0] = (TrueRange)prototype;

                    Ind.TrueRange(period).IsPopulated = true;                     // set here so instance is guaranteed to exits
                }

                Ind.Bar.CurrentBar = oldCurrentBar;
            }
        }
예제 #5
0
        protected override void Initialize()
        {
            // Initialize and create nested indicators
            tr = CreateDataSeries();
            tri = Indicators.TrueRange();
            TRMA = Indicators.MovingAverage(tr, Periods, MovingAverageType.Simple);

        }
예제 #6
0
 protected override void Initialize()
 {
     // Initialize and create nested indicators
     CCI = Indicators.CommodityChannelIndex(CCI_Period);
     atr = CreateDataSeries();
     tr = CreateDataSeries();
     tri = Indicators.TrueRange();
 }
예제 #7
0
 protected override void Initialize()
 {
     // Initialize and create nested indicators
     CCI = Indicators.CommodityChannelIndex(CCI_Period);
     atr = CreateDataSeries();
     tr  = CreateDataSeries();
     tri = Indicators.TrueRange();
 }
예제 #8
0
        public async Task TestTrueRangeAsync()
        {
            var candles = await ImportCandlesAsync();

            var indicator = new TrueRange(candles);
            var result    = indicator[candles.Count() - 1];

            Assert.IsTrue(0.94m.IsApproximatelyEquals(result.Tick.Value));
        }
예제 #9
0
 protected override void Initialize()
 {
     // Initialize and create nested indicators
     tr    = CreateDataSeries();
     tri   = Indicators.TrueRange();
     TRMAF = Indicators.MovingAverage(tr, FPeriods, MovingAverageType.Simple);
     TRMAM = Indicators.MovingAverage(tr, MPeriods, MovingAverageType.Simple);
     TRMAS = Indicators.MovingAverage(tr, SPeriods, MovingAverageType.Simple);
 }
예제 #10
0
        public void Indicators_Make_TrueRange_for_bar_test()
        {
            List <Bar> bars = new List <Bar>();

            bars.Add(new Bar(new DateTime(2013, 10, 1), 50, 55, 49, 51, 35));
            bars.Add(new Bar(new DateTime(2013, 10, 2), 51, 56, 48, 52, 38));
            bars.Add(new Bar(new DateTime(2013, 10, 3), 49, 53, 44, 50, 41));

            Assert.AreEqual(6, TrueRange.Value(bars, 0));
            Assert.AreEqual(8, TrueRange.Value(bars, 1));
            Assert.AreEqual(9, TrueRange.Value(bars, 2));
        }
예제 #11
0
        public Density(Bars bars, int NBars, string description)
            : base(bars, description)
        {
            base.FirstValidValue = NBars;

            DataSeries Area = (Highest.Series(bars.High, NBars) - Lowest.Series(bars.Low, NBars));

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                base[bar] = Sum.Series(TrueRange.Series(bars), NBars)[bar] / Area[bar];
            }
        }
예제 #12
0
        protected override string GetPresentDetail(IOutputInstant Instant, IIndicatorValues Data, IndicatorParameters IndicatorParameters)
        {
            TrueRange tr = Data.TrueRange(IndicatorParameters)[Instant.ExposureDate];

            if (tr != null)
            {
                return(String.Format("{0}|", tr.Value));
            }
            else
            {
                return(String.Format("{0}|", ""));
            }
        }
예제 #13
0
        public TrendQuality(Bars bars, int period, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period;
            double val = 0.0; double net = 0.0; double gross = 0.0;

            for (int bar = FirstValidValue; bar < bars.Count; bar++)
            {
                net       = Momentum.Series(bars.Close, period)[bar];
                gross     = Sum.Series(TrueRange.Series(bars), period)[bar];
                val       = (gross > 0) ? (net / gross) * 100 : 0;
                base[bar] = val;
            }
        }
예제 #14
0
        public Choppiness(Bars bars, int period, string description)
            : base(bars, description)
        {
            base.FirstValidValue = period;

            double     true_high, true_low, true_rng, sum;
            DataSeries n_high = bars.High - bars.High;
            DataSeries n_low  = bars.Low - bars.Low;

            for (int bar = bars.FirstActualBar + period; bar < bars.Count; bar++)
            {
                true_high   = Math.Max(bars.High[bar], bars.Close[bar - 1]);
                true_low    = Math.Min(bars.Low[bar], bars.Close[bar - 1]);
                true_rng    = TrueRange.Series(bars)[bar];
                n_high[bar] = true_high;
                n_low[bar]  = true_low;
            }

            DataSeries trueHigh = Highest2.Series(bars.High, bars.Close >> 1, period);
            DataSeries trueLow  = Lowest2.Series(bars.Low, bars.Close >> 1, period);

            double nHigh, nLow, nRange, ratio, log_ratio, log_n;

            for (int bar = bars.FirstActualBar + period; bar < bars.Count; bar++)
            {
                // OLD:

                /* nHigh = Highest.Series( n_high, period )[bar];
                 * nLow = Lowest.Series( n_low, period )[bar]; */

                // NEW:
                nHigh = trueHigh[bar];
                nLow  = trueLow[bar];

                nRange    = nHigh - nLow;
                sum       = Sum.Series(TrueRange.Series(bars), period)[bar];
                ratio     = sum / nRange;
                log_ratio = Math.Log(ratio);
                log_n     = Math.Log(period);

                if (bar <= period)
                {
                    base[bar] = 50;
                }
                else
                {
                    base[bar] = 100 * log_ratio / log_n;
                }
            }
        }
예제 #15
0
파일: NRTR.cs 프로젝트: ToniTsai/LeetCode
        public NRTR_WATR(Bars bars, int lookback, double multiple, string description)
            : base(bars, description)
        {
            base.FirstValidValue = lookback;

            int    Trend   = 0;
            double Reverse = 0;
            double HPrice  = 0;
            double LPrice  = 0;

            DataSeries K = WMA.Series(TrueRange.Series(bars), lookback) * multiple;

            for (int bar = base.FirstValidValue; bar < bars.Count; bar++)
            {
                // Calculate the NRTR_WATR Series
                if (Trend >= 0)
                {
                    HPrice  = Math.Max(bars.Close[bar], HPrice);
                    Reverse = HPrice - K[bar];

                    if (bars.Close[bar] <= Reverse)
                    {
                        Trend   = -1;
                        LPrice  = bars.Close[bar];
                        Reverse = LPrice + K[bar];
                    }
                }
                if (Trend <= 0)
                {
                    LPrice  = Math.Min(bars.Close[bar], LPrice);
                    Reverse = LPrice + K[bar];

                    if (bars.Close[bar] >= Reverse)
                    {
                        Trend   = 1;
                        HPrice  = bars.Close[bar];
                        Reverse = HPrice - K[bar];
                    }
                }

                base[bar] = Reverse;
            }
        }
예제 #16
0
파일: PGO.cs 프로젝트: vmsalinasg/cAlgoBot
 protected override void Initialize()
 {
     _sma       = Indicators.SimpleMovingAverage(MarketSeries.Close, Period);
     _trueRange = (TrueRange)Indicators.TrueRange();
     _ema       = Indicators.ExponentialMovingAverage(_trueRange.Result, Period);
 }
 protected override void Initialize()
 {
     tr = CreateDataSeries();
     tri = Indicators.TrueRange();
     ema = Indicators.ExponentialMovingAverage(tr, Period);
 }
예제 #18
0
 protected override void Initialize()
 {
     alpha = 2.0 / (Period + 1.0);
     tr    = Indicators.TrueRange();
 }
예제 #19
0
        private void BData_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                var candle        = (BinanceCandle)e.NewItems[0];
                var TPC           = (candle.Candle.High + candle.Candle.Low + candle.Candle.Close) / 3;
                var TPVM          = TPC * candle.Candle.Volume;
                var RawData       = Starter.core.Candles.Select(y => y.Candle).ToList();
                int countIndex    = RawData.Count - 1;
                var indexdcandles = new IndexedCandle(RawData, RawData.Count() - 1);
                //public static class OhlcvExtension

                //zone to update with TA - Node (temporary here)
                try
                {
                    var rsi        = RawData.Rsi(12, 0, countIndex);
                    var bb         = RawData.BbWidth(20, 2);
                    var macd       = RawData.Macd(7, 10, 12);
                    var chandelier = RawData.Chandlr(14, 22);
                    var ichimoku   = RawData.Ichimoku(9, 26, 52);
                    var KAMA       = RawData.Kama(21, 12, 32);
                    var Median     = RawData.Median(12);
                    var PSAR       = RawData.Sar(0.2m, 0.2m);
                    var DM         = new DownMomentum(RawData);
                    var bbw        = new BollingerBands(RawData, 20, 2);
                    var UM         = new UpMomentum(RawData);
                    var Bullish    = new Bullish(RawData);
                    var Bearish    = new Bearish(RawData);
                    var trendup    = new UpTrend(RawData);
                    var trenddown  = new DownTrend(RawData);
                    var dmi        = new DynamicMomentumIndex(RawData, 14, 30, 12, 70, 30);
                    var minusDI    = new MinusDirectionalIndicator(RawData, 12);
                    var truerange  = new TrueRange(RawData);
                    var efratio    = new EfficiencyRatio(RawData, 12);
                    var obv        = new OnBalanceVolume(RawData);
                    var sthrsi     = new StochasticsRsiOscillator(RawData, 12);
                    if (rsi.Count() > 0)
                    {
                        //TA
                        candle.Properties.Add("RSI", rsi.Last().Tick);
                        candle.Properties.Add("DOWNMOMENTUM", DM.Compute(12).Last().Tick);
                        candle.Properties.Add("UPMOMENTUM", UM.Compute(12).Last().Tick);
                        candle.Properties.Add("MACD", macd.Last().Tick);
                        candle.Properties.Add("BB", bb.Last().Tick);
                        candle.Properties.Add("bbw", bbw.Compute().Last().Tick);
                        candle.Properties.Add("PSAR", PSAR.Last().Tick);
                        candle.Properties.Add("CHANDELIEREXIT", chandelier.Last().Tick);
                        candle.Properties.Add("ichimoku", ichimoku.Last().Tick);
                        candle.Properties.Add("KAMA", KAMA.Last().Tick);
                        candle.Properties.Add("Median", Median.Last().Tick);
                        candle.Properties.Add("DynamicMomentumIndex", dmi.Compute(12).Last().Tick);
                        candle.Properties.Add("MinusDirectionalIndicator", minusDI.Compute(12).Last().Tick);
                        candle.Properties.Add("TrueRange", truerange.Compute(12).Last().Tick);
                        candle.Properties.Add("EfficiencyRatio", efratio.Compute(12).Last().Tick);
                        candle.Properties.Add("OnBalanceVolume", obv.Compute(12).Last().Tick);
                        candle.Properties.Add("StochasticsRsiOscillator", sthrsi.Compute(12).Last().Tick);

                        //Pattern Periodic
                        candle.Properties.Add("BullishPeriodic_L1", Bullish.Compute(12).Last().Tick);
                        candle.Properties.Add("BearishPeriodic_L1", Bearish.Compute(12).Last().Tick);
                        candle.Properties.Add("UptrendPeriodic_L1", trendup.Compute(12).Last().Tick);
                        candle.Properties.Add("DowntrendPeriodic_L1", trenddown.Compute(12).Last().Tick);
                        Console.WriteLine(candle.ToString());

                        //candle.Properties.Add("BullishPeriodic_L2", Bullish.Compute(24).Last().Tick);
                        //candle.Properties.Add("BearishPeriodic_L2", Bearish.Compute(24).Last().Tick);
                        //candle.Properties.Add("UptrendPeriodic_L2", trendup.Compute(24).Last().Tick);
                        //candle.Properties.Add("DowntrendPeriodic_L2", trenddown.Compute(24).Last().Tick);


                        //candle.Properties.Add("BullishPeriodic_L3", Bullish.Compute(36).Last().Tick);
                        //candle.Properties.Add("BearishPeriodic_L3", Bearish.Compute(36).Last().Tick);
                        //candle.Properties.Add("UptrendPeriodic_L3", trendup.Compute(36).Last().Tick);
                        //candle.Properties.Add("DowntrendPeriodic_L3", trenddown.Compute(36).Last().Tick);

                        //PatternInject
                        candle.Properties.Add("bearish", indexdcandles.IsBearish());
                        candle.Properties.Add("isbullish", indexdcandles.IsBullish());
                        candle.Properties.Add("isaccumdistbearish", indexdcandles.IsAccumDistBearish());
                        candle.Properties.Add("isaccumdistbullish", indexdcandles.IsAccumDistBullish());
                        candle.Properties.Add("closepricepercentagechange", indexdcandles.ClosePricePercentageChange());
                        candle.Properties.Add("closepricechange", indexdcandles.ClosePriceChange());
                        candle.Properties.Add("isbreakinghistoricalhighestclose", indexdcandles.IsBreakingHistoricalHighestClose());
                        candle.Properties.Add("isbreakinghistoricalhighesthigh", indexdcandles.IsBreakingHistoricalHighestHigh());
                        candle.Properties.Add("isbreakinghistoricallowestlow", indexdcandles.IsBreakingHistoricalLowestLow());
                        candle.Properties.Add("isobvbearish", indexdcandles.IsObvBearish());
                        candle.Properties.Add("isobvbullish", indexdcandles.IsObvBullish());
                        candle.UpdateContainer();
                    }
                }
                catch { }
                var LastBinanceCandle = (BinanceCandle)e.NewItems[0];

                Console.WriteLine("Market Node - Sending candle : {0} to suscribers", LastBinanceCandle.UID);
                Messages Content = new Messages();
                Content.Content      = candle.Jscontainer;
                Content.MessageType  = TypeOfContent.Binance_Candles;
                Content.RootType     = candle.TypeOfData;
                Content.TargetObject = "BinanceCandle";
                try
                {
                    Send(Content.ToString());
                    this.Starter.core.Candles.Clear();
                }
                catch
                {
                }
            }
        }
예제 #20
0
 protected override void Initialize()
 {
     atr = CreateDataSeries();
     tri = Indicators.TrueRange();
     expo = Indicators.MovingAverage(MarketSeries.Close, KeltnerPeriod, matype);
 }
예제 #21
0
 protected override void Initialize()
 {
     atr  = CreateDataSeries();
     tri  = Indicators.TrueRange();
     expo = Indicators.MovingAverage(MarketSeries.Close, KeltnerPeriod, matype);
 }
예제 #22
0
 protected override void Initialize()
 {
     _globalSeries = MarketData.GetSeries(Symbol, GlobalTimeFrame);
     _globalTr = Indicators.TrueRange(_globalSeries);
     _globalAtr = Indicators.AverageTrueRange(_globalSeries, AtrPeriod, AtrMovingAverageType);
 }
예제 #23
0
 protected override void Initialize()
 {
     _tri = Indicators.TrueRange();
 }
예제 #24
0
        /// <summary>
        /// Initialize test
        /// </summary>
        public TestIndicatorTrueRange()
        {
            DataStream stream = new OHLCBarStream(new ForexSecurity("EURUSD"), BarInterval.FiveMin);

            _sut = new TrueRange(stream, stream.DefaultInterval);
        }
 protected override void Initialize()
 {
     tr = Indicators.TrueRange();
 }
예제 #26
0
파일: PGO.cs 프로젝트: Mikai47/cAlgoBot
 protected override void Initialize()
 {
     _sma = Indicators.SimpleMovingAverage(MarketSeries.Close, Period);
     _trueRange = (TrueRange)Indicators.TrueRange();
     _ema = Indicators.ExponentialMovingAverage(_trueRange.Result, Period);
 }
예제 #27
0
 protected override void Initialize()
 {
     tr  = CreateDataSeries();
     tri = Indicators.TrueRange();
     ema = Indicators.ExponentialMovingAverage(tr, Period);
 }
예제 #28
0
 protected override void Initialize()
 {
     _globalSeries = MarketData.GetSeries(Symbol, GlobalTimeFrame);
     _globalTr     = Indicators.TrueRange(_globalSeries);
     _globalAtr    = Indicators.AverageTrueRange(_globalSeries, AtrPeriod, AtrMovingAverageType);
 }