logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
chrisdr22  
#1 Posted : Tuesday, June 5, 2018 8:28:22 AM(UTC)
chrisdr22

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/13/2018(UTC)
Posts: 13

Thanks: 3 times
Was thanked: 4 time(s) in 4 post(s)

Hi,

I found a Heikin-Ashi indicator on this web-site: http://trader-online.tk/MSZ/e-w-Heikin-Ashi_Candlestick_Oscillator.html

I cut and pasted the formula into the Indicator Builder and it works as expected - the result is either 1 or zero, and plots a binary square wave.  Now I want to create an expert to plot buy and sell symbols, but I only want to plot the symbols on a transition: ie 0->1 = buy symbol, 1->0 = sell symbol.

The below code (buy symbol), slightly adapted from the web-site, displays the buy symbol when the result is 1, but it displays a buy symbol for every bar that equals 1.  How can I adapt the code to get the value of the previous bar to do a comparison for a transition 0->1?

Thanks

Christopher

Code:
{HACO Sylvain Vervoort}
avg:={Input("Up TEMA average: ",1,100,34);} 34;
avgdn:={Input("Down TEMA Average: ",1,100,34);} 34;
haOpen:=(Ref((O+H+L+C)/4,-1) + PREV)/2;
haC:=((O+H+L+C)/4+haOpen+Max(H,haOpen)+Min(L,haOpen))/4;
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;
keep1:=Alert(haC>=haOpen,2);
keep2:=ZlDif>=0;
keeping:=(keep1 OR keep2);
keepall:=keeping OR (Ref(keeping,-1) AND (C>=O) OR C>=Ref(C,-1));
keep3:=(Abs(C-O)<(H-L)*.35 AND H>=Ref(L,-1));
utr:=Keepall OR (Ref(keepall,-1) AND keep3);
TMA1:= Tema(haC,avgdn);
TMA2:= Tema(TMA1,avgdn);
Diff:= TMA1 - TMA2;
ZlHa:= TMA1 + Diff;
TMA1:= Tema((H+L)/2,avgdn);
TMA2:= Tema(TMA1,avgdn);
Diff:= TMA1 - TMA2;
ZlCl:= TMA1 + Diff;
ZlDif:=ZlCl-ZlHa;
keep1:=Alert(haC<haOpen,2);
keep2:=ZlDif<0;
keep3:=Abs(C-O)<(H-L)*.35 AND L<=Ref(H,-1);
keeping:=keep1 OR keep2;
keepall:=keeping OR (Ref(keeping,-1) AND (C<O) OR C<Ref(C,-1));
dtr:=If(Keepall OR (Ref(keepall,-1) AND keep3)=1,1,0);
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 = 1;

chrisdr22  
#2 Posted : Tuesday, June 5, 2018 9:01:49 AM(UTC)
chrisdr22

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/13/2018(UTC)
Posts: 13

Thanks: 3 times
Was thanked: 4 time(s) in 4 post(s)

Ok, got it working - changed the last line to : result = 1 AND Ref(result, -1) = 0;

MS Support  
#3 Posted : Tuesday, June 5, 2018 2:39:47 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,420

Thanks: 35 times
Was thanked: 110 time(s) in 106 post(s)

The cross() function can also be useful here:

Code:
Cross(Result,0) OR Cross(0,Result)

chrisdr22  
#4 Posted : Wednesday, June 6, 2018 4:40:55 AM(UTC)
chrisdr22

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/13/2018(UTC)
Posts: 13

Thanks: 3 times
Was thanked: 4 time(s) in 4 post(s)

Thanks for the tip!  Out of interest, is this more efficient than using Ref?

MS Support  
#5 Posted : Wednesday, June 6, 2018 3:07:48 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,420

Thanks: 35 times
Was thanked: 110 time(s) in 106 post(s)
As far as resource usage, not that I am aware of but it might be slightly more efficient in scenarios where it would allow you to shorten the overall code length.
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.