public void Is_Not_Hammer_Test(TestCandlesContext context)
        {
            var downTrend     = new DownTrend();
            var hammerPattern = new Hammer(downTrend);

            var match = hammerPattern.Match(context);

            Assert.False(match.Success, "Candles do not create an Hammer pattern");
        }
        public void DownTrend_Wrong_Period_Return_False()
        {
            var context = new TestCandlesContext()
                          .WithCandleIndex(3);

            var downTrendPattern = new DownTrend();
            var match            = downTrendPattern.Match(context);

            Assert.False(match.Success);
        }
        public void Is_DownTrend_Test()
        {
            var context = new TestCandlesContext()
                          .WithDownTrend()
                          .WithCandleIndex(3);

            var downTrendPattern = new DownTrend();
            var match            = downTrendPattern.Match(context);

            Assert.True(match.Success, "Candles create an DownTrend pattern");
        }
Beispiel #4
0
 /// <summary>
 /// Called on each bar update event (incoming tick)
 /// </summary>
 protected override void OnBarUpdate()
 {
     // Use this method for calculating your indicator values. Assign a value to each
     // plot below by replacing 'Close[0]' with your own formula.
     if (CurrentBar < Lenght)
     {
         Trend.Set(true);
         UpTrend.Set(Close[0]);
         DownTrend.Set(Close[0]);
         return;
     }
     ;
     if (Close[0] > DownTrend[1])
     {
         Trend.Set(true);
     }
     else
     if (Close[0] < UpTrend[1])
     {
         Trend.Set(false);
     }
     else
     {
         Trend.Set(Trend[1]);
     }
     if (Trend[0] && !Trend[1])
     {
         UpTrend.Set(Median[0] - ATR(Lenght)[0] * Multiplier);
         UpTrend.Set(1, DownTrend[1]);
         if (ShowArrows)
         {
             DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, Color.Blue);
         }
     }
     else
     if (!Trend[0] && Trend[1])
     {
         DownTrend.Set(Median[0] + ATR(Lenght)[0] * Multiplier);
         DownTrend.Set(1, UpTrend[1]);
         if (ShowArrows)
         {
             DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, Color.Red);
         }
     }
     else
     if (Trend[0])
     {
         UpTrend.Set((Median[0] - ATR(Lenght)[0] * Multiplier) > UpTrend[1] ? (Median[0] - ATR(Lenght)[0] * Multiplier) : UpTrend[1]);
     }
     else
     {
         DownTrend.Set((Median[0] + ATR(Lenght)[0] * Multiplier) < DownTrend[1] ? (Median[0] + ATR(Lenght)[0] * Multiplier) : DownTrend[1]);
     }
 }
        public void Is_Hammer_Test()
        {
            var context = new TestCandlesContext()
                          .WithHammers()
                          .WithCandleIndex(4);

            var downTrend     = new DownTrend();
            var hammerPattern = new Hammer(downTrend);

            var match = hammerPattern.Match(context);

            Assert.True(match.Success, "Candles create an Hammer pattern");
        }
Beispiel #6
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
                {
                }
            }
        }
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 1)
            {
                if (_smooth > 1 && _avg == null)
                    switch (_maType)
                    {
                        case MovingAverageType.SMA:
                            _avg = SMA(Input, _smooth);
                            break;
                        case MovingAverageType.SMMA:
                            _avg = SMMA(Input, _smooth);
                            break;
                        case MovingAverageType.TMA:
                            _avg = TMA(Input, _smooth);
                            break;
                        case MovingAverageType.WMA:
                            _avg = WMA(Input, _smooth);
                            break;
                        case MovingAverageType.VWMA:
                            _avg = VWMA(Input, _smooth);
                            break;
                        case MovingAverageType.TEMA:
                            _avg = TEMA(Input, _smooth);
                            break;
                        case MovingAverageType.HMA:
                            _avg = HMA(Input, _smooth);
                            break;
                        case MovingAverageType.VMA:
                            _avg = VMA(Input, _smooth, _smooth);
                            break;
						case MovingAverageType.JMA:
							_avg = JurikJMA(Input, 0, _smooth);
							break;
                        default:
                            _avg = EMA(Input, _smooth);
                            break;
                    }
                else
                    _avg = Input;

                _trend.Set(true);
                UpTrend.Set(Input[0]);
                DownTrend.Set(Input[0]);
                return;
            }

            switch (_smode)
            {
                case SuperTrendMode.ATR:
                    _offset = ATR(_length)[0] * Multiplier;
                    break;
                case SuperTrendMode.Adaptive:
                    _offset = ATR(_length)[0] * HomodyneDiscriminator(Input)[0] / 10;
                    break;
                default:
                    _offset = Dtt(_length, Multiplier);
                    break;
            }

            if (FirstTickOfBar)
                _prevColor = _tempColor;

            _trend.Set(Close[0] > DownTrend[1] ? true : Close[0] < UpTrend[1] ? false : _trend[1]);

            if (_trend[0] && !_trend[1])
            {
                _th = High[0];
                UpTrend.Set(Math.Max(_avg[0] - _offset, _tl));
                if (Plots[0].PlotStyle == PlotStyle.Line) UpTrend.Set(1, DownTrend[1]);
                _tempColor = _barColorUp;
                if (ShowArrows)
                    DrawArrowUp(CurrentBar.ToString(), true, 0, UpTrend[0] - TickSize, _barColorUp);
                if(PlayAlert && _thisbar != CurrentBar)
                {
                    _thisbar = CurrentBar;
                    PlaySound(LongAlert);
                }
            }
            else
                if (!_trend[0] && _trend[1])
                {
                    _tl = Low[0];
                    DownTrend.Set(Math.Min(_avg[0] + _offset, _th));
                    if (Plots[1].PlotStyle == PlotStyle.Line) DownTrend.Set(1, UpTrend[1]);
                    _tempColor = _barColorDown;
                    if (ShowArrows)
                        DrawArrowDown(CurrentBar.ToString(), true, 0, DownTrend[0] + TickSize, _barColorDown);
                    if (PlayAlert && _thisbar != CurrentBar)
                    {
                        _thisbar = CurrentBar;
                        PlaySound(ShortAlert);
                    }
                }
                else
                {
                    if (_trend[0])
                    {
                        UpTrend.Set((_avg[0] - _offset) > UpTrend[1] ? (_avg[0] - _offset) : UpTrend[1]);
                        _th = Math.Max(_th, High[0]);
                    }
                    else
                    {
                        DownTrend.Set((_avg[0] + _offset) < DownTrend[1] ? (_avg[0] + _offset) : DownTrend[1]);
                        _tl = Math.Min(_tl, Low[0]);
                    }
                    RemoveDrawObject(CurrentBar.ToString());
                    _tempColor = _prevColor;
                }

            if (!_colorBars) 
                return;

            CandleOutlineColor = _tempColor;

            BarColor = Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick
                           ? Color.Transparent
                           : _tempColor;
        }
Beispiel #8
0
 public Hammer(DownTrend downTrendPattern, decimal lowerWickLengthRatio = 0.6m)
 {
     this.downTrendPattern = downTrendPattern;
     LowerWickLengthRatio  = lowerWickLengthRatio;
 }
Beispiel #9
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0)
            {
                trend.Set(true);
                UpTrend.Set(Input[0]);
                DownTrend.Set(Input[0]);
                return;
            }

            switch (smode)
            {
            case SuperTrendMode.ATR: offset = ATR(length)[0] * Multiplier;                                                 break;

            case SuperTrendMode.Adaptive: offset = ATR(length)[0] * HomodyneDiscriminator(Input)[0] / 10;     break;

            default: offset = Dtt(length, Multiplier);                                                             break;
            }

            if (FirstTickOfBar)
            {
                prevColor = tempColor;
            }

            trend.Set(Close[0] > DownTrend[1] || !(Close[0] < UpTrend[1]) && trend[1]);

            if (trend[0] && !trend[1])
            {
                th = High[0];
                UpTrend.Set(Math.Max(avg[0] - offset, tl));
                if (Plots[0].PlotStyle == PlotStyle.Line)
                {
                    UpTrend.Set(1, DownTrend[1]);
                }
                tempColor = barColorUp;
                if (ShowArrows)
                {
                    DrawArrowUp(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, UpTrend[0] - TickSize, barColorUp);
                }
                if (thisbar != CurrentBar)
                {
                    thisbar = CurrentBar;
                    if (PlayAlert)
                    {
                        PlaySound(LongAlert);
                    }
                    if (SendEmail && !string.IsNullOrEmpty(mailFrom) && !string.IsNullOrEmpty(mailTo))
                    {
                        SendMail(mailFrom, mailTo, "SuperTrend Long Signal", string.Format("{0}: {1} {2} {3} chart", Time[0], Instrument.FullName, Bars.Period.Value, Bars.Period.Id));
                    }
                }
            }
            else if (!trend[0] && trend[1])
            {
                tl = Low[0];
                DownTrend.Set(Math.Min(avg[0] + offset, th));
                if (Plots[1].PlotStyle == PlotStyle.Line)
                {
                    DownTrend.Set(1, UpTrend[1]);
                }
                tempColor = barColorDown;
                if (ShowArrows)
                {
                    DrawArrowDown(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, DownTrend[0] + TickSize, barColorDown);
                }
                if (thisbar != CurrentBar)
                {
                    thisbar = CurrentBar;
                    if (PlayAlert)
                    {
                        PlaySound(ShortAlert);
                    }
                    if (SendEmail && !string.IsNullOrEmpty(mailFrom) && !string.IsNullOrEmpty(mailTo))
                    {
                        SendMail(mailFrom, mailTo, "SuperTrend Short Signal", string.Format("{0}: {1} {2} {3} chart", Time[0], Instrument.FullName, Bars.Period.Value, Bars.Period.Id));
                    }
                }
            }
            else
            {
                if (trend[0])
                {
                    UpTrend.Set((avg[0] - offset) > UpTrend[1] ? (avg[0] - offset) : UpTrend[1]);
                    th = Math.Max(th, High[0]);
                }
                else
                {
                    DownTrend.Set((avg[0] + offset) < DownTrend[1] ? (avg[0] + offset) : DownTrend[1]);
                    tl = Math.Min(tl, Low[0]);
                }
                RemoveDrawObject(CurrentBar.ToString(CultureInfo.InvariantCulture));
                tempColor = prevColor;
            }

            if (!colorBars)
            {
                return;
            }

            CandleOutlineColor = tempColor;
            BarColor           = Open[0] < Close[0] && ChartControl.ChartStyleType == ChartStyleType.CandleStick ? Color.Transparent : tempColor;
        }