Take a look at the bit of code preceding the snippet you posted.
ArraySetAsSeries(ExtLowHighBuffer,false);
ArraySetAsSeries(ExtHighLowBuffer,false);
ArraySetAsSeries(ExtOpenBuffer,false);
ArraySetAsSeries(ExtCloseBuffer,false);
ArraySetAsSeries(open,false);
ArraySetAsSeries(high,false);
ArraySetAsSeries(low,false);
ArraySetAsSeries(close,false);
ArraySetAsSeries(ExtHighLowBuffer,false);
ArraySetAsSeries(ExtOpenBuffer,false);
ArraySetAsSeries(ExtCloseBuffer,false);
ArraySetAsSeries(open,false);
ArraySetAsSeries(high,false);
ArraySetAsSeries(low,false);
ArraySetAsSeries(close,false);
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
The Heikin-Ashi technique uses a modified formula:
o Average price of the current bar
o Midpoint of the previous bar
o Highest value in the set
o Lowest value in the set
Shouldn't the highlighted line have i+1 for the HA calculation
//--- preliminary calculation
if(prev_calculated>1)
pos=prev_calculated-1;
else
{
//--- set first candle
if(open[0]<close[0])
{
ExtLowHighBuffer[0]=low[0];
ExtHighLowBuffer[0]=high[0];
}
else
{
ExtLowHighBuffer[0]=high[0];
ExtHighLowBuffer[0]=low[0];
}
ExtOpenBuffer[0]=open[0];
ExtCloseBuffer[0]=close[0];
//---
pos=1;
}
//--- main loop of calculations
for(i=pos; i<rates_total; i++)
{
haOpen=(ExtOpenBuffer[i-1]+ExtCloseBuffer[i-1])/2;
haClose=(open[i]+high[i]+low[i]+close[i])/4;
haHigh=MathMax(high[i],MathMax(haOpen,haClose));
haLow=MathMin(low[i],MathMin(haOpen,haClose));
if(haOpen<haClose)
{
ExtLowHighBuffer[i]=haLow;
ExtHighLowBuffer[i]=haHigh;
}
else
{
ExtLowHighBuffer[i]=haHigh;
ExtHighLowBuffer[i]=haLow;
}
ExtOpenBuffer[i]=haOpen;
ExtCloseBuffer[i]=haClose;
}
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+