Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 3/13/2018(UTC) Posts: 40
Thanks: 7 times Was thanked: 9 time(s) in 9 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;
|