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
|
|
|
|
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]
|
|
|
|
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? 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]
|
|
|
|
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 = ?
|
|
|
|
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.