Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 11/13/2020(UTC) Posts: 10
Was thanked: 3 time(s) in 3 post(s)
|
I want to use the variable period indicators available through the forum.dll. I want the period to be determined by my definition of a trend. So suppose I define a trend condition e.g. trend:= a > b; First thing I need is the number of times a trend was initiated: Code:init:= cum(trend = 1 AND ref(trend,-1) = 0);
Next thing I need are the total number of days where there was a trend:
Finally, the average number of days for a trend:
The problem is that before the first time there is a trend in the chart, init = 0 and I get an error for division with zero and thus I cannot calculate the average number of days that a trend lasts. Any ideas how to overcome this? In a regular programming language I could give init an initial value of 0.0000000001 but this is not possible in Metastock, or I don't know how to do it.
|
|
|
|
Rank: Advanced Member
Groups: Moderators, Registered, Registered Users, Subscribers Joined: 10/8/2010(UTC) Posts: 1,960
Thanks: 92 times Was thanked: 155 time(s) in 150 post(s)
|
Originally Posted by: Crossover521 I want to use the variable period indicators available through the forum.dll. I want the period to be determined by my definition of a trend. So suppose I define a trend condition e.g. trend:= a > b; First thing I need is the number of times a trend was initiated: Code:init:= cum(trend = 1 AND ref(trend,-1) = 0);
Next thing I need are the total number of days where there was a trend:
Finally, the average number of days for a trend:
The problem is that before the first time there is a trend in the chart, init = 0 and I get an error for division with zero and thus I cannot calculate the average number of days that a trend lasts. Any ideas how to overcome this? In a regular programming language I could give init an initial value of 0.0000000001 but this is not possible in Metastock, or I don't know how to do it.
Hello, You should be able to combine with an IF statement for that last line, such as: Code:avgtrend:= days / if(init=0, 0.00001, init);
|
|
|
|
Rank: Member
Groups: Registered, Registered Users, Subscribers Joined: 11/13/2020(UTC) Posts: 10
Was thanked: 3 time(s) in 3 post(s)
|
Can't believe it was that simple and I missed it. Thamk you !
|
|
|
|
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.