/// <summary>
        ///      Computes the next value of this indicator from the given state
        /// </summary>
        /// <param name="time"></param>
        /// <param name="input">The input given to the indicator</param>
        /// <returns>A new value for this indicator</returns>
        protected override DoubleArray Forward(long time, DoubleArray input)
        {
            _adx.Update(time, input);

            if (_adx.IsReady)
            {
                _adxHistory.Add(_adx);
            }

            return(IsReady ? (_adx + _adxHistory[_period - 1]) / 2 : 50.0d);
        }
Пример #2
0
        public void ResetsProperly()
        {
            var adxIndicator = new AverageDirectionalIndex("ADX", 14);

            foreach (var data in TestHelper.GetTradeBarStream("spy_with_adx.txt", false))
            {
                adxIndicator.Update(data);
            }

            Assert.IsTrue(adxIndicator.IsReady);

            adxIndicator.Reset();
        }
Пример #3
0
        public bool Update(TradeBar data, decimal holdings)
        {
            _data     = data;
            _holdings = holdings;

            var isReady = _ich.Update(data) && _adx.Update(data) && _vwap.Update(data);

            _consolidation.RollConsolidationWindow();
            _consolidation.Consolidate(data, _ich);

            //_volume.Add(data.Volume);

            TrendDirection = IsBullishTrend()
                ? Direction.Bullish
                : IsBearishTrend() ? Direction.Bearish : Direction.None;

            return(isReady);
        }
        /// <summary>
        /// Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.
        /// </summary>
        public override void Initialize()
        {
            // initialize algorithm level parameters
            SetStartDate(2013, 10, 07);
            SetEndDate(2013, 10, 11);
            //SetStartDate(2014, 01, 01);
            //SetEndDate(2014, 06, 01);
            SetCash(100000);

            // leverage tradier $1 traders
            SetBrokerageModel(BrokerageName.TradierBrokerage);

            // request high resolution equity data
            AddSecurity(SecurityType.Equity, symbol, Resolution.Second);

            // save off our security so we can reference it quickly later
            Security = Securities[symbol];

            // Set our max leverage
            Security.SetLeverage(MaximumLeverage);

            // define our longer term indicators
            ADX14   = ADX(symbol, 28, Resolution.Hour);
            STD14   = STD(symbol, 14, Resolution.Daily);
            ATR14   = ATR(symbol, 14, resolution: Resolution.Daily);
            PSARMin = new ParabolicStopAndReverse(symbol, afStart: 0.0001m, afIncrement: 0.0001m);

            // smooth our ATR over a week, we'll use this to determine if recent volatilty warrants entrance
            var oneWeekInMarketHours = (int)(5 * 6.5);

            SmoothedATR14 = new ExponentialMovingAverage("Smoothed_" + ATR14.Name, oneWeekInMarketHours).Of(ATR14);
            // smooth our STD over a week as well
            SmoothedSTD14 = new ExponentialMovingAverage("Smoothed_" + STD14.Name, oneWeekInMarketHours).Of(STD14);

            // initialize our charts
            var chart = new Chart(symbol);

            chart.AddSeries(new Series(ADX14.Name, SeriesType.Line, 0));
            chart.AddSeries(new Series("Enter", SeriesType.Scatter, 0));
            chart.AddSeries(new Series("Exit", SeriesType.Scatter, 0));
            chart.AddSeries(new Series(PSARMin.Name, SeriesType.Scatter, 0));
            AddChart(chart);

            var history = History(symbol, 20, Resolution.Daily);

            foreach (var bar in history)
            {
                ADX14.Update(bar);
                ATR14.Update(bar);
                STD14.Update(bar.EndTime, bar.Close);
            }

            // schedule an event to run every day at five minutes after our symbol's market open
            Schedule.Event("MarketOpenSpan")
            .EveryDay(symbol)
            .AfterMarketOpen(symbol, minutesAfterOpen: OpeningSpanInMinutes)
            .Run(MarketOpeningSpanHandler);

            Schedule.Event("MarketOpen")
            .EveryDay(symbol)
            .AfterMarketOpen(symbol, minutesAfterOpen: -1)
            .Run(() => PSARMin.Reset());
        }