DX Candlestick Patterns

by Danis in category Volatility at 12/11/2017
Description

This is a complete candlestick pattern indicator. It is very accurate but in my opinion, is a deprecated tool for trading. I publish this for free because now I use another strategy trading, without candlestick patterns more accurately and efficiently.

For more details about my indicators contact me at dp@ideadevelop.net

DX Patterns

Download
233 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using System;
using System.IO;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.FileSystem)]
    public class DX_Patterns : Indicator
    {
        #region Parameters

        [Parameter("HMA Period", DefaultValue = 10)]
        public int hmaPeriod { get; set; }
        [Parameter("Show names", DefaultValue = false)]
        public bool Name_Status { get; set; }
        [Parameter("Show more info", DefaultValue = true)]
        public bool Add_info { get; set; }
        [Parameter("Show description", DefaultValue = false)]
        public bool Show_description { get; set; }
        [Parameter("Show Doji", DefaultValue = true)]
        public bool Show_Doji { get; set; }
        [Parameter("Show Hammer", DefaultValue = true)]
        public bool Show_Hammer { get; set; }
        [Parameter("Show Bullish Engulfing", DefaultValue = true)]
        public bool Show_Bullish_Engulfing { get; set; }
        [Parameter("Show Bullish Harami", DefaultValue = true)]
        public bool Show_Bullish_Harami { get; set; }
        [Parameter("Show Piercing Pattern", DefaultValue = true)]
        public bool Show_Piercing_Pattern { get; set; }
        [Parameter("Show Morning Star", DefaultValue = true)]
        public bool Show_Morning_Star { get; set; }
        [Parameter("Show Bearish Engulfing", DefaultValue = true)]
        public bool Show_Bearish_Engulfing { get; set; }
        [Parameter("Show Dark Cloud", DefaultValue = true)]
        public bool Show_Dark_Cloud { get; set; }
        [Parameter("Show Shooting Star", DefaultValue = true)]
        public bool Show_Shooting_Star { get; set; }
        [Parameter("Show Bearish Harami", DefaultValue = true)]
        public bool Show_Bearish_Harami { get; set; }
        [Parameter("Show Evening Star", DefaultValue = true)]
        public bool Show_Evening_Star { get; set; }
        [Parameter("Show Hanging Man", DefaultValue = true)]
        public bool Show_Hanging_Man { get; set; }
        [Parameter("Show BBand Pattern", DefaultValue = true)]
        public bool Show_BBand_Pattern { get; set; }

        [Parameter("Doji", DefaultValue = "Dj")]
        public string Doji_s { get; set; }
        [Parameter("Hammer", DefaultValue = "Hm")]
        public string Hammer_s { get; set; }
        [Parameter("Bullish Engulfing", DefaultValue = "BE")]
        public string Bullish_Engulfing_s { get; set; }
        [Parameter("Bullish Harami", DefaultValue = "BH")]
        public string Bullish_Harami_s { get; set; }
        [Parameter("Piercing Pattern", DefaultValue = "PP")]
        public string Piercing_Pattern_s { get; set; }
        [Parameter("Morning Star", DefaultValue = "MS")]
        public string Morning_Star_s { get; set; }
        [Parameter("Bearish Engulfing", DefaultValue = "bE")]
        public string Bearish_Engulfing_s { get; set; }
        [Parameter("Dark Cloud", DefaultValue = "DC")]
        public string Dark_Cloud_s { get; set; }
        [Parameter("Shooting Star", DefaultValue = "SS")]
        public string Shooting_Star_s { get; set; }
        [Parameter("Bearish Harami", DefaultValue = "bH")]
        public string Bearish_Harami_s { get; set; }
        [Parameter("Evening Star", DefaultValue = "ES")]
        public string Evening_Star_s { get; set; }
        [Parameter("Hanging Man", DefaultValue = "HM")]
        public string Hanging_Man_s { get; set; }
        [Parameter("BBand Pattern", DefaultValue = "☨")]
        public string BBand_Pattern_s { get; set; }

        #endregion Parameters

        private IndicatorDataSeries diff;
        private ExponentialMovingAverage ema1;
        private ExponentialMovingAverage ema2;
        private ExponentialMovingAverage ema3;
        private BollingerBands Bbands;

        private const VerticalAlignment vAlign = VerticalAlignment.Top;
        private const HorizontalAlignment hAlign = HorizontalAlignment.Center;
        private const double n = 0.618;
        private string Pattern_name;

        double var1 = 0;
        double var2 = 0;

        private double offset;
        private struct Candle
        {
            #region Data

            public double High;
            public double Close;
            public double Open;
            public double Low;
            public double High1;
            public double Close1;
            public double Open1;
            public double Low1;
            public double High2;
            public double Close2;
            public double Open2;
            public double Low2;

            #endregion Data

            #region Functions

            public bool IsFallCandle()
            {
                if (Close < Open)
                    return true;
                else
                    return false;
            }
            public bool IsFallCandle1()
            {
                if (Close1 < Open1)
                    return true;
                else
                    return false;
            }
            public bool IsFallCandle2()
            {
                if (Close2 < Open2)
                    return true;
                else
                    return false;
            }

            public bool IsRiseCandle()
            {
                if (Open < Close)
                    return true;
                else
                    return false;
            }
            public bool IsRiseCandle1()
            {
                if (Open1 < Close1)
                    return true;
                else
                    return false;
            }
            public bool IsRiseCandle2()
            {
                if (Open2 < Close2)
                    return true;
                else
                    return false;
            }

            public bool SizeCandle()
            {
                if (Open > Close)
                {
                    if ((Open - Close) > (High - Low) * n)
                        return true;
                }
                else if (Open < Close)
                {
                    if ((Close - Open) > (High - Low) * n)
                        return true;
                }

                return false;
            }
            public bool SizeCandle1()
            {
                if (Open1 > Close1)
                {
                    if ((Open1 - Close1) > (High1 - Low1) * n)
                        return true;
                }
                else if (Open1 < Close1)
                {
                    if ((Close1 - Open1) > (High1 - Low1) * n)
                        return true;
                }

                return false;
            }
            public bool SizeCandle2()
            {
                if (Open2 > Close2)
                {
                    if ((Open2 - Close2) > (High2 - Low2) * n)
                        return true;
                }
                else if (Open2 < Close2)
                {
                    if ((Close2 - Open2) > (High2 - Low2) * n)
                        return true;
                }

                return false;
            }
            public bool SmallCandle()
            {
                if (Open > Close)
                {
                    if ((Open - Close) < (High - Low) * n / 2)
                        return true;
                }
                else if (Open < Close)
                {
                    if ((Close - Open) < (High - Low) * n / 2)
                        return true;
                }

                return false;
            }
            public bool SmallCandle1()
            {
                if (Open1 > Close1)
                {
                    if ((Open1 - Close1) < (High1 - Low1) * n / 2)
                        return true;
                }
                else if (Open1 < Close1)
                {
                    if ((Close1 - Open1) < (High1 - Low1) * n / 2)
                        return true;
                }

                return false;
            }
            public bool SmallCandle2()
            {
                if (Open2 > Close2)
                {
                    if ((Open2 - Close2) < (High2 - Low2) * n / 2)
                        return true;
                }
                else if (Open2 < Close2)
                {
                    if ((Close2 - Open2) < (High2 - Low2) * n / 2)
                        return true;
                }

                return false;
            }

            #endregion Functions
        }

        private enum PatternType : int
        {
            Doji = 1,
            Hammer = 2,
            Bullish_Engulfing = 3,
            Bullish_Harami = 4,
            Piercing_Pattern = 5,
            Morning_Star = 6,
            Bearish_Engulfing = 7,
            Dark_Cloud = 8,
            Shooting_Star = 9,
            Bearish_Harami = 10,
            Evening_Star = 11,
            Hanging_Man = 12,
            BBand_Pattern = 13
        }

        protected override void Initialize()
        {
            offset = Symbol.PipSize * 5;

            diff = CreateDataSeries();
            ema1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)(hmaPeriod / 2));
            ema2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, hmaPeriod);
            ema3 = Indicators.ExponentialMovingAverage(diff, (int)Math.Sqrt(hmaPeriod));
            Bbands = Indicators.BollingerBands(MarketSeries.Close, 21, 2.1, MovingAverageType.Weighted);

        }

        private void DrawText(int index, int _Type)
        {
            var high = MarketSeries.High[index];
            var low = MarketSeries.Low[index];

            int x = index;

            double h_y = high + offset;
            double h_d_y = h_y + offset * 2.5;
            double h_t_y = h_d_y + offset;

            double l_y = low - offset * 2.5;
            double l_d_y = l_y - offset;

            if (TimeFrame == TimeFrame.Minute)
            {
                h_y = high + offset / 2;
                h_d_y = h_y + offset / 2;
                h_t_y = h_d_y + offset;

                l_y = low - offset / 2;
                l_d_y = l_y - offset / 2;
            }

            if (TimeFrame == TimeFrame.Minute15)
            {
                h_y = high + offset / 1.5;
                h_d_y = h_y + offset;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 1.5;
                l_d_y = l_y - offset * 1.1;
            }

            if (TimeFrame == TimeFrame.Hour)
            {
                h_y = high + offset;
                h_d_y = h_y + offset * 3;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 3;
                l_d_y = l_y - offset * 3;
            }

            if (TimeFrame == TimeFrame.Hour4)
            {
                h_y = high + offset;
                h_d_y = h_y + offset * 5;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 5;
                l_d_y = l_y - offset * 5;
            }
            if (TimeFrame == TimeFrame.Hour8)
            {
                h_y = high + offset * 2;
                h_d_y = h_y + offset * 6;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 6;
                l_d_y = l_y - offset * 6;
            }


            if (TimeFrame == TimeFrame.Daily)
            {
                h_y = high + offset * 3;
                h_d_y = h_y + offset * 12;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 12;
                l_d_y = l_y - offset * 12;
            }

            if (TimeFrame == TimeFrame.Weekly)
            {
                h_y = high + offset * 6;
                h_d_y = h_y + offset * 24;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 24;
                l_d_y = l_y - offset * 24;
            }

            if (TimeFrame == TimeFrame.Monthly)
            {
                h_y = high + offset * 24;
                h_d_y = h_y + offset * 64;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 64;
                l_d_y = l_y - offset * 64;
            }

            string f_ObjName;
            string s_ObjName;

            switch (_Type)
            {
                case (int)PatternType.Doji:

                    f_ObjName = string.Format("Doji {0}", index);
                    s_ObjName = string.Format("Doji | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Doji", x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Hammer:

                    f_ObjName = string.Format("Hammer {0}", index);
                    s_ObjName = string.Format("Hammer | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Hammer", x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bullish_Engulfing:
                    f_ObjName = string.Format("Bullish Engulfing {0}", index);
                    s_ObjName = string.Format("Bullish Engulfing | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Bullish Engulfing", x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bullish_Harami:
                    f_ObjName = string.Format("Bullish Harami {0}", index);
                    s_ObjName = string.Format("Bullish Engulfing | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Bullish Harami", x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Piercing_Pattern:
                    f_ObjName = string.Format("Piercing Pattern {0}", index);
                    s_ObjName = string.Format("Piercing Pattern | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Piercing Pattern", x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Morning_Star:
                    f_ObjName = string.Format("Morning Star {0}", index);
                    s_ObjName = string.Format("Morning Star | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Morning Star", x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bearish_Engulfing:
                    f_ObjName = string.Format("Bearish Engulfing {0}", index);
                    s_ObjName = string.Format("Bearish Engulfing | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Bearish Engulfing", x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Dark_Cloud:
                    f_ObjName = string.Format("Dark Cloud {0}", index);
                    s_ObjName = string.Format("Dark Cloud | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Dark Cloud", x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Shooting_Star:
                    f_ObjName = string.Format("Shooting Star {0}", index);
                    s_ObjName = string.Format("Shooting Star | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Shooting Star", x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bearish_Harami:
                    f_ObjName = string.Format("Bearish Harami {0}", index);
                    s_ObjName = string.Format("Bearish Harami | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Bearish Harami", x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Evening_Star:
                    f_ObjName = string.Format("Evening Star {0}", index);
                    s_ObjName = string.Format("Evening Star | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Evening Star", x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Hanging_Man:
                    f_ObjName = string.Format("Hanging Man {0}", index);
                    s_ObjName = string.Format("Hanging Man | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "Hanging Man", x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.BBand_Pattern:
                    f_ObjName = string.Format("BBand Pattern {0}", index);
                    s_ObjName = string.Format("BBand Pattern | {0}", index);

                    ChartObjects.DrawText(f_ObjName, "BBand Pattern", x, l_d_y, vAlign, hAlign, Colors.DarkGray);
                    ChartObjects.DrawText(s_ObjName, "\n|", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

            }
        }

        private void DrawSymbols(int index, int _Type)
        {
            var high = MarketSeries.High[index];
            var low = MarketSeries.Low[index];

            int x = index;

            double h_y = high + offset;
            double h_d_y = h_y + offset * 2.5;
            double h_t_y = h_d_y + offset;

            double l_y = low - offset * 2.5;
            double l_d_y = l_y - offset;


            if (TimeFrame == TimeFrame.Minute)
            {
                h_y = high + offset / 2;
                h_d_y = h_y + offset / 2;
                h_t_y = h_d_y + offset;

                l_y = low - offset / 2;
                l_d_y = l_y - offset / 2;
            }

            if (TimeFrame == TimeFrame.Minute15)
            {
                h_y = high + offset / 1.5;
                h_d_y = h_y + offset;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 1.5;
                l_d_y = l_y - offset * 1.1;
            }


            if (TimeFrame == TimeFrame.Hour)
            {
                h_y = high + offset;
                h_d_y = h_y + offset * 3;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 3;
                l_d_y = l_y - offset * 3;
            }

            if (TimeFrame == TimeFrame.Hour4)
            {
                h_y = high + offset;
                h_d_y = h_y + offset * 5;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 5;
                l_d_y = l_y - offset * 5;
            }

            if (TimeFrame == TimeFrame.Hour8)
            {
                h_y = high + offset * 4;
                h_d_y = h_y + offset * 9;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 9;
                l_d_y = l_y - offset * 9;
            }
            if (TimeFrame == TimeFrame.Daily)
            {
                h_y = high + offset * 3;
                h_d_y = h_y + offset * 12;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 12;
                l_d_y = l_y - offset * 12;
            }

            if (TimeFrame == TimeFrame.Weekly)
            {
                h_y = high + offset * 6;
                h_d_y = h_y + offset * 24;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 24;
                l_d_y = l_y - offset * 24;
            }

            if (TimeFrame == TimeFrame.Monthly)
            {
                h_y = high + offset * 24;
                h_d_y = h_y + offset * 64;
                h_t_y = h_d_y + offset;

                l_y = low - offset * 64;
                l_d_y = l_y - offset * 64;
            }

            string f_ObjName;
            string s_ObjName;

            switch (_Type)
            {
                case (int)PatternType.Doji:

                    f_ObjName = string.Format("Doji {0}", index);
                    s_ObjName = string.Format("Doji | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Doji_s, x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Hammer:

                    f_ObjName = string.Format("Hammer {0}", index);
                    s_ObjName = string.Format("Hammer | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Hammer_s, x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bullish_Engulfing:
                    f_ObjName = string.Format("Bullish Engulfing {0}", index);
                    s_ObjName = string.Format("Bullish Engulfing | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Bullish_Engulfing_s, x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bullish_Harami:
                    f_ObjName = string.Format("Bullish Harami {0}", index);
                    s_ObjName = string.Format("Bullish Harami | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Bullish_Harami_s, x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Piercing_Pattern:
                    f_ObjName = string.Format("Piercing Pattern {0}", index);
                    s_ObjName = string.Format("Piercing Pattern | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Piercing_Pattern_s, x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Morning_Star:
                    f_ObjName = string.Format("Morning Star {0}", index);
                    s_ObjName = string.Format("Morning Star | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Morning_Star_s, x, h_d_y, vAlign, hAlign, Colors.RoyalBlue);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, h_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bearish_Engulfing:
                    f_ObjName = string.Format("Bearish Engulfing {0}", index);
                    s_ObjName = string.Format("Bearish Engulfing | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Bearish_Engulfing_s, x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Dark_Cloud:
                    f_ObjName = string.Format("Dark Cloud {0}", index);
                    s_ObjName = string.Format("Dark Cloud | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Dark_Cloud_s, x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Shooting_Star:
                    f_ObjName = string.Format("Shooting Star {0}", index);
                    s_ObjName = string.Format("Shooting Star | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Shooting_Star_s, x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Bearish_Harami:
                    f_ObjName = string.Format("Bearish Harami {0}", index);
                    s_ObjName = string.Format("Bearish Harami | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Bearish_Harami_s, x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Evening_Star:
                    f_ObjName = string.Format("Evening Star {0}", index);
                    s_ObjName = string.Format("Evening Star | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Evening_Star_s, x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;

                case (int)PatternType.Hanging_Man:
                    f_ObjName = string.Format("Hanging Man {0}", index);
                    s_ObjName = string.Format("Hanging Man | {0}", index);

                    ChartObjects.DrawText(f_ObjName, Hanging_Man_s, x, l_d_y, vAlign, hAlign, Colors.Red);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;
                case (int)PatternType.BBand_Pattern:
                    f_ObjName = string.Format("BBand Pattern {0}", index);
                    s_ObjName = string.Format("BBand Pattern | {0}", index);

                    ChartObjects.DrawText(f_ObjName, BBand_Pattern_s, x, l_d_y, vAlign, hAlign, Colors.DarkGray);
                    ChartObjects.DrawText(s_ObjName, "\n.", x, l_y, vAlign, hAlign, Colors.DarkGray);

                    break;


            }
        }

        private void Text_Info(int index, string Pattern_name)
        {
            if (Add_info == true)
            {

                #region Pattern

                ChartObjects.DrawText("PATTERN", "\t\t\t\t\t\tLast Pattern: " + Pattern_name, StaticPosition.TopLeft, Colors.DarkGray);

                #endregion Pattern

            }
            if (Show_description == true)
            {
                #region Description
                ChartObjects.DrawText("Doji", "Doji - Dj", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Hammer", "\nHammer - Hm", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Bullish Engulfing", "\n\nBullish Engulfing - BE", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Bullish Harami", "\n\n\nBullish Harami - BH", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Piercing Pattern", "\n\n\n\nPiercing Pattern - PP", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Morning Star", "\n\n\n\n\nMorning Star - MS", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Bearish Engulfing", "\n\n\n\n\n\nBearish Engulfing - bE", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Dark Cloud", "\n\n\n\n\n\n\nDark Cloud - DC", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Shooting Star", "\n\n\n\n\n\n\n\nShooting Star - SS", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Bearish Harami", "\n\n\n\n\n\n\n\n\nBearish Harami - bH", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Evening Star", "\n\n\n\n\n\n\n\n\n\nEvening Star - ES", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("Hanging Man", "\n\n\n\n\n\n\n\n\n\n\nHanging Man - HM", StaticPosition.TopRight, Colors.DarkGray);
                ChartObjects.DrawText("BBand Pattern", "\n\n\n\n\n\n\n\n\n\n\n\nHanging Man - BP", StaticPosition.TopRight, Colors.DarkGray);
                #endregion Description
            }
        }

        private bool Doji(Candle candle)
        {

            if (candle.IsFallCandle() & (candle.Close != candle.Low))
            {
                if ((candle.High - candle.Low) > 12 * (candle.Open - candle.Close))
                    return true;
            }
            if (candle.IsRiseCandle() & (candle.Close != candle.High))
            {
                if ((candle.High - candle.Low) > 12 * (candle.Close - candle.Open))
                    return true;
            }
            return false;
        }

        private bool Hammer(Candle candle)
        {
            if (ema3.Result.Last(1) < ema3.Result.Last(2) & candle.Close != candle.Open)
            {

                if (candle.IsFallCandle())
                {
                    if ((candle.High - candle.Low) > 3 * (candle.Close - candle.Open) & (candle.Close - candle.Low) / (0.001 + candle.High - candle.Low) > n & (candle.Open - candle.Low) / (0.001 + candle.High - candle.Low) > n)
                    {
                        return true;
                    }
                    if ((candle.High - candle.Low) > 3 * (candle.Open - candle.Close) & (candle.High - candle.Close) / (0.001 + candle.High - candle.Low) > n & (candle.High - candle.Open) / (0.001 + candle.High - candle.Low) > n)
                    {
                        return true;
                    }

                    return false;
                }
                if (candle.IsRiseCandle())
                {

                    if ((candle.High - candle.Low) > 3 * (candle.Open - candle.Close) & (candle.Close - candle.Low) / (0.001 + candle.High - candle.Low) > n & (candle.Open - candle.Low) / (0.001 + candle.High - candle.Low) > n)
                    {
                        return true;
                    }

                    if ((candle.High - candle.Low) > 3 * (candle.Close - candle.Open) & (candle.High - candle.Close) / (0.001 + candle.High - candle.Low) > n & (candle.High - candle.Open) / (0.001 + candle.High - candle.Low) > n)
                    {
                        return true;
                    }

                    return false;
                }
            }
            return false;
        }
        private bool Bullish_Engulfing(Candle candle)
        {
            if (ema3.Result.Last(1) < ema3.Result.Last(2) & candle.IsFallCandle1() & candle.IsRiseCandle() & candle.SizeCandle() & (candle.Close > candle.Open1 & candle.Close1 > candle.Open))
            {
                return true;
            }
            return false;
        }

        private bool Bullish_Harami(Candle candle)
        {
            if (ema3.Result.Last(1) < ema3.Result.Last(2) & candle.IsFallCandle1() & candle.SizeCandle1() & candle.SmallCandle() & candle.IsRiseCandle() & candle.Close < candle.Open1 & candle.Close1 < candle.Open)
            {
                return true;
            }

            return false;
        }

        private bool Piercing_Pattern(Candle candle)
        {
            if (ema3.Result.Last(1) < ema3.Result.Last(2) & candle.IsFallCandle1() & candle.IsRiseCandle() & (((candle.Open1 + candle.Close1) / 2) < candle.Close) & candle.Open < candle.Close1 & candle.Close < candle.Open1 & ((candle.Close - candle.Open) / (0.001 + (candle.High - candle.Low))) > n)
            {
                return true;
            }

            return false;
        }

        private bool Morning_Star(Candle candle)
        {
            if (ema3.Result.Last(2) > ema3.Result.Last(1) & candle.IsFallCandle2() & candle.SmallCandle1() & candle.IsRiseCandle() & ((candle.Open2 - candle.Close2) / (0.001 + candle.High2 - candle.Low2) > n) & candle.Close2 > candle.Open1 & candle.Open1 > candle.Close1 & ((candle.High1 - candle.Low1) > (3 * (candle.Open1 - candle.Close1))) & candle.Open > candle.Close1)
            {
                return true;
            }
            return false;
        }

        private bool Bearish_Engulfing(Candle candle)
        {
            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsRiseCandle1() & candle.IsFallCandle() & candle.SizeCandle() & candle.Close < candle.Open1 & candle.Close1 < candle.Open)
            {
                return true;
            }
            return false;
        }

        private bool Dark_Cloud(Candle candle)
        {
            //
            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsRiseCandle1() & candle.IsFallCandle() & ((candle.Close1 + candle.Open1) / 2 > candle.Close) & candle.Open > candle.Close1 & candle.Close > candle.Open1 & (candle.Open - candle.Close) / (0.001 + (candle.High - candle.Low)) > n)
            {
                return true;
            }
            return false;
        }

        private bool Shooting_Star(Candle candle)
        {
            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsFallCandle() & (candle.High - candle.Low) > 4 * (candle.Open - candle.Close) & (candle.High - candle.Close) / (0.001 + candle.High - candle.Low) >= 0.75 & (candle.High - candle.Open) / (0.001 + candle.High - candle.Low) >= 0.75 & candle.High > candle.High1)
            {
                return true;
            }
            return false;
        }
        private bool Bearish_Harami(Candle candle)
        {

            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsFallCandle() & candle.SmallCandle() & candle.IsRiseCandle1() & candle.SizeCandle1() & candle.Open < candle.Close1 & candle.Open1 < candle.Close)
            {
                return true;
            }
            return false;
        }

        private bool Evening_Star(Candle candle)
        {
            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsRiseCandle2() & candle.SmallCandle1() & candle.IsFallCandle())
            {
                if (((candle.Close2 - candle.Open2) / (0.001 + candle.High2 - candle.Low2) > n) & candle.Close2 < candle.Open1 & candle.Close1 > candle.Open1 & ((candle.High1 - candle.Low1) > (3 * (candle.Close1 - candle.Open1))) & candle.Open < candle.Close1)
                {
                    return true;
                }

                if (((candle.Close2 - candle.Open2) / (0.001 + candle.High2 - candle.Low2) > n) & candle.Close2 < candle.Open1 & candle.Close1 < candle.Open1 & ((candle.High1 - candle.Low1) > (3 * (candle.Open1 - candle.Close1))) & candle.Open < candle.Close1)
                {
                    return true;
                }
            }
            return false;
        }

        private bool Hanging_Man(Candle candle)
        {
            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsRiseCandle() & (candle.High - candle.Low) > 4 * (candle.Close - candle.Open) & (candle.Close - candle.Low) / (0.001 + candle.High - candle.Low) >= 0.75 & (candle.Open - candle.Low) / (0.001 + candle.High - candle.Low) >= 0.75 & candle.Open > candle.Close1)
            {
                return true;
            }
            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsFallCandle() & (candle.High - candle.Low) > 4 * (candle.Open - candle.Close) & (candle.Close - candle.Low) / (0.001 + candle.High - candle.Low) >= 0.75 & (candle.Open - candle.Low) / (0.001 + candle.High - candle.Low) >= 0.75 & candle.Open > candle.Close1)
            {
                return true;
            }
            return false;
        }

        private bool BBand_Pattern(Candle candle)
        {
            if (ema3.Result.Last(1) > ema3.Result.Last(2) & candle.IsRiseCandle1() & candle.Close1 > Bbands.Top.Last(1) & candle.IsFallCandle() & candle.Open > Bbands.Top.LastValue & candle.Close < Bbands.Top.LastValue)
            {
                return true;
            }
            if (ema3.Result.Last(1) < ema3.Result.Last(2) & candle.IsFallCandle1() & candle.Close1 < Bbands.Bottom.Last(1) & candle.IsRiseCandle() & candle.Open < Bbands.Bottom.LastValue & candle.Close > Bbands.Bottom.LastValue)
            {
                return true;
            }
            return false;
        }

        public override void Calculate(int index)
        {
            var1 = 2 * ema1.Result[index];
            var2 = ema2.Result[index];
            diff[index] = var1 - var2;
            #region structs

            Candle candle = new Candle();

            #endregion structs

            #region variables

            int candle_index = 0;

            candle.High = MarketSeries.High.Last(candle_index);
            candle.Open = MarketSeries.Open.Last(candle_index);
            candle.Close = MarketSeries.Close.Last(candle_index);
            candle.Low = MarketSeries.Low.Last(candle_index);
            candle.High1 = MarketSeries.High.Last(candle_index + 1);
            candle.Open1 = MarketSeries.Open.Last(candle_index + 1);
            candle.Close1 = MarketSeries.Close.Last(candle_index + 1);
            candle.Low1 = MarketSeries.Low.Last(candle_index + 1);
            candle.High2 = MarketSeries.High.Last(candle_index + 2);
            candle.Open2 = MarketSeries.Open.Last(candle_index + 2);
            candle.Close2 = MarketSeries.Close.Last(candle_index + 2);
            candle.Low2 = MarketSeries.Low.Last(candle_index + 2);

            #endregion variables

            #region Patterns

// Doji

            if (Doji(candle))
            {
                if (Show_Doji == true)
                {
                    Pattern_name = "Doji";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Doji);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Doji);
                    }
                }
            }

//Hammer

            if (Hammer(candle))
            {
                if (Show_Hammer == true)
                {
                    Pattern_name = "Hammer";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Hammer);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Hammer);
                    }
                }
            }

//Bullish Engulfing

            if (Bullish_Engulfing(candle))
            {
                if (Show_Bullish_Engulfing == true)
                {
                    Pattern_name = "Bullish Engulfing";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Bullish_Engulfing);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Bullish_Engulfing);
                    }
                }
            }

//Bullish Harami
            if (Bullish_Harami(candle))
            {
                if (Show_Bullish_Harami == true)
                {
                    Pattern_name = "Bullish Harami";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Bullish_Harami);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Bullish_Harami);
                    }
                }
            }

//Piercing_Pattern
            if (Piercing_Pattern(candle))
            {
                if (Show_Piercing_Pattern == true)
                {
                    Pattern_name = "Piercing Pattern";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Piercing_Pattern);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Piercing_Pattern);
                    }
                }
            }

//Morning_Star
            if (Morning_Star(candle))
            {
                if (Show_Morning_Star == true)
                {
                    Pattern_name = "Morning Star";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Morning_Star);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Morning_Star);
                    }
                }
            }

//Bearish_Engulfing
            if (Bearish_Engulfing(candle))
            {
                if (Show_Bearish_Engulfing == true)
                {
                    Pattern_name = "Bearish Engulfing";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Bearish_Engulfing);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Bearish_Engulfing);
                    }
                }
            }

//Dark_Cloud
            if (Dark_Cloud(candle))
            {
                if (Show_Dark_Cloud == true)
                {
                    Pattern_name = "Dark Cloud";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Dark_Cloud);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Dark_Cloud);
                    }
                }
            }

//Shooting_Star
            if (Shooting_Star(candle))
            {
                if (Show_Shooting_Star == true)
                {
                    Pattern_name = "Shooting Star";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Shooting_Star);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Shooting_Star);
                    }
                }
            }

//Bearish_Harami
            if (Bearish_Harami(candle))
            {
                if (Show_Bearish_Harami == true)
                {
                    Pattern_name = "Bearish Harami";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Bearish_Harami);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Bearish_Harami);
                    }
                }
            }

//Evening_Star
            if (Evening_Star(candle))
            {
                if (Show_Evening_Star == true)
                {
                    Pattern_name = "Evening Star";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Evening_Star);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Evening_Star);
                    }
                }
            }

//Hanging Man
            if (Hanging_Man(candle))
            {
                if (Show_Hanging_Man == true)
                {
                    Pattern_name = "Hanging Man";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.Hanging_Man);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.Hanging_Man);
                    }
                }
            }

//Bollinger Band Pattern
            if (BBand_Pattern(candle))
            {
                if (Show_BBand_Pattern == true)
                {
                    Pattern_name = "BBand Pattern";
                    if (Name_Status == true)
                    {
                        DrawText(index, (int)PatternType.BBand_Pattern);
                    }
                    else
                    {
                        DrawSymbols(index, (int)PatternType.BBand_Pattern);
                    }
                }
            }



            #endregion Patterns

            #region Text

            Text_Info(index, Pattern_name);

            #endregion Text
        }
    }
}
Comments
5