Beispiel #1
0
 private void InitColorSeries()
 {
     for (int i = 0; i <= CurrentBar + Displacement + (CalculateOnBarClose ? 1 : 0); i++)
     {
         BarColorSeries.Set(i, Color.Transparent);
         CandleOutlineColorSeries.Set(i, Color.Transparent);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < Period)
            {
                return;
            }
            if (Displacement + (CalculateOnBarClose ? 1 : 0) > 0 && CurrentBar > 0 && BarColorSeries[1] != Color.Transparent)
            {
                InitColorSeries();
            }
            BarColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            CandleOutlineColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            PlotEMA_H.Set(CurrentBar == 0 ? High[0] : High[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * PlotEMA_H[1]);
            PlotEMT_C.Set(CurrentBar == 0 ? Close[0] : Close[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * PlotEMT_C[1]);
            PlotEMA_L.Set(CurrentBar == 0 ? Low[0] : Low[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * PlotEMA_L[1]);

            if (CurrentBar == 0)
            {
                HAOpen.Set(Open[0]);
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAClose.Set(Close[0]);
                return;
            }
            if (Close[0] > PlotEMA_H[0])
            {
                HAOpen.Set(Open[0]);
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAClose.Set(Close[0]);
            }
            //else if (Close[0] < PlotEMA_L[0])
            //{
            //    brushUp = brushRed;
            //    brushDown = brushMaroon;
            //    HAOpen.Set(Open[0]);
            //    HAHigh.Set(High[0]);
            //    HALow.Set(Low[0]);
            //    HAClose.Set(Close[0]);
            //}
            //else
            //{
            //    brushUp = brushLightSteelBlue;
            //    brushDown = brushSteelBlue;
            //    HAOpen.Set(Open[0]);
            //    HAHigh.Set(High[0]);
            //    HALow.Set(Low[0]);
            //    HAClose.Set(Close[0]);
            //}
        }
Beispiel #3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (Displacement + (CalculateOnBarClose ? 1 : 0) > 0 && CurrentBar > 0 && BarColorSeries[1] != Color.Transparent)
            {
                InitColorSeries();
            }

            BarColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            CandleOutlineColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);

            if (CurrentBar == 0)
            {
                HAOpen.Set(Open[0]);
                HAHigh.Set(High[0]);
                HALow.Set(Low[0]);
                HAClose.Set(Close[0]);
                return;
            }

            HAClose.Set((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close
            HAOpen.Set((HAOpen[1] + HAClose[1]) * 0.5);                  // Calculate the open
            HAHigh.Set(Math.Max(High[0], HAOpen[0]));                    // Calculate the high
            HALow.Set(Math.Min(Low[0], HAOpen[0]));                      // Calculate the low
        }
Beispiel #4
0
        protected override void OnBarUpdate()
        {
            if (ChartControl == null || Bars == null)
            {
                return;
            }

            if (Displacement + (CalculateOnBarClose ? 1 : 0) > 0 && CurrentBar > 0 && BarColorSeries[1] != Color.Transparent)
            {
                InitColorSeries();
            }

            BarColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            CandleOutlineColorSeries.Set(Math.Max(0, CurrentBar + Math.Max(0, Displacement) + (CalculateOnBarClose ? 1 : 0)), Color.Transparent);
            Condition4.Reset();
            Condition5.Reset();
            Condition2.Reset();
            Condition67.Reset();
            if (CurrentBar == 0)
            {
                hao.Set(Open[0]);
                hah.Set(High[0]);
                hal.Set(Low[0]);
                hac.Set(Close[0]);
                return;
            }

            hac.Set((Open[0] + High[0] + Low[0] + Close[0]) * 0.25); // Calculate the close
            hao.Set((hao[1] + hac[1]) * 0.5);                        // Calculate the open
            hah.Set(Math.Max(High[0], hao[0]));                      // Calculate the high
            hal.Set(Math.Min(Low[0], hao[0]));                       // Calculate the low
            if (CurrentBar < 3)
            {
                return;
            }
            bool condition1 = (ZLEMA(7)[0] < hao[0] || ZLEMA(7)[0] < Median[0]) && ZLEMA(7)[0] < ZLEMA(21)[1] && hac[0] < ZLEMA(21)[2] &&
                              (MACD(12, 26, 9).Diff[0] < 0 || (hac[0] < ZLEMA(21)[2] && hao[0] < ZLEMA(21)[2]) || Close[0] < SMA(21)[0] || ZLEMA(7)[0] < ZLEMA(21)[2]);

            bool condition2 = (ZLEMA(7)[0] > hao[0] || ZLEMA(7)[0] > Median[0]) && ZLEMA(7)[0] > ZLEMA(21)[1] && hac[0] > ZLEMA(21)[2] &&
                              (MACD(12, 26, 9).Diff[0] > 0 || (hac[0] > ZLEMA(21)[2] && hao[0] > ZLEMA(21)[2]) || Close[0] > SMA(21)[0] || ZLEMA(7)[0] > ZLEMA(21)[2]);

            bool condition3 = (Low[0] + ((High[0] - Low[0]) * 0.1)) < SMA(21)[0] && (High[0] - ((High[0] - Low[0]) * 0.1)) < SMA(21)[0] && ZLEMA(7)[0] < ZLEMA(7)[1] && ZLEMA(11)[0] < hao[0];

            bool condition4 = condition1 && condition3;

            bool condition5 = condition1 || condition3;

            bool condition6 = ZLEMA(7)[0] < ZLEMA(7)[1] && ZLEMA(11)[0] < ZLEMA(11)[1] && ZLEMA(11)[0] < SMA(21)[0] && hac[0] < hao[0] && Close[0] < Median[0];

            bool condition7 = hac[0] < SMA(21)[0] && ZLEMA(7)[0] < ZLEMA(7)[1] && High[0] < SMA(78)[0] && SMA(21)[0] < SMA(78)[0] && SMA(78)[0] < SMA(78)[3];

            c4.Set(condition4);
            c5.Set(condition5);
            c2.Set(condition2);
            c67.Set(condition6 || condition7);

            if (condition6 || condition7)
            {
                if (st67 == SignalType.PLOT)
                {
                    Condition67.Set(hah[0] + 3 * TickSize);
                }
                else if (st67 == SignalType.BACKGROUNDCOLOR)
                {
                    BackColor = Plots[3].Pen.Color;
                }
            }
            if (condition2)
            {
                if (st2 == SignalType.PLOT)
                {
                    Condition2.Set(hal[0] - TickSize);
                }
                else if (st2 == SignalType.BACKGROUNDCOLOR)
                {
                    BackColor = Plots[2].Pen.Color;
                }
            }
            if (condition5)
            {
                if (st5 == SignalType.PLOT)
                {
                    Condition5.Set(hah[0] + 2 * TickSize);
                }
                else if (st5 == SignalType.BACKGROUNDCOLOR)
                {
                    BackColor = Plots[1].Pen.Color;
                }
            }
            if (condition4)
            {
                if (st4 == SignalType.PLOT)
                {
                    Condition4.Set(hah[0] + TickSize);
                }
                else if (st4 == SignalType.BACKGROUNDCOLOR)
                {
                    BackColor = Plots[0].Pen.Color;
                }
            }

            if (FirstTickOfBar && c4[1] && !c4[2] && playAlert)
            {
                PlaySound("Aler4.wav");
            }
        }
Beispiel #5
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar == 0 && ChartControl != null)
            {
                downColor = ChartControl.GetAxisBrush(ChartControl.BackColor).Color;
                txtColor  = downColor;
                if (downColor == Color.Black)
                {
                    upColor = Color.Transparent;
                }
                else
                {
                    upColor = Color.Black;
                }
            }

            // Calculates trend lines and prevailing trend for patterns that require a trend
            if (TrendStrength > 0 && CurrentBar >= TrendStrength)
            {
                CalculateTrendLines();
            }

            Value.Set(0);

            switch (pattern)
            {
            case ChartPattern.BearishBeltHold:
            {
                #region Bearish Belt Hold
                if (CurrentBar < 1 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if (Close[1] > Open[1] && Open[0] > Close[1] + 5 * TickSize && Open[0] == High[0] && Close[0] < Open[0])
                {
                    if (ChartControl != null)
                    {
                        BarColorSeries.Set(CurrentBar - 1, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        BarColor = downColor;
                    }

                    DrawText("Bearish Belt Hold" + CurrentBar, false, "Bearish Belt Hold", 0, High[0], 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.BearishEngulfing:
            {
                #region Bearish Engulfing
                if (CurrentBar < 1 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if (Close[1] > Open[1] && Close[0] < Open[0] && Open[0] > Close[1] && Close[0] < Open[1])
                {
                    BarColor = downColor;
                    DrawText("Bearish Engulfing" + CurrentBar, false, "Bearish Engulfing", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.BearishHarami:
            {
                #region Bearish Harami
                if (CurrentBar < 1 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if (Close[0] < Open[0] && Close[1] > Open[1] && Low[0] >= Open[1] && High[0] <= Close[1])
                {
                    BarColor = downColor;
                    DrawText("Bearish Harami" + CurrentBar, false, "Bearish Harami", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.BearishHaramiCross:
            {
                #region Bearish Harami Cross
                if (CurrentBar < 1 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if ((High[0] <= Close[1]) && (Low[0] >= Open[1]) && Open[0] <= Close[1] && Close[0] >= Open[1] && ((Close[0] >= Open[0] && Close[0] <= Open[0] + TickSize) || (Close[0] <= Open[0] && Close[0] >= Open[0] - TickSize)))
                {
                    BarColor = downColor;
                    DrawText("Bearish Harami Cross" + CurrentBar, false, "Bearish Harami Cross", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);
                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.BullishBeltHold:
            {
                #region Bullish Belt Hold
                if (CurrentBar < 1 || (TrendStrength > 0 && !downTrend))
                {
                    return;
                }

                if (Close[1] < Open[1] && Open[0] < Close[1] - 5 * TickSize && Open[0] == Low[0] && Close[0] > Open[0])
                {
                    if (ChartControl != null)
                    {
                        BarColorSeries.Set(CurrentBar - 1, downColor);
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                    }

                    DrawText("Bullish Belt Hold" + CurrentBar, false, "Bullish Belt Hold", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.BullishEngulfing:
            {
                #region Bullish Engulfing
                if (CurrentBar < 1 || (TrendStrength > 0 && !downTrend))
                {
                    return;
                }

                if (Close[1] < Open[1] && Close[0] > Open[0] && Close[0] > Open[1] && Open[0] < Close[1])
                {
                    if (ChartControl != null)
                    {
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                    }

                    DrawText("Bullish Engulfing" + CurrentBar, false, "Bullish Engulfing", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.BullishHarami:
            {
                #region Bullish Harami
                if (CurrentBar < 1 || (TrendStrength > 0 && !downTrend))
                {
                    return;
                }

                if (Close[0] > Open[0] && Close[1] < Open[1] && Low[0] >= Close[1] && High[0] <= Open[1])
                {
                    if (ChartControl != null)
                    {
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                    }

                    DrawText("Bullish Harami" + CurrentBar, false, "Bullish Harami", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.BullishHaramiCross:
            {
                #region Bullish Harami Cross
                if (CurrentBar < 1 || (TrendStrength > 0 && !downTrend))
                {
                    return;
                }

                if ((High[0] <= Open[1]) && (Low[0] >= Close[1]) && Open[0] >= Close[1] && Close[0] <= Open[1] && ((Close[0] >= Open[0] && Close[0] <= Open[0] + TickSize) || (Close[0] <= Open[0] && Close[0] >= Open[0] - TickSize)))
                {
                    if (ChartControl != null)
                    {
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                    }

                    DrawText("Bullish Harami Cross" + CurrentBar, false, "Bullish Harami Cross", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.DarkCloudCover:
            {
                #region Dark Cloud Cover
                if (CurrentBar < 1 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if (Open[0] > High[1] && Close[1] > Open[1] && Close[0] < Open[0] && Close[0] <= Close[1] - (Close[1] - Open[1]) / 2 && Close[0] >= Open[1])
                {
                    if (ChartControl != null)
                    {
                        CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 1, upColor);
                        BarColor = downColor;
                    }

                    DrawText("Dark Cloud Cover" + CurrentBar, false, "Dark Cloud Cover", 1, High[0], 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.Doji:
            {
                #region Doji
                if (Math.Abs(Close[0] - Open[0]) <= (High[0] - Low[0]) * 0.07)
                {
                    if (ChartControl != null)
                    {
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                    }

                    int yOffset = Close[0] > Close[Math.Min(1, CurrentBar)] ? 10 : -10;
                    DrawText("Doji Text" + CurrentBar, false, "Doji", 0, (yOffset > 0 ? High[0] : Low[0]), yOffset, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.DownsideTasukiGap:
            {
                #region Downside Tasuki Gap
                if (CurrentBar < 2)
                {
                    return;
                }

                if (Close[2] < Open[2] && Close[1] < Open[1] && Close[0] > Open[0] &&
                    High[1] < Low[2] &&
                    Open[0] > Close[1] && Open[0] < Open[1] &&
                    Close[0] > Open[1] && Close[0] < Close[2])
                {
                    if (ChartControl != null)
                    {
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        BarColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 2, downColor);
                    }

                    DrawText("Downside Tasuki Gap" + CurrentBar, false, "Downside Tasuki Gap", 1, High[2], 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.EveningStar:
            {
                #region Evening Star
                if (CurrentBar < 2)
                {
                    return;
                }

                if (Close[2] > Open[2] && Close[1] > Close[2] && Open[0] < (Math.Abs((Close[1] - Open[1]) / 2) + Open[1]) && Close[0] < Open[0])
                {
                    if (ChartControl != null)
                    {
                        if (Close[0] > Open[0])
                        {
                            BarColor = upColor;
                            CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        }
                        else
                        {
                            BarColor = downColor;
                        }

                        if (Close[1] > Open[1])
                        {
                            BarColorSeries.Set(CurrentBar - 1, upColor);
                            CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        }
                        else
                        {
                            BarColorSeries.Set(CurrentBar - 1, downColor);
                        }

                        if (Close[2] > Open[2])
                        {
                            BarColorSeries.Set(CurrentBar - 2, upColor);
                            CandleOutlineColorSeries.Set(CurrentBar - 2, downColor);
                        }
                        else
                        {
                            BarColorSeries.Set(CurrentBar - 2, downColor);
                        }
                    }

                    DrawText("Evening Star Text" + CurrentBar, false, "Evening Star", 1, High[1], 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.FallingThreeMethods:
            {
                #region Falling Three Methods
                if (CurrentBar < 5)
                {
                    return;
                }

                if (Close[4] < Open[4] && Close[0] < Open[0] && Close[0] < Low[4] &&
                    High[3] < High[4] && Low[3] > Low[4] &&
                    High[2] < High[4] && Low[2] > Low[4] &&
                    High[1] < High[4] && Low[1] > Low[4])
                {
                    if (ChartControl != null)
                    {
                        BarColor = downColor;
                        BarColorSeries.Set(CurrentBar - 4, downColor);

                        int x = 1;
                        while (x < 4)
                        {
                            if (Close[x] > Open[x])
                            {
                                BarColorSeries.Set(CurrentBar - x, upColor);
                                CandleOutlineColorSeries.Set(CurrentBar - x, downColor);
                            }
                            else
                            {
                                BarColorSeries.Set(CurrentBar - x, downColor);
                            }
                            x++;
                        }
                    }

                    DrawText("Falling Three Methods" + CurrentBar, false, "Falling Three Methods", 2, Math.Max(High[0], High[4]), 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.Hammer:
            {
                #region Hammer
                if (TrendStrength > 0)
                {
                    if (!downTrend || MIN(Low, TrendStrength)[0] != Low[0])
                    {
                        return;
                    }
                }

                if (Low[0] < Open[0] - 5 * TickSize && Math.Abs(Open[0] - Close[0]) < (0.10 * (High[0] - Low[0])) && (High[0] - Close[0]) < (0.25 * (High[0] - Low[0])))
                {
                    if (ChartControl != null)
                    {
                        if (Close[0] > Open[0])
                        {
                            BarColor = upColor;
                            CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        }
                        else
                        {
                            BarColor = downColor;
                        }
                    }

                    DrawText("Hammer" + CurrentBar, false, "Hammer", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.HangingMan:
            {
                #region Hanging Man
                if (TrendStrength > 0)
                {
                    if (!upTrend || MAX(High, TrendStrength)[0] != High[0])
                    {
                        return;
                    }
                }

                if (Low[0] < Open[0] - 5 * TickSize && Math.Abs(Open[0] - Close[0]) < (0.10 * (High[0] - Low[0])) && (High[0] - Close[0]) < (0.25 * (High[0] - Low[0])))
                {
                    if (ChartControl != null)
                    {
                        if (Close[0] > Open[0])
                        {
                            BarColor = upColor;
                            CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        }
                        else
                        {
                            BarColor = downColor;
                        }
                    }

                    DrawText("Hanging Man" + CurrentBar, false, "Hanging Man", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.InvertedHammer:
            {
                #region Inverted Hammer
                if (TrendStrength > 0)
                {
                    if (!upTrend || MAX(High, TrendStrength)[0] != High[0])
                    {
                        return;
                    }
                }

                if (High[0] > Open[0] + 5 * TickSize && Math.Abs(Open[0] - Close[0]) < (0.10 * (High[0] - Low[0])) && (Close[0] - Low[0]) < (0.25 * (High[0] - Low[0])))
                {
                    if (ChartControl != null)
                    {
                        if (Close[0] > Open[0])
                        {
                            BarColor = upColor;
                            CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        }
                        else
                        {
                            BarColor = downColor;
                        }
                    }

                    DrawText("Inverted Hammer" + CurrentBar, false, "InvertedHammer", 0, High[0] + 5 * TickSize, 0, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.MorningStar:
            {
                #region Morning Star
                if (CurrentBar < 2)
                {
                    return;
                }

                if (Close[2] < Open[2] && Close[1] < Close[2] && Open[0] > (Math.Abs((Close[1] - Open[1]) / 2) + Open[1]) && Close[0] > Open[0])
                {
                    if (ChartControl != null)
                    {
                        if (Close[0] > Open[0])
                        {
                            BarColor = upColor;
                            CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        }
                        else
                        {
                            BarColor = downColor;
                        }

                        if (Close[1] > Open[1])
                        {
                            BarColorSeries.Set(CurrentBar - 1, upColor);
                            CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        }
                        else
                        {
                            BarColorSeries.Set(CurrentBar - 1, downColor);
                        }

                        if (Close[2] > Open[2])
                        {
                            BarColorSeries.Set(CurrentBar - 2, upColor);
                            CandleOutlineColorSeries.Set(CurrentBar - 2, downColor);
                        }
                        else
                        {
                            BarColorSeries.Set(CurrentBar - 2, downColor);
                        }
                    }

                    DrawText("Morning Star Text" + CurrentBar, false, "Morning Star", 1, Low[1], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.PiercingLine:
            {
                #region Piercing Line
                if (CurrentBar < 1 || (TrendStrength > 0 && !downTrend))
                {
                    return;
                }

                if (Open[0] < Low[1] && Close[1] < Open[1] && Close[0] > Open[0] && Close[0] >= Close[1] + (Open[1] - Close[1]) / 2 && Close[0] <= Open[1])
                {
                    if (ChartControl != null)
                    {
                        CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 1, upColor);
                        BarColor = downColor;
                    }

                    DrawText("Piercing Line" + CurrentBar, false, "Piercing Line", 1, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }

                #endregion
                break;
            }

            case ChartPattern.RisingThreeMethods:
            {
                #region Rising Three Methods
                if (CurrentBar < 5)
                {
                    return;
                }

                if (Close[4] > Open[4] && Close[0] > Open[0] && Close[0] > High[4] &&
                    High[3] < High[4] && Low[3] > Low[4] &&
                    High[2] < High[4] && Low[2] > Low[4] &&
                    High[1] < High[4] && Low[1] > Low[4])
                {
                    if (ChartControl != null)
                    {
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        BarColorSeries.Set(CurrentBar - 4, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 4, downColor);

                        int x = 1;
                        while (x < 4)
                        {
                            if (Close[x] > Open[x])
                            {
                                BarColorSeries.Set(CurrentBar - x, upColor);
                                CandleOutlineColorSeries.Set(CurrentBar - x, downColor);
                            }
                            else
                            {
                                BarColorSeries.Set(CurrentBar - x, downColor);
                            }
                            x++;
                        }
                    }

                    DrawText("Rising Three Methods" + CurrentBar, false, "Rising Three Methods", 2, Math.Min(Low[0], Low[4]), -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.ShootingStar:
            {
                #region Shooting Star
                if (CurrentBar < 1 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if (High[0] > Open[0] && (High[0] - Open[0]) >= 2 * (Open[0] - Close[0]) && Close[0] < Open[0] && (Close[0] - Low[0]) <= 2 * TickSize)
                {
                    if (ChartControl != null)
                    {
                        BarColor = downColor;
                    }

                    DrawText("Shooting Star" + CurrentBar, false, "Shooting Star", 0, Low[0], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.StickSandwich:
            {
                #region Stick Sandwich
                if (CurrentBar < 2)
                {
                    return;
                }

                if (Close[2] == Close[0] && Close[2] < Open[2] && Close[1] > Open[1] && Close[0] < Open[0])
                {
                    if (ChartControl != null)
                    {
                        BarColor = downColor;
                        BarColorSeries.Set(CurrentBar - 1, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 2, downColor);
                    }

                    DrawText("Stick Sandwich" + CurrentBar, false, "Stick Sandwich", 1, Math.Min(Low[0], Math.Min(Low[1], Low[2])), -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.ThreeBlackCrows:
            {
                #region Three Black Crows
                if (CurrentBar < 2 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if (Value[1] == 0 && Value[2] == 0 &&
                    Close[0] < Open[0] && Close[1] < Open[1] && Close[2] < Open[2] &&
                    Close[0] < Close[1] && Close[1] < Close[2] &&
                    Open[0] < Open[1] && Open[0] > Close[1] &&
                    Open[1] < Open[2] && Open[1] > Close[2])
                {
                    if (ChartControl != null)
                    {
                        BarColor = downColor;
                        BarColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 2, downColor);
                    }

                    DrawText("Three Black Crows" + CurrentBar, false, "Three Black Crows", 1, High[2], 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.ThreeWhiteSoldiers:
            {
                #region Three White Soldiers
                if (CurrentBar < 2 || (TrendStrength > 0 && !downTrend))
                {
                    return;
                }

                if (Value[1] == 0 && Value[2] == 0 &&
                    Close[0] > Open[0] && Close[1] > Open[1] && Close[2] > Open[2] &&
                    Close[0] > Close[1] && Close[1] > Close[2] &&
                    Open[0] < Close[1] && Open[0] > Open[1] &&
                    Open[1] < Close[2] && Open[1] > Open[2])
                {
                    if (ChartControl != null)
                    {
                        BarColor = upColor;
                        CandleOutlineColorSeries.Set(CurrentBar, downColor);
                        BarColorSeries.Set(CurrentBar - 1, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 2, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 2, downColor);
                    }

                    DrawText("Three White Soldiers" + CurrentBar, false, "Three White Soldiers", 1, Low[2], -10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.UpsideGapTwoCrows:
            {
                #region Upside Gap Two Crows
                if (CurrentBar < 2 || (TrendStrength > 0 && !upTrend))
                {
                    return;
                }

                if (Close[2] > Open[2] && Close[1] < Open[1] && Close[0] < Open[0] &&
                    Low[1] > High[2] &&
                    Close[0] > High[2] &&
                    Close[0] < Close[1] && Open[0] > Open[1])
                {
                    if (ChartControl != null)
                    {
                        BarColor = downColor;
                        BarColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 2, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 2, downColor);
                    }

                    DrawText("Upside Gap Two Crows" + CurrentBar, false, "Upside Gap Two Crows", 1, Math.Max(High[0], High[1]), 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }

            case ChartPattern.UpsideTasukiGap:
            {
                #region Upside Tasuki Gap
                if (CurrentBar < 2)
                {
                    return;
                }

                if (Close[2] > Open[2] && Close[1] > Open[1] && Close[0] < Open[0] &&
                    Low[1] > High[2] &&
                    Open[0] < Close[1] && Open[0] > Open[1] &&
                    Close[0] < Open[1] && Close[0] > Close[2])
                {
                    if (ChartControl != null)
                    {
                        BarColor = downColor;
                        BarColorSeries.Set(CurrentBar - 1, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 1, downColor);
                        BarColorSeries.Set(CurrentBar - 2, upColor);
                        CandleOutlineColorSeries.Set(CurrentBar - 2, downColor);
                    }

                    DrawText("Upside Tasuki Gap" + CurrentBar, false, "Upside Tasuki Gap", 1, Math.Max(High[0], High[1]), 10, txtColor, textFont, StringAlignment.Center, Color.Transparent, Color.Transparent, 0);

                    patternsFound++;
                    Value.Set(1);
                }
                #endregion
                break;
            }
            }

            DrawTextFixed("Count", patternsFound.ToString() + " patterns found", TextPosition.BottomRight);
        }