Heiken Ashi Cannot Find the haClose==haLow Signal

 

Hi all,

I need help on developing the signal using Heiken Ashi.

I am writing an EA with Heiken Ashi, which has 3 conditions on the signal:

  1. Two consecutive heiken bars of same color (Bull if haOpen2<haClose2 && haOpen1<haClose2)
  2. Long shadow on the direction of trend (Bull if haClose1<haHigh1)
  3. No shadow on the opposite side of the trend (Bull if haOpen==haLow)

I have inserted the signal one-by-one and succeeded signal  #1 & #2, but I cannot somehow implement the signal #3. It seems like there is no case of `haOpen==haLow` or `haOpen==haHigh` whatsoever. Is that possible? I am sure there is some error in my code, but cannot find one. If you could give me some advice, I am much appreciated.

Following is my simplified short code of EA:

void OnTick()
  {
   //Previous Heiken Ashi(+2)
   double haOpen2 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,2,2);
   double haClose2 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,3,2);

   //Previous Heiken Ashi(+1)
   double haOpen1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,2,1);
   double haClose1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,3,1);
   double haHigh1, haLow1;
   
   if(haOpen1 < haClose1)//Bullish Candle
   { 
      double haHigh1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,1,1);
      double haLow1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,0,1);
   }
   else //Bearish Candle
   { 
      double haHigh1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,0,1);
      double haLow1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,1,1);
   };

   //Buy Signal

   if(haOpen1==haLow1) 

   {

     Ticket = OrderSend(_Symbol, OP_BUY, Lots, Ask, 0,0,0);

   };

   //Sell Signal

   if(haOpen1==haHigh1) 

   { 

     Ticket = OrderSend(_Symbol, OP_SELL, Lots, Bid, 0,0, 0);

   };  

If you need more information, please let me know!

Thank you!

 
sgyblee: It seems like there is no case of `haOpen==haLow` or `haOpen==haHigh` whatsoever. Is that possible?
  1. Doubles are rarely equal.
              The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Do you know what the haOpen is? It's Previous candle's (haO+haC)/2 and haC is (O+H+L+C)/4.
              Candlestick chart - Wikipedia
    The only time that can equal the HA Low is when all three are exactly equal, or the market gaps down to that exact value and only ticks up from that.

  3.    double haOpen2 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,2,2);
       double haClose2 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,3,2);
       double haOpen1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,2,1);
       double haClose1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,3,1);
          double haHigh1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,0,1);
          double haLow1 = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,1,1);
    Don't keep pasting the same code over and over. Encapsulate it.
              take candle color hekin ashi - Inflation - MQL4 and MetaTrader 4 - MQL4 programming forum

  4.      Ticket = OrderSend(_Symbol, OP_BUY, Lots, Ask, 0,0,0);
         Ticket = OrderSend(_Symbol, OP_SELL, Lots, Bid, 0,0, 0);
    
    Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

 
whroeder1:
  1. Doubles are rarely equal.
              The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Do you know what the haOpen is? It's Previous candle's (haO+haC)/2 and haC is (O+H+L+C)/4.
              Candlestick chart - Wikipedia
    The only time that can equal the HA Low is when all three are exactly equal, or the market gaps down to that exact value and only ticks up from that.

  3. Don't keep pasting the same code over and over. Encapsulate it.
              take candle color hekin ashi - Inflation - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

 
whroeder1:
  1. Doubles are rarely equal.
              The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Do you know what the haOpen is? It's Previous candle's (haO+haC)/2 and haC is (O+H+L+C)/4.
              Candlestick chart - Wikipedia
    The only time that can equal the HA Low is when all three are exactly equal, or the market gaps down to that exact value and only ticks up from that.

  3. Don't keep pasting the same code over and over. Encapsulate it.
              take candle color hekin ashi - Inflation - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
    Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.

Awesome! Thanks for the helpful tips with links. Difficult to understand all of these details at once for me, but I will surely try to understand them one by one! Happy coding! :)
 
whroeder1:
  1. Doubles are rarely equal.
              The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. Do you know what the haOpen is? It's Previous candle's (haO+haC)/2 and haC is (O+H+L+C)/4.
              Candlestick chart - Wikipedia
    The only time that can equal the HA Low is when all three are exactly equal, or the market gaps down to that exact value and only ticks up from that.

I found out that there are a lot of time when `haOpen==haLow` and `haOpen==haHigh`. haHigh(or haLow) is equal to Max(or Min) among high(or low), haOpen, and haClose. There were many times when haOpen was the max( or min) among those three.

But the main problem was my code. Because I declared `double` again inside of the if block, variables were not assigned properly and `haHigh` and 'haLow' ended up as `0.0` all the time. 

Anyway, thanks again for the tips; my codes look cleaner with encapsulation and using Print to see what is really happening helped me the debugging.

Happy coding! :)