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

Notification

Icon
Error

Options
Go to last post Go to first unread
blackcat54  
#1 Posted : Wednesday, April 21, 2010 5:26:36 PM(UTC)
blackcat54

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/23/2010(UTC)
Posts: 60

Is using the "Previous" function discouraged for some reason?

I have been using it in some of my code and it works, but could it be responsible for slowing down the calculations?

Here is an example of a Long Stop Code:

PREV+.5*(Ref(Fml("+ag Smoothed Midpoint"),-1)-.5*Ref( Fml("+ag Average Daily Range"),-1)-2.85*Ref(Stdev(Fml("+ag Daily Range"),10),-1)-PREV).

Should I be looking for an alternative to using "Prev" in my code?

Thanks,

Dennis

wabbit  
#2 Posted : Wednesday, April 21, 2010 6:53:03 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
PREV is a recursive function, which by its very nature is slow. With modern computers and processors, the performance is markedly better now than it was ten years ago when using more than one PREV in an indicator used to bring the computer to almost a complete standstill.

Although I haven't tested this for a long time and if I remember the results correctly, you should try to avoid Fml(), FmlVar() and ExtFml() calls in variables containing PREV as this slows the recursive computation down even more so assign these values to a variable and then call them:

Code:

x0:=Ref(Fml("+ag Smoothed Midpoint"),-1);
x1:=.5*Ref( Fml("+ag Average Daily Range"),-1);
x2:=2.85*Ref(Stdev(Fml("+ag Daily Range"),10),-1);

PREV+.5*(x0-x1-x2-PREV)

[Edit: had + and - reversed!]

(If not faster, then it is easier to read!)

Do a search of the Forum as there have been many, many discussions on PREV and ways to eliminate them from a function.



wabbit [:D]

wabbit  
#3 Posted : Wednesday, April 21, 2010 7:50:39 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
...and then d'uh!

When you write the code in the easier to read fashion, something should have been obvious? Well, after a morning cup of coffee it became obvious [:)]

Ever seen this written in another way?

Code:

PREV+.5*(x0-x1-x2-PREV)


No? Then:
Code:

z:=x0-x1-x2;
PREV + 0.5*(z-PREV);


No? Another machination then:
Code:

z:=x0-x1-x2;
0.5*PREV + 0.5*z;


3 period EMA!

Code:

x0:=Ref(Fml("+ag Smoothed Midpoint"),-1);
x1:=0.5 * Ref(Fml("+ag Average Daily Range"),-1);
x2:=2.85 * Ref(Stdev(Fml("+ag Daily Range"),10),-1);

z:=x0-x1-x2;

Mov(z,3,E);



wabbit[:D]


blackcat54  
#4 Posted : Thursday, April 22, 2010 2:29:36 PM(UTC)
blackcat54

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/23/2010(UTC)
Posts: 60

If: Prev + .5*(z-Prev) = Mov(z,3,E)

Prev + x*(z-prev) = Mov(z,y,E)

What is the relationship between x and y?

Prev+ .3*(z-Prev)= Mov(z,y,E)

y = ?

blackcat54  
#5 Posted : Thursday, April 22, 2010 2:56:01 PM(UTC)
blackcat54

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/23/2010(UTC)
Posts: 60

blackcat54 wrote:

If: Prev + .5*(z-Prev) = Mov(z,3,E)

Prev + x*(z-prev) = Mov(z,y,E)

What is the relationship between x and y?

Prev+ .3*(z-Prev)= Mov(z,y,E)

y = ?

(edit) OK.... y = (2/x)-1 = (2/.3)-1 = 5

Users browsing this topic
Guest (Hidden)
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.