/// <summary>
        /// Called when the order has been filled during the bar update.
        /// </summary>
        /// <param name="currentBar">Current bar of the simulation for the order</param>
        /// <returns>True if the order was closed</returns>
        public override bool OnUpdate(int currentBar)
        {
            // Don't sell if the indicator is wobbily.
            if (_order.BuyBar >= currentBar - 2)
            {
                return(false);
            }

            TickerData data           = _order.Ticker;
            double     crossoverValue = _series2 != null ? _series2[currentBar] : _value;

            if (_crossoverType == CrossoverType.Above &&
                ((_series2 == null && DataSeries.CrossAbove(_series1, crossoverValue, currentBar, 0) != -1) ||
                 (_series2 != null && DataSeries.CrossAbove(_series1, _series2, currentBar, 0) != -1)))
            {
                _order.Sell(data.Close[currentBar], currentBar, "Cross Above");
                return(true);
            }
            else if (_crossoverType == CrossoverType.Below &&
                     ((_series2 == null && DataSeries.CrossBelow(_series1, crossoverValue, currentBar, 0) != -1) ||
                      (_series2 != null && DataSeries.CrossBelow(_series1, _series2, currentBar, 0) != -1)))
            {
                _order.Sell(data.Close[currentBar], currentBar, "Cross Below");
                return(true);
            }

            // Didn't sell.
            return(false);
        }
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            Bollinger ind = (Bollinger)Dependents[0];

            if (DataSeries.CrossAbove(Data.Close, ind.Upper, currentBar, 0) != -1)
            {
                WasFound[currentBar] = true;
            }
        }
Пример #3
0
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            Sma sma = (Sma)Dependents[0];

            if (DataSeries.CrossAbove(Data.Close, sma.Avg, currentBar, 0) != -1)
            {
                WasFound[currentBar] = true;
            }
        }
Пример #4
0
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            Trix ind = (Trix)Dependents[0];

            if (DataSeries.CrossAbove(ind.Default, 0, currentBar, 0) != -1)
            {
                WasFound[currentBar] = true;
            }
        }
Пример #5
0
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            Cci ind = (Cci)Dependents[0];

            if (DataSeries.CrossAbove(ind.Value, -100, currentBar, 0) != -1)
            {
                WasFound[currentBar] = true;
            }
        }
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            PriceOscillator ind = (PriceOscillator)Dependents[0];

            if (DataSeries.CrossAbove(ind.Value, 0, currentBar, 0) != -1)
            {
                WasFound[currentBar] = true;
            }
        }
Пример #7
0
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            Macd macd = (Macd)Dependents[0];

            if (DataSeries.CrossAbove(macd.Value, macd.Avg, currentBar, 0) != -1)
            {
                WasFound[currentBar] = true;
            }
        }
Пример #8
0
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            Rsi rsi = (Rsi)Dependents[0];

            if (DataSeries.CrossAbove(rsi.Value, 30, currentBar, 0) != -1)
            {
                WasFound[currentBar] = true;
            }
        }
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            Stochastics ind = (Stochastics)Dependents[0];

            if (DataSeries.IsBelow(ind.D, 20, currentBar, 0) != -1)
            {
                if (DataSeries.CrossAbove(ind.K, ind.D, currentBar, 0) != -1)
                {
                    WasFound[currentBar] = true;
                }
            }
        }
Пример #10
0
        /// <summary>
        /// Called when the order has been filled during the bar update.
        /// </summary>
        /// <param name="currentBar">Current bar of the simulation for the order</param>
        /// <returns>True if the order was closed</returns>
        public override bool OnUpdate(int currentBar)
        {
            if (_order.BuyBar == currentBar)
            {
                return(false);
            }

            TickerData data = _order.Ticker;

            if (_order.Type == Order.OrderType.Long)
            {
                // If the oscillator moves out from the oversold area but then goes back in it
                // then it's not going to be able to go back up so we should sell it.
                if (DataSeries.CrossAbove(_oscillator.SD, DtOscillator.OversoldZone, currentBar, 4) != -1 &&
                    DataSeries.CrossBelow(_oscillator.SD, DtOscillator.OversoldZone, currentBar, 0) != -1)
                {
                    _order.Sell(data.Close[currentBar], currentBar, "DTosc Fail");
                    return(true);
                }

                // If we reverse out of the overbought area then the cycle is coming back down and we should
                // take our profits.
                if (DataSeries.CrossBelow(_oscillator.SD, DtOscillator.OverboughtZone, currentBar, 0) != -1)
                {
                    _order.Sell(data.Close[currentBar], currentBar, "DTosc Reverse");
                    return(true);
                }
            }
            // Comments are just the same for short orders but the opposite direction.
            else if (_order.Type == Order.OrderType.Short)
            {
                if (DataSeries.CrossBelow(_oscillator.SD, DtOscillator.OverboughtZone, currentBar, 4) != -1 &&
                    DataSeries.CrossAbove(_oscillator.SD, DtOscillator.OverboughtZone, currentBar, 0) != -1)
                {
                    _order.Sell(data.Close[currentBar], currentBar, "DTosc Fail");
                    return(true);
                }

                if (DataSeries.CrossAbove(_oscillator.SD, DtOscillator.OversoldZone, currentBar, 0) != -1)
                {
                    _order.Sell(data.Close[currentBar], currentBar, "DTosc Reverse");
                    return(true);
                }
            }

            // Didn't sell.
            return(false);
        }
Пример #11
0
        /// <summary>
        /// Called on every new bar of data.
        /// </summary>
        /// <param name="currentBar">The current bar of the simulation</param>
        protected override void OnBarUpdate(int currentBar)
        {
            base.OnBarUpdate(currentBar);

            if (currentBar < 1)
            {
                return;
            }

            DtOscillator ind = (DtOscillator)Dependents[0];

            if (DataSeries.IsBelow(ind.SK, 25, currentBar, 1) != -1)
            {
                if (DataSeries.CrossAbove(ind.SK, ind.SD, currentBar, 0) != -1)
                {
                    WasFound[currentBar] = true;
                }
            }
        }
Пример #12
0
        /// <summary>
        /// Returns true if we pass all the conditions to buy short.
        /// </summary>
        /// <param name="currentBar">Current bar of the simulation</param>
        /// <returns>See summary</returns>
        private bool ShouldBuyShort(int currentBar)
        {
            DmiAdx dmiAdx = (DmiAdx)_dependents[1];

            bool isHigherTimeframeLong = Data.HigherTimeframeTrend[currentBar] > 0.0;

            // For a cross over.
            bool isAdxHighEnough       = dmiAdx.Adx[currentBar] >= 20.0;
            bool isDmiAboutToCrossover = DataSeries.IsAboutToCrossAbove(dmiAdx.DmiPlus, dmiAdx.DmiMinus, currentBar);

            // Adx was low but just increased and our dmi lines are already crossed over.
            bool didAdxCrossover   = DataSeries.CrossAbove(dmiAdx.Adx, 20.0, currentBar, 0) != -1;
            bool hasDmiCrossedover = DataSeries.CrossAbove(dmiAdx.DmiPlus, dmiAdx.DmiMinus, currentBar, 8) != -1;

            // Either case is good for an entry signal.
            bool isDmiAdxSignal = (isAdxHighEnough && isDmiAboutToCrossover) || (didAdxCrossover && hasDmiCrossedover);

            return(isHigherTimeframeLong && isDmiAdxSignal);
        }
Пример #13
0
        /// <summary>
        /// Returns true if we pass all the conditions to buy long.
        /// </summary>
        /// <param name="currentBar">Current bar of the simulation</param>
        /// <returns>See summary</returns>
        private bool ShouldBuyLong(int currentBar)
        {
            GavalasZones zones = (GavalasZones)_dependents[0];

            // Higher timeframe
            if (Data.HigherTimeframeTrend[currentBar] < 0.0)
            {
                return(false);
            }

            // Zones buy direction
            if (_lastZoneHitDirection < 0.0)
            {
                return(false);
            }

            // Verify with the mechanical buy signal.
            DtOscillator dtosc = (DtOscillator)_dependents[1];

            if (DataSeries.IsBelow(dtosc.SK, DtOscillator.OversoldZone, currentBar, 3) == -1 ||
                DataSeries.CrossAbove(dtosc.SK, dtosc.SD, currentBar, 0) == -1)
            {
                return(false);
            }

            // If we are trending make sure the best fits lines are positive.
            DmiAdx dmiAdx = (DmiAdx)_dependents[3];

            if (dmiAdx.Adx[currentBar] >= 25)
            {
                double angle = UtilityMethods.RadianToDegree(Math.Atan(zones.AllBestFitLineSlope[currentBar]));
                if (angle < 0)
                {
                    return(false);
                }
            }

            // TODO?
            // If we are not trending make sure we are close to the bottom of the channel?

            return(true);
        }
Пример #14
0
        /// <summary>
        /// Returns true if we pass all the conditions to buy long.
        /// </summary>
        /// <param name="currentBar">Current bar of the simulation</param>
        /// <returns>See summary</returns>
        private bool ShouldBuyLong(int currentBar)
        {
            // Higher timeframe
            if (Data.HigherTimeframeTrend[currentBar] < 0.0)
            {
                return(false);
            }

            KeltnerChannel kelt = (KeltnerChannel)_dependents[2];

            //if (DataSeries.CrossBelow(Data.Low, kelt.Lower, currentBar, 5) == -1)
            //{
            //	return false;
            //}

            if (Math.Max(Data.Open[currentBar], Data.Close[currentBar]) > kelt.Midline[currentBar])
            {
                return(false);
            }

            DtOscillator dtosc = (DtOscillator)_dependents[3];

            if (DataSeries.IsBelow(dtosc.SD, DtOscillator.OversoldZone, currentBar, 3) == -1 ||
                DataSeries.IsBelow(dtosc.SK, DtOscillator.OversoldZone, currentBar, 3) == -1 ||
                DataSeries.CrossAbove(dtosc.SK, dtosc.SD, currentBar, 0) == -1)
            {
                return(false);
            }

            // Make sure we are not in a heavy trend the other way.
            //DmiAdx dmiAdx = (DmiAdx)_dependents[1];
            //if (dmiAdx.Adx[currentBar] > 30 && dmiAdx.DmiMinus[currentBar] > dmiAdx.DmiPlus[currentBar] &&
            //	UtilityMethods.LineAngle(currentBar - 2, dmiAdx.Adx[currentBar - 2], currentBar, dmiAdx.Adx[currentBar]) > 5)
            //{
            //	return false;
            //}

            return(true);
        }