# Heikin Ashi Price Problem

Hi, I have a problem with my Heikin Ashi code. I searched for an expert advisor that gives me the Heikin Ashi prices to then use those for my filter. The problem I now face is that those prices are not the same as the ones that my indicator on the metatrader chart shows. I first though that I just get the price for the wrong candle or something like that, but the prices are fairly similar. My filter is based upon the Heikin Ashi chart from Mt5 and if those prices dont align I cant test it properly.

Thanks for any advise, if there is a better way to get the Heikin Ashi prices into a double data type to then use them for further calculations that would be great too.

( I did not include the actual calculations because the dont belong to the problem )

```
#property version   "1.00"

// Indicator handles
int HeikenAshiHandle;
int ATRHandle;

// Buffers
double HAOpen[];
double HAClose[];
double HAHigh[];
double HALow[];

void OnInit()
{

HeikenAshiHandle = iCustom(_Symbol, _Period, "\\Indicators\\Ashi");

}

void OnTick()
{
///////////////////////////////////////
// HEIKEN FILTER
///////////////////////////////////////

// Latest two completed bars
if (CopyBuffer(HeikenAshiHandle, 0, 1, 2, HAOpen) != 2) return;
if (CopyBuffer(HeikenAshiHandle, 3, 1, 2, HAClose) != 2) return;
// Don't need the previous candle for High/Low, but copying it anyway for the sake of code uniformity.
if (CopyBuffer(HeikenAshiHandle, 1, 1, 2, HAHigh) != 2) return;
if (CopyBuffer(HeikenAshiHandle, 2, 1, 2, HALow) != 2) return;

///////////////////////////////////////
// HEIKEN FILTER DATA CHECK
///////////////////////////////////////
static datetime prevTimeCHECK=0;
datetime lastTimeCHECK[1];
if (CopyTime(_Symbol,PERIOD_D1,0,1,lastTimeCHECK)==1 && prevTimeCHECK!=lastTimeCHECK[0])
{

Print(HAHigh[1],"_HAHigh");
Print(HALow[1], "_HALow" );
Print(HAOpen[1],"_HAOpen");
Print(HAClose[1], "_HAClose" );
Print( "_____________" );

prevTimeCHECK=lastTimeCHECK[0];
}

}
//+-----------------------------------------------------------------```

Use code:

```//+------------------------------------------------------------------+
//|                                           Simple Heiken_Ashi.mq5 |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property version   "1.000"
/*
*/
int    handle_iCustom;              // variable for storing the handle of the iCustom indicator
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create handle of the indicator iCustom
handle_iCustom=iCustom(Symbol(),Period(),"Examples\\Heiken_Ashi");
//--- if the handle is not created
if(handle_iCustom==INVALID_HANDLE)
{
//--- tell about the failure and output the error code
PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",
Symbol(),
EnumToString(Period()),
GetLastError());
//--- the indicator is stopped early
return(INIT_FAILED);
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double heiken_ashi_open[],heiken_ashi_high[],heiken_ashi_low[],heiken_ashi_close[];
ArraySetAsSeries(heiken_ashi_open,true);
ArraySetAsSeries(heiken_ashi_high,true);
ArraySetAsSeries(heiken_ashi_low,true);
ArraySetAsSeries(heiken_ashi_close,true);
int start_pos=0,count=3;
if(!iGetArray(handle_iCustom,0,start_pos,count,heiken_ashi_open) ||
!iGetArray(handle_iCustom,1,start_pos,count,heiken_ashi_high) ||
!iGetArray(handle_iCustom,2,start_pos,count,heiken_ashi_low) ||
!iGetArray(handle_iCustom,3,start_pos,count,heiken_ashi_close))
{
return;
}
Comment(DoubleToString(heiken_ashi_open[0],Digits()),"\n",
DoubleToString(heiken_ashi_high[0],Digits()),"\n",
DoubleToString(heiken_ashi_low[0],Digits()),"\n",
DoubleToString(heiken_ashi_close[0],Digits()));
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
{
//---

}
//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
double iGetArray(const int handle,const int buffer,const int start_pos,
const int count,double &arr_buffer[])
{
bool result=true;
if(!ArrayIsDynamic(arr_buffer))
{
Print("This a no dynamic array!");
return(false);
}
ArrayFree(arr_buffer);
//--- reset error code
ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
if(copied!=count)
{
//--- if the copying fails, tell the error code
PrintFormat("Failed to copy data from the indicator, error code %d",GetLastError());
//--- quit with zero result - it means that the indicator is considered as not calculated
return(false);
}
return(result);
}
//+------------------------------------------------------------------+
```
Files:

Thank you very much, I will have a look at it.
Reason: