Error

 Previous Topic Next Topic
 chrisdr22 #1 Posted : Tuesday, June 5, 2018 8:28:22 AM(UTC) Rank: Advanced MemberGroups: Registered, Registered Users, SubscribersJoined: 3/13/2018(UTC)Posts: 34Thanks: 7 timesWas thanked: 7 time(s) in 7 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
 Wanna join the discussion?! Login to your Discussions forum accountor Register a new forum account.
 chrisdr22 #2 Posted : Tuesday, June 5, 2018 9:01:49 AM(UTC) Rank: Advanced MemberGroups: Registered, Registered Users, SubscribersJoined: 3/13/2018(UTC)Posts: 34Thanks: 7 timesWas thanked: 7 time(s) in 7 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) Rank: Advanced MemberGroups: Moderators, Registered, Registered Users, SubscribersJoined: 10/8/2010(UTC)Posts: 1,508Thanks: 44 timesWas thanked: 119 time(s) in 115 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) Rank: Advanced MemberGroups: Registered, Registered Users, SubscribersJoined: 3/13/2018(UTC)Posts: 34Thanks: 7 timesWas thanked: 7 time(s) in 7 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) Rank: Advanced MemberGroups: Moderators, Registered, Registered Users, SubscribersJoined: 10/8/2010(UTC)Posts: 1,508Thanks: 44 timesWas thanked: 119 time(s) in 115 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.