# Heikin Ashi Oscillator

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
NiC72
Posts: 92
Joined: 02 Nov 2009
Location: Sweden
Has thanked: 34 times
Been thanked: 12 times

### Heikin Ashi Oscillator

Hi,
I have some problem with Heikin Ashi Oscillator..
What is "Tema" and "haC" in easylanguage? it is not supported.
Here is the code:
----------------------------

Code: Select all

`inputs:Avg( 34 );variables:TMA1(0),TMA2(0),Diff(0),ZlHa(0),ZlCl(0),ZlDif(0) ;{CrossOver formula}    TMA1= Tema(haC,avg);    TMA2= Tema(TMA1,avg);    Diff= TMA1 - TMA2;    ZlHa= TMA1 + Diff;    TMA1= Tema((H+L)/2,avg);    TMA2= Tema(TMA1,avg);    Diff= TMA1 - TMA2;    ZlCl= TMA1 + Diff;    ZlDif=ZlCl-ZlHa;    Plot1( ZlDif,”ZlDif”);    Plot2(0,”Zero Line”);`

----------------------------

TJ
Posts: 6839
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 979 times
Been thanked: 1968 times
Hi,
I have some problem with Heikin Ashi Oscillator..
What is "Tema" and "haC" in easylanguage? it is not supported.
Here is the code:
----------------------------

What do you mean by "it is not supported"?
can you copy and paste the error message?

TEMA and HaC are functions; you need to add them with your PLEditor.

Code: Select all

`{Function: TEMA} INPUTS: PRICE(NumericSeries),LENGTH(NumericSimple); TEMA = (3 * XAVERAGE(PRICE,LENGTH)) - (3 * XAVERAGE(XAVERAGE(PRICE,LENGTH),LENGTH)) + (XAVERAGE(XAVERAGE(XAVERAGE(PRICE,LENGTH),LENGTH),LENGTH));`

Code: Select all

`// Function: haChaC = 0.25 * ( AvgPrice + haOpen + MaxList( High, haOpen )+ Minlist( Low, haOpen )) ;`

you will also need the following functions:

Code: Select all

`// function: AvgPricevariables: var0( 1 / 3 ) ;if Open <> 0 then    AvgPrice = ( Open + High + Low + Close ) * .25else    AvgPrice =  ( High + Low + Close ) * var0 ;`

Code: Select all

`// Function: haOpenhaOpen = 0.5 * ( AvgPrice + haOpen[1] );`

NiC72
Posts: 92
Joined: 02 Nov 2009
Location: Sweden
Has thanked: 34 times
Been thanked: 12 times

### Fixed now

Thanks TJ,

- What do you mean by "it is not supported"?
When I paste Heikin Ashi Oscillator code, "Tema" and "haC" was not a reserved word in easylanguage.

I added the functions as you said and it works great now

glen demarco
Posts: 35
Joined: 16 Nov 2009
Contact:
The Plot1 and Plot2 statements should be double quoted " " and not the tilde "~". Then I was able to compile it.

sts
Posts: 4
Joined: 12 Mar 2012
Has thanked: 3 times

### Re: Heikin Ashi Oscillator

I have long been using HACO - Heiken Ashi Oscillator (binary) in Metastock
And I found the Multicharts alternative for that oscillator in this page:

But I can't make this indicator plot the "binary wave" as the one you can see
in the screen shot given in the code page.
Can you help me sort this out please?
Attachments
The binary at the bottom of this chart?
ttfig1.gif (43.41 KiB) Viewed 1341 times

Posts: 669
Joined: 09 Apr 2010
Has thanked: 435 times
Been thanked: 248 times
Contact:

### Re: Heikin Ashi Oscillator

With a few minor changes you can get the same binary output- try this:

Code: Select all

`inputs:Avg( 34 );variables:TMA1(0),TMA2(0),Diff(0),ZlHa(0),ZlCl(0),ZlDif(0),dir(0);{add this}{CrossOver formula}    TMA1= Tema(haC,avg);    TMA2= Tema(TMA1,avg);    Diff= TMA1 - TMA2;    ZlHa= TMA1 + Diff;    TMA1= Tema((H+L)/2,avg);    TMA2= Tema(TMA1,avg);    Diff= TMA1 - TMA2;    ZlCl= TMA1 + Diff;    ZlDif=ZlCl-ZlHa;    dir = iff(Zldif > 0,1,-1);{add this} Plot1(dir,"ZlDif");{add this} Plot2(0,"Zero Line");`

sts
Posts: 4
Joined: 12 Mar 2012
Has thanked: 3 times

### Re: Heikin Ashi Oscillator

But actually the crossover formula is simply the starting point for the HACO-binary:

Code: Select all

`[b] { Crossover formula for trend determination }[/b][i]TMA1 = TEMA( HaCValue, TEMALength ) ;TMA2 = TEMA( TMA1, TEMALength ) ;TMADiff = TMA1 - TMA2 ;ZlHa = TMA1 + TMADiff ;TMA1 = TEMA( MedianPrice, TEMALength ) ;TMA2= TEMA( TMA1, TEMALength ) ;TMADiff = TMA1 - TMA2 ; ZlCl = TMA1 + TMADiff ;ZlDiff = ZlCl - ZlHa ;[/i]`

After that point these next calculations are done:

Code: Select all

`[b]{basic Heikin-Ashi condition }[/b]HABasic = HaCValue >= HaOpenValue ; [b]{trend determination }[/b]Z1DiffPos = ZlDiff >= 0 ;[b]{don't let a Doji reverse an uptrend }[/b]NoDojiReverse = ( AbsValue( Close - Open ) < ( High - Low ) * 0.35 and High >= Low[1] ) and ( HABasic or DiffAndLastBasic or UpSigns ) ;[b]{ if prior bar was Green, then make this one green too }[/b]DiffAndLastBasic = Z1DiffPos and HABasic[1] ; [b]{ make one more green if "upwards signs" exist }[/b]UpSigns = ( ( HABasic[2] and DiffAndLastBasic[1] ) or UpSigns[1] ) and ( Close >= Open or Close >= Close[1] ) ;GreenBar = HABasic or DiffAndLastBasic or UpSigns or NoDojiReverse ;if GreenBar then   begin   ColorW = UpTrendColor ;   if ( Close > Close[1] and Open < Close ) or    ( Close < Close[1] and Open > Close ) then      Color = UpTrendColor    else      Color = HollowColor ;   endelse    begin   ColorW = DnTrendColor ;   if Close < Close[1] then      begin       if Open > Close then         Color = DnTrendColor       else         Color = HollowColor ;      end   else if  Close > Close[1] then       begin      if Open < Close then         Color = HollowColor       else         Color = DnTrendColor ;      end ;   end ;`

After all these a FILTERED binary wave is plot as HACO. Actually the Metastock code is almost similar but the main difference is that there is no HallowColor inn that code.Instead, the very same code that calculates the GreenBar (uptrend) is used in the opposite manner to find out the RedBar (downtrend) and then this final decision lines are run:

Code: Select all

`upw:=dtr=0 AND Ref(dtr,-1) AND utr;dnw:=utr=0 AND Ref(utr,-1) AND dtr;result:=If(upw,1,If(dnw,0,PREV));result`

I can translate it in a straight forward manner like this:

Code: Select all

`upw= There is an UPtrend if the previous bar was a RedBar but it changed to a GreenBardwn= There is a DownTrend if the previous bar was a GreenBar but it changed to a RedBarResult=  If this is a GreenBar then plot 1 else if this is a RedBar Plot 0 else plot Result[1]Plot(result)`

I have taken all these steps but the resulting indicator's value doesn't change even the selected period is changed? So I quit trying and started looking for a ready to use code...

Posts: 669
Joined: 09 Apr 2010