Category Trend  Published on 02/12/2023

DRKHASHIXCandlestick

Description

"To download the extraordinary Dr. khashix, please visit the drkhashix.com."

"Vittaverse is the best broker for bot and traid; they support a variety of currencies, have low spreads, and most importantly, provide you with funding." 

this is link: click here for sign up Vittaverse 

General Description: This indicator is designed to identify specific candlestick patterns in financial charts. It is used to detect and signal Bullish and Bearish market conditions.

 

 

Identified Candlestick Patterns:

  1. Bullish Power: Indicates an increase in market strength and is represented by the symbol ▲.
  2. Bearish Power: Indicates a decrease in market strength and is represented by the symbol ▼.
  3. Bullish Hammer: A Bullish Hammer pattern has been identified and is represented by the symbol ▲.
  4. Bearish Hammer: A Bearish Hammer pattern has been identified and is represented by the symbol ▼.

Adjustable Parameters:

  • Min Shadow Height: Specifies the minimum shadow height for Hammer patterns.
  • Candles Count: The desired number of candles for pattern detection.
  • Period Reference: The number of reference candles for calculating the average candle height.
  • Period To Check: The number of candles to check for pattern recognition.
  • Candle Power Threshold: The threshold for candle strength used as a filter for pattern detection.

How to Use:

  • Bullish Power and Bearish Power patterns signal based on the detection of three consecutive positive or negative candles, respectively. The Candle Power Threshold filter is applied to confirm the signals.
  • Bullish Hammer pattern signals when a specific Bullish Hammer condition is identified.
  • Bearish Hammer pattern signals when a specific Bearish Hammer condition is identified.

Important Notes:

  • This indicator automatically generates and displays Bullish and Bearish signals on the chart.
  • It utilizes information on the average candle height to assess candle strength and detect patterns.

Additional Information:

  • This indicator operates independently on the chart and provides visual signals for detected patterns.

If anyone could review the code and share their feedback in the comments, that would be great

Best regards, Dr.khashix. I LOVE YOU ALL


using System;
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DRKHASHIXCandlestick : Indicator
    {
        public enum Signals
        {
            None,
            Bullishpower,
            Bearishpower,
            BullishHammer,
            BearishHammer
        }

        [Output("Bullish power", Color = Colors.White, Thickness = 7, PlotType = PlotType.Points)]
        public IndicatorDataSeries Bullishpower { get; set; }

        [Output("Bearish power", Color = Colors.RoyalBlue, Thickness = 7, PlotType = PlotType.Points)]
        public IndicatorDataSeries Bearishpower { get; set; }

        [Output("Bullish Hammer", Color = Colors.SpringGreen, Thickness = 7, PlotType = PlotType.Points)]
        public IndicatorDataSeries BullishHammer { get; set; }

        [Output("Bearish Hammer", Color = Colors.MediumVioletRed, Thickness = 7, PlotType = PlotType.Points)]
        public IndicatorDataSeries BearishHammer { get; set; }

        [Parameter("Min Shadow Height", DefaultValue = 0.0003, Group = "hammer")]
        public double MinShadowHeight { get; set; }

        [Parameter("Candles Count", DefaultValue = 3)]
        public int CandlesCount { get; set; }

        [Parameter("Period Reference", DefaultValue = 100, MinValue = 1)]
        public int PeriodReference { get; set; }

        [Parameter("Period To Check", DefaultValue = 3, MinValue = 1)]
        public int PeriodToCheck { get; set; }

        [Parameter("Candle Power Threshold", DefaultValue = 1.5)]
        public double CandlePowerThreshold { get; set; }

        private Signals lastSignal = Signals.None;
        private int consecutiveGreenCandles = 0;
        private int consecutiveRedCandles = 0;

        private void PrintLastSignal()
        {
            string lastSignalText = "LAST PATTERN : ";

            switch (lastSignal)
            {
                case Signals.Bullishpower:
                    lastSignalText += "Bullish power = ▲";
                    break;
                case Signals.Bearishpower:
                    lastSignalText += "Bearish power = ▼";
                    break;
                case Signals.BullishHammer:
                    lastSignalText += "Bullish Hammer = ▲";
                    break;
                case Signals.BearishHammer:
                    lastSignalText += "Bearish Hammer = ▼";
                    break;
                default:
                    lastSignalText += "None signal";
                    break;
            }

            ChartObjects.DrawText("lastSignalText", lastSignalText, StaticPosition.TopLeft, Colors.White);
        }

        public override void Calculate(int index)
        {
            if (index < Math.Max(CandlesCount, Math.Max(PeriodReference, PeriodToCheck)))
                return;

            double sumCandleHeightReference = 0;
            double sumCandleHeightToCheck = 0;

            for (int i = 0; i < PeriodReference; i++)
                sumCandleHeightReference += MarketSeries.High[index - i] - MarketSeries.Low[index - i];

            for (int i = 0; i < PeriodToCheck; i++)
                sumCandleHeightToCheck += MarketSeries.High[index - i] - MarketSeries.Low[index - i];

            double averageCandleHeightReference = sumCandleHeightReference / PeriodReference;
            double averageCandleHeightToCheck = sumCandleHeightToCheck / PeriodToCheck;

            double candlePower = averageCandleHeightToCheck / averageCandleHeightReference;

            // Use candlePower in signal generation as a filter
            if (IsGreenCandles(index))
            {
                consecutiveGreenCandles++;

                if (consecutiveGreenCandles == CandlesCount && lastSignal != Signals.Bullishpower && candlePower > CandlePowerThreshold)
                {
                    Bullishpower[index] = MarketSeries.Low[index] - Symbol.PipSize;
                    lastSignal = Signals.Bullishpower;
                    Bearishpower[index] = double.NaN;
                }
                else
                {
                    Bearishpower[index] = double.NaN;
                }

                // Check for Bullish Hammer
                if (IsBullishHammer(index))
                {
                    BullishHammer[index] = MarketSeries.Low[index] - Symbol.PipSize;
                    lastSignal = Signals.BullishHammer;
                    BearishHammer[index] = double.NaN;
                }

                consecutiveRedCandles = 0;
            }
            else if (IsRedCandles(index))
            {
                consecutiveRedCandles++;

                if (consecutiveRedCandles == CandlesCount && lastSignal != Signals.Bearishpower && candlePower > CandlePowerThreshold)
                {
                    Bearishpower[index] = MarketSeries.High[index] + Symbol.PipSize;
                    lastSignal = Signals.Bearishpower;
                    Bullishpower[index] = double.NaN;
                }
                else
                {
                    BullishHammer[index] = double.NaN;
                }

                // Check for Bearish Hammer
                if (IsBearishHammer(index))
                {
                    BearishHammer[index] = MarketSeries.High[index] + Symbol.PipSize;
                    lastSignal = Signals.BearishHammer;
                    BullishHammer[index] = double.NaN;
                }

                consecutiveGreenCandles = 0;
            }
            else
            {
                consecutiveGreenCandles = 0;
                consecutiveRedCandles = 0;
                Bullishpower[index] = double.NaN;
                Bearishpower[index] = double.NaN;
                BullishHammer[index] = double.NaN;
                BearishHammer[index] = double.NaN;
            }
            PrintLastSignal();
        }

        private bool IsGreenCandles(int index)
        {
            return MarketSeries.Close[index] > MarketSeries.Open[index];
        }

        private bool IsRedCandles(int index)
        {
            return MarketSeries.Close[index] < MarketSeries.Open[index];
        }

        private bool IsBullishHammer(int index)
        {
            var candle = GetCandle(index);

            // Check Min Shadow Height
            if ((candle.High - candle.Low) < MinShadowHeight)
                return false;

            if (candle.IsRiseCandle() && (candle.Close == candle.High))
            {
                if ((candle.Median() < candle.Open) && (candle.Median() < candle.Close))
                {
                    if ((candle.High - candle.Median()) > 1.618 * (candle.Close - candle.Open))
                    {
                        BullishHammer[index] = MarketSeries.Low[index] - Symbol.PipSize;
                        return true;
                    }
                }
            }

            return false;
        }

        private bool IsBearishHammer(int index)
        {
            var candle = GetCandle(index);

            // Check Min Shadow Height
            if ((candle.High - candle.Low) < MinShadowHeight)
                return false;

            if (candle.IsFallCandle() && (candle.Close == candle.Low))
            {
                if ((candle.Median() > candle.Open) && (candle.Median() > candle.Close))
                {
                    if ((candle.Median() - candle.Low) > 1.618 * (candle.Open - candle.Close))
                    {
                        BearishHammer[index] = MarketSeries.High[index] + Symbol.PipSize;
                        return true;
                    }
                }
            }

            return false;
        }

        private struct Candle
        {
            public double High;
            public double Close;
            public double Open;
            public double Low;

            public bool IsFallCandle()
            {
                return Close < Open;
            }

            public bool IsRiseCandle()
            {
                return Open < Close;
            }

            public double Median()
            {
                return (High + Low) / 2;
            }
        }

        private Candle GetCandle(int index)
        {
            return new Candle
            {
                High = MarketSeries.High[index],
                Open = MarketSeries.Open[index],
                Close = MarketSeries.Close[index],
                Low = MarketSeries.Low[index]
            };
        }
    }
}


drkhashix's avatar
drkhashix

Joined on 12.02.2023

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: DRKHASHIX Candlestick.algo
  • Rating: 5
  • Installs: 378
Comments
Log in to add a comment.
No comments found.