示例#1
0
        protected override bool Rule(Trade trade, Portfolio portfolio, DateTime AsOf, TimeOfDay timeOfDay)
        {
            PriceBar bar = trade.Security.GetPriceBar(AsOf, PriceBarSize.Daily);
            decimal  atr = bar.AverageTrueRange(Stoploss_Atr_Period);

            if (bar.Close - (atr * Stoploss_Multiple) < 0)
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        private static void Candlestick_Hammer(this PriceBar me)
        {
            decimal wickToBody     = 2.0m;
            decimal upperWickLimit = .25m;

            // Bottom of a down trend, with a lower wick at least 2x body, closing at or near high

            // Define downtrend using SP bar count
            var priorBars = me.PriorBars(3, false);

            if (priorBars.Count < 3)
            {
                me.SetCandlestickFlag(CandleStickPattern.BullishHammer, false);
                return;
            }

            if (priorBars.Min(x => x.Low) <= Math.Min(me.Open, me.Close))
            {
                me.SetCandlestickFlag(CandleStickPattern.BullishHammer, false);
                return;
            }

            var lowerWick = Math.Min(me.Open, me.Close) - me.Low;
            var upperWick = me.High - Math.Max(me.Open, me.Close);
            var body      = Math.Abs(me.Change);

            if (lowerWick < 0)
            {
                me.SetCandlestickFlag(CandleStickPattern.BullishHammer, false);
                return;
            }
            if (body > 0 && lowerWick / body < wickToBody)
            {
                me.SetCandlestickFlag(CandleStickPattern.BullishHammer, false);
                return;
            }
            if (lowerWick < me.AverageTrueRange())
            {
                me.SetCandlestickFlag(CandleStickPattern.BullishHammer, false);
                return;
            }
            if (upperWick > body * upperWickLimit)
            {
                me.SetCandlestickFlag(CandleStickPattern.BullishHammer, false);
                return;
            }

            me.SetCandlestickFlag(CandleStickPattern.BullishHammer, true);
            return;
        }