Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/19/2005(UTC) Posts: 2,995
Was thanked: 14 time(s) in 10 post(s)
|
I am trying to make my first custom exploration. I want to find the number of consecutive days that the close has been higher AND average the closing price for that number of days. I found this formula on the internet for the consecutive days and it seems to work (I placed this into ColA):
[code:1:5bfc627f86]If(C>Ref(C,-1) AND Ref(C,-1)>Ref(C,-2),PREV+1,
If(C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2),PREV-1,
If(C>Ref(C,-1) AND Ref(C,-1)<=Ref(C,-2),1,
If(C<Ref(C,-1) AND Ref(C,-1)>=Ref(C,-2),-1,
0))))[/code:1:5bfc627f86]
Now, I am stuck with the second part of my exploration. In ColB, I can set it manually like this: (Ref(C,-2)+Ref(C,-1)+C)/3, but it isn't dynamic. When I try to use sum(C,Variable)/Variable I get an error stating that a constant must be used.
Any help appreciated.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
Try
Variable:= ......;
Sum(C,Lastvalue(Variable-prev+prev))/Max(Variable,0.00001)
Patrick
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/19/2005(UTC) Posts: 2,995
Was thanked: 14 time(s) in 10 post(s)
|
Thanks Patrick!
That works great. I am getting a "self-referencing" warning, but the calculations are right on.
In the Max(Variable,0.00001) reference, where does the 0.00001 come from? I don't understand how it works.
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
Don't worry about the warning, it just tells you that it might be slow ...
The Max(Variable,0.0001) is to avoid division by zero errors.
The program might have bugged you about it, so what we tell it to do is use the biggest out of Variable or 0.000001 which will ( or should) always return the variable value and save you from annoying div by 0 error messages.
Patrick
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users Joined: 3/19/2005(UTC) Posts: 2,995
Was thanked: 14 time(s) in 10 post(s)
|
That's super! Thanks so much. :D
|
|
|
|
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.