Problems with Heiken Ashi candles

 

Hi Folks,


I've got an problem with Heiken Ashi candles. I want to use them in my expert advisor and got some problems with the code. I've searched nearly the whole internet for an answer to solve this problem but didn't got it right. So please help me. First I'm reading the Heiken indicator with the following code:


//---- get indicators
   double Heiken_op = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,2,0);
   double Heiken_cl = iCustom(NULL,0,"Heiken Ashi",Red,White,Red,White,3,0);


Then I want to enter LONG if the color of the candles is white. I simply check if the opening value is smaller than the closing value:


//---- check if trades are open
   if(OrdersTotal() == 0)
   {
//---- condition enter long
      if(
         Heiken_op < Heiken_cl
        )
        {
// do something to enter long ...
        }
   } 

That's it. The conditions for the exit are simply the other way round. But now with my test run I got some strange results:




The EA enters the trade during a chain of red candles or closes a trade within a row of white candles. So my conditions for white/red candles are probably wrong... Can someone find the mistakte?!?


Best regards,

TheScalper

 
TheScalper:

[...] The EA enters the trade during a chain of red candles or closes a trade within a row of white candles. So my conditions for white/red candles are probably wrong... Can someone find the mistakte?!?

It looks very likely to be because the candle colour potentially changes during the course of the hour/day/whatever time period you're trading. Taking the first two bars in your screenshot, you've got a white candle followed by a red candle. The second one almost certainly started white - causing the EA to trade - and then turned red over the course of the hour/day/whatever (and ended red) because of the price movement within that time period.


Unless you're explicitly only trading at the end of bars, you can't simply look back at a chart and expect to match up the candle colour, from the end of each minute/hour/whatever, against what the EA saw during the minute/hour/whatever.

 

What you need to do is to provide a shift argument > 0 to your iCustom call. Instead of a shift argument of 0, try a shift argument of 1. This will return the values for the just-completed candle, avoiding false signals from the incomplete current candle.


RS

 

Thank you!


@jjc: I'm using for the backtest only the "open price" model - but as RhythmStar mentioned -> I've set a shift of 1 to the iCustom function and tested again. This way the results are looking good now! Great.


Bests,

TheScalper

Reason: