Rank: Newbie
Groups: Registered, Registered Users, Subscribers Joined: 7/26/2009(UTC) Posts: 7
|
I've been looking at the following code and it brought up this question: Is Stop1 presumed to be zero right off the bat, or do I have to call out Stop1:=0?
Stop1:=If( PREV < L, {then} If(( H - 3*ATR(10) ) >= PREV, {then} ( H - 3*ATR(10) ), {else} PREV), {else (L <= PREV)} ( H - 3*ATR(10) ));
Thanks
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 7/25/2005(UTC) Posts: 1,042
Was thanked: 57 time(s) in 54 post(s)
|
Yes, an initial PREV value of zero is assumed. You can’t predefine a variable with PREV in it but what works in some situations is that the variable can be “seeded” on the first bar from within – see the following exponential moving average formula as an example of this.
{Exponential Moving Average}
Pds:=Input("Periods",1,1000,10);
Rate:=2/(Min(Cum(1),Pds)+1);
If(Cum(1)=0,C,PREV*(1-Rate)+C*Rate);
Your formula can be reduced to just two PREVs as follows.
X:=H-3*ATR(10);
If(PREV<L,Max(X,PREV),X);
In some cases a PREV-based variable can be rewritten to remove PREV altogether, although I don’t think it’s possible with your example.
Roy
|
|
|
|
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.