Challenge is identifying Bullish Candle

 

Dear Members

I have challenge to identify Bullish candle with attached code. Codes for Calculating BEAR_Doji / BEAR_SpinningTop / BEAR_LONGLOWERWICK candles also attached just in case needed by members for understanding.

//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:       IsBearDoji()
//| APPLICATION:  RETURN TRUE IS BULLISH CANDLE WITH BODYSIZE <= 5% OF ITS AMPLITUDE
//+-----------------------------------------------------------------------------------------------------------------------------+
bool CiHAshi::IsBearDoji(int pIndex) {

        int k = pIndex;

        if(GetIndexClose(k) < GetIndexOpen(k) &&
                NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) <= 0.05) return(true);
        else return(false);

} // END Of IsBearDoji()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:       IsBearSTop()
//| APPLICATION:  RETURN TRUE IF BEARISH CANDLE WITH BODYSIZE > 5% AND <= 20% OF ITS AMPLITUDE
//+-----------------------------------------------------------------------------------------------------------------------------+
bool CiHAshi::IsBearSTop(int pIndex) {

        int k = pIndex;

        if(GetIndexClose(k) < GetIndexOpen(k) &&
                 NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4)  > 0.05 &&
                 NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) <= 0.20return(true);
        else     return(false);

} // END Of IsBearSTop()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:       IsBearLLW()
//| APPLICATION:  RETURN TRUE IF BEARISH WITH LOWER WICK SIZE MORE 50% OF AMPLITUDE
//| NOTE:                                       A SIGN OF WEAK BEARISH TREND, AS BEARS SEEMS TO HAVE FAILED TO PUSH PRICE DOWN SUFFICIENTLY
//+-----------------------------------------------------------------------------------------------------------------------------+
bool CiHAshi::IsBearLLW(int pIndex) {

        int k = pIndex;

        if(GetIndexClose(k) < GetIndexOpen(k)) {
                if(NormalizeDouble(GetLowerWick(k) / GetAmplitude(k),4) > 0.50 &&
                         NormalizeDouble(GetBodySize(k)  / GetAmplitude(k),4) > 0.20) {
                        return(true);
                }
        }

        return(false);

} // END Of IsBearLLW()
//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:       IsBearish()
//| APPLICATION:  Returns true if HA Candle is STRONG BEARISH Bar
//| TEXT DEFINITION HA HIGH = HA OPEN, WE TAKE UPPPER WICK <= 1% OF AMPLITUDE (MARKET IS NOT PERFECT)
//+-----------------------------------------------------------------------------------------------------------------------------+
bool CiHAshi::IsBearish(int pIndex) {

        int k = pIndex;
/*2022.01.03 19:00:00 [BEAR_DOJI] [0.5606] <= 0.05
                        [BEAR_STOP] LowerWick[0.5606] > 0.05 Body[0.4291] <= 0.20
                        [BEAR_LLW] LowerWick[0.5606] > 0.50 BodySize[0.4291] > 0.20
                        [BEARISH] UpperWick[0.0103] <= 0.01 LowerWick[0.5606] <= 0.50 BodySize[0.4291] > 0.20 */ ... By definition it should not be BEARISH CANDLE, however it returns as Bearish

        // Tried Method [1]
        if(GetIndexClose(k) < GetIndexOpen(k)) {
        if((NormalizeDouble(GetUpperWick(k) / GetAmplitude(k),4) <= 0.01) &&
           (NormalizeDouble(GetLowerWick(k) / GetAmplitude(k),4) <= 0.50) &&
	   (NormalizeDouble(GetBodySize(k)  / GetAmplitude(k),4)  > 0.20))                        return(true);
        }
	return(false);
	
        // Tried Method [2]
        if(GetIndexClose(k) < GetIndexOpen(k)) {
          if(!(NormalizeDouble(GetUpperWick(k) / GetAmplitude(k),4) <= 0.01))                     return(false);
          if(!(NormalizeDouble(GetLowerWick(k) / GetAmplitude(k),4) <= 0.50))                     return(false);
          if(!(NormalizeDouble(GetBodySize(k)  / GetAmplitude(k),4)  > 0.20))                     return(false);
          	return(true);
        }

        return(false);

} // END Of IsBearish()

Thanks in advance for your cooperation and suggestions.

regards

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 

Why don't you search first before trying out the mistakes?

Search for doji gives me 2 links to the code base and half a dozen articles about it: https://www.mql5.com/en/search#!keyword=doji%20candle%20detection

Copy and change according your needs - it's a lot faster.

 
Carl Schreiber #:

Why don't you search first before trying out the mistakes?

Search for doji gives me 2 links to the code base and half a dozen articles about it: https://www.mql5.com/en/search#!keyword=doji%20candle%20detection

Copy and change according your needs - it's a lot faster.

Dear Carl

Thanks a lot for your response. Yes I used to do the same, and even now sometimes I do search. Anyway for me it actually consumes more time then looking out for mistake. I had downloaded Candle Pattern detector long back and done a lot of modifications in the same, as text book definitions does work efficiently in real life.

Lately I was introduced to Heiken Ashi Candles and on the basis of earlier 'Candle Pattern Detector' I have make my own HA Candle Pattern Detector, including defining what HA Doji etc should be.

This was an attempt to identify patterns with separate methods, and I discovered that same candle is detected by two different patterns. That is where I started looking deep into my code and could not find any logical reasoning for the same.

THIS IS TIME WHEN I RESORTED TO SEEK EXPERTS OPINION ON THE FORUM. This way I think learning process goes on. But it seems all dont share the same view here!!!

Anyway I have rewritten the code again in a different style and initial tests seems to be promising. I am attaching it here, for someone who may be benefitted by it.

//+-----------------------------------------------------------------------------------------------------------------------------+
//| METHOD:       GetHACandleType()
//| APPLICATION:  
//+-----------------------------------------------------------------------------------------------------------------------------+
CENUM_HA_BAR CiHAshi::GetHACandleType(int pIndex) {

        int k = pIndex;

        if(GetIndexClose(k) > GetIndexOpen(k)) {
                if(NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) <= 0.05) {
                        return(BULL_DOJI);      
                } else
                if(NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) > 0.05 &&
                         NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) <= 0.20) {
                        return(BULL_STOP);      
                } else
                if(NormalizeDouble(GetUpperWick(k) / GetAmplitude(k),4) > 0.50 &&
                         NormalizeDouble(GetBodySize(k)  / GetAmplitude(k),4) > 0.20) {
                        return(BULL_LUW);
                } else
                if(NormalizeDouble(GetLowerWick(k) / GetAmplitude(k),4) <= 0.01 &&
                         NormalizeDouble(GetUpperWick(k) / GetAmplitude(k),4) <= 0.50 &&
                         NormalizeDouble(GetBodySize(k)  / GetAmplitude(k),4)  > 0.20) {
                        return(BULLISH);
                } else
                        return(BULL_WEAK);
        } else
        if(GetIndexClose(k) < GetIndexOpen(k)) {
                if(NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) <= 0.05) {
                        return(BEAR_DOJI);      
                } else
                if(NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) > 0.05 &&
                         NormalizeDouble(GetBodySize(k) / GetAmplitude(k),4) <= 0.20) {
                        return(BEAR_STOP);      
                } else
                if(NormalizeDouble(GetLowerWick(k) / GetAmplitude(k),4) > 0.50 &&
                         NormalizeDouble(GetBodySize(k)  / GetAmplitude(k),4) > 0.20) {
                        return(BEAR_LLW);
                } else
                if(NormalizeDouble(GetUpperWick(k) / GetAmplitude(k),4) <= 0.01 &&
                         NormalizeDouble(GetLowerWick(k) / GetAmplitude(k),4) <= 0.50 &&
                         NormalizeDouble(GetBodySize(k)  / GetAmplitude(k),4)  > 0.20) {
                        return(BEARISH);
                } else
                        return(BEAR_WEAK);
        }

        return(WRONG_VALUE);

} // END Of GetHACandleType()
Reason: