Posted 1/8/2010 23:50:00
|
|
|
|
I have an indicator that shows me the trend of the underlying stock which works as expected but I want to do some analysis on it and I am stuck on how to do it.
It has readings for the trend strength and when it goes above zero I want to find out on average how many days it stays above 0.
So on one stock over its life it can go above 0 for x days and then fall back below 0. Each stock may have any number of periods above 0 so I need a way to count the number of bars in each period above 0 and then calculate the average number of bars > 0 for each stock.
At the moment I have a user series that shows 1 if > 0 and 0 if <0 but what would be a good way to loop through each section and calculate the average period > 0?
Any ideas?
Thanks.
|
|
Posted 1/10/2010 01:45:55
|
|
|
|
Do you want there to be any limit on how far back the "average number of bars above zero" value looks back? Should it use all the data it has, or should it go back a certain number of bars, or a certain number of periods that the value was above zero?
I would declare an integer class variable in your symbol script. On a new bar, when the trend strength is greater than zero, add one to this variable. If the trend strength is less than zero, and the variable value is greater than zero, then add the variable value to a list of numbers to use for your average, and then reset the variable to zero.
Daniel
|
|
|
|