Heiken Ashi candlestick

 
Hello!
I have an EA that’s works with the Heikin Ashi candles and another indicator that I made. Currently the EA opens the orders  at the closing of candlestick when the signal is made. 

The question is: I’m able to program the EA to open orders in the next Heikin Ashi candle when the signal is activated?
 
Dinosatoshi: I need to know if I have an EA with Heiken Ashi candlestick and indicator with and buy and sell signal, if it’s possible to opens orders in the open in the next HA candle or not

Please note the the Heikin Ashi Open and Close prices are virtual prices (moving average) and not the prices of the current real candle. So when you place the order it will be for the current market prices, not the heikin ashi prices.

You can obviously also place pending orders for the desired prices based on the Heikin Ashi, but there is no guarantee that it will be triggered within a reasonable timespan.

 
Yes, Heikin Ashi is "virtual", but it is not MA based. It is Median Price based, which is the average of (high + low) / 2.

So it is technically an average, but not in the sense of a known MA with periods, like SMA 50.


 
Dominik Christian Egert #:
Yes, Heikin Ashi is "virtual", but it is not MA based. It is Median Price based, which is the average of (high + low) / 2.

So it is technically an average, but not in the sense of a known MA with periods, like SMA 50.


So, can the operations be made to open based on HA's open or not?
 
Dominik Christian Egert #: Yes, Heikin Ashi is "virtual", but it is not MA based. It is Median Price based, which is the average of (high + low) / 2. So it is technically an average, but not in the sense of a known MA with periods, like SMA 50.

A Heikin Ashi is a exponential moving average (EMA) of period 3 (alpha = 0.5), of the Total Price ( (O+H+L+C)/4 ). It is definitely not median price.

 
Dinosatoshi #: So, can the operations be made to open based on HA's open or not?

No! Not at the open of the bar. Only possible if you wait for the quote to move to the desired price, but by then it may already be a invalid signal or it may never happen at all.

I repeat, Heikin Ashi is just an indicator in the form of a candle. It is not a real candle or bar. It is virtual. It is just an indicator.

 
Fernando Carreiro #:

No! Not at the open of the bar. Only possible if you wait for the quote to move to the desired price, but by then it may already be a invalid signal or it may never happen at all.

I repeat, Heikin Ashi is just an indicator in the form of a candle. It is not a real candle or bar. It is virtual. It is just an indicator.

Thanks Sir! 🙏🏼
 
Fernando Carreiro #:

A Heikin Ashi is a exponential moving average (EMA) of period 3 (alpha = 0.5), of the Total Price ( (O+H+L+C)/4 ). It is definitely not median price.

Are you sure???

I cannot find EMA/SMA here:

//+------------------------------------------------------------------+
//| Heiken Ashi                                                      |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int start;
//--- preliminary calculations
   if(prev_calculated==0)
     {
      ExtLBuffer[0]=low[0];
      ExtHBuffer[0]=high[0];
      ExtOBuffer[0]=open[0];
      ExtCBuffer[0]=close[0];
      start=1;
     }
   else
      start=prev_calculated-1;

//--- the main loop of calculations
   for(int i=start; i<rates_total && !IsStopped(); i++)
     {
      double ha_open =(ExtOBuffer[i-1]+ExtCBuffer[i-1])/2;
      double ha_close=(open[i]+high[i]+low[i]+close[i])/4;
      double ha_high =MathMax(high[i],MathMax(ha_open,ha_close));
      double ha_low  =MathMin(low[i],MathMin(ha_open,ha_close));

      ExtLBuffer[i]=ha_low;
      ExtHBuffer[i]=ha_high;
      ExtOBuffer[i]=ha_open;
      ExtCBuffer[i]=ha_close;

      //--- set candle color
      if(ha_open<ha_close)
         ExtColorBuffer[i]=0.0; // set color DodgerBlue
      else
         ExtColorBuffer[i]=1.0; // set color Red
     }
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
You are right, it is not median, but one of the weighted definitions, OHLC/4.

Close is OHLC/4
Open is OC/2 (from the previous candle)

So, yes, you are right about it not being median.

But it is not EMA3 either. Is it?
 
Dominik Christian Egert #: But it is not EMA3 either. Is it?

Yes it is. Not because it has a specific EMA calculation but because of the math, O=(O1+C1)/2 recursively.

Add an EMA(3) to your chart and see how it overlays the EMA on some candles.

 
Dominik Christian Egert #: You are right, it is not median, but one of the weighted definitions, OHLC/4. Close is OHLC/4. Open is OC/2 (from the previous candle). So, yes, you are right about it not being median. But it is not EMA3 either. Is it?
Dominik Christian Egert #: Are you sure??? I cannot find EMA/SMA here:

Yes, I am absolutely sure.

  • haClose = ( Open + High + Low + Close) / 4
  • haOpen = ( haOpen(previous) + haClose(previous) ) / 2
    =  haOpen(previous) + 0.5 * ( haClose(previous) - haOpen(previous) ) = μn−1 + α(xn − μn−1)
  • EMS equation: μn = μn−1 + α(xn − μn−1)
  • alpha for period 3 = α = 2 / ( p + 1 ) = 2 / (3 + 1) = 2 /4 = 0.5

The only detail to note is the current haOpen is based on the previous Total Price instead of the current Total Price (data points are shifted by one) but the equation remains the same.

EDIT: Here are the equations in graphic form for easier viewing:


EDIT 2: This is the reason why I publish my Dōteki Heikin Ashi (Dynamic Average Foot/Bar) with the variable period, where a period of 3.0 is the default for the original Heikin Ashi.


    Dōteki Heikin Ashi (Dynamic Average Foot/Bar)
    Dōteki Heikin Ashi (Dynamic Average Foot/Bar)
    • www.mql5.com
    A dynamic version of the standard Heikin Ashi indicator (code compatible with both MQL4 or MQL5).