I think I might have all the details required to get this working. From the comments section above we have the following specifications:
- Compute the net change from one day to the next, subtracting the current daily close from the previous.
- For each bar where this difference is greater than +1.00 count that bar as a one
- For each bar where this difference is less than -1.00 count that bar as minus one
- Compute the sum total over 21 days for each value and display each in a separate column
There are 21 days of trading data in the average month. So for one month of computations we set the numberOfDays input to 21. There is also a user input to adjust the priceThreshold, the default value is set to 1.0.
The code to perform the base computations is here:
input priceThreshold = 1.0;
input numberOfDays = 10;
def dailyChange = close - close[1];
To that, we add the following line to count the $1 gains in that time span:
plot countGain = Sum(dailyChange > priceThreshold, numberOfDays);
And for the other column that displaces the $1 declines we add the following:
plot countDecline = Sum(dailyChange < -priceThreshold, numberOfDays);
You can only use one of those plot statements for a given column. So make sure to apply the correct line to the bottom for each column. Each custom column must be set to the daily time frame. However you can apply this to a different time frame if you wanted to compute these values for another time frame. The code simply counts bars so the time frame if flexible.
In the comments section we are told that for the previous month the ticker symbol AAPL should display a $1 gain count of 8 and a $1 decline count of 3. However when we build the code according the above specifications we find the computed values are 8 and 7.
Screenshot below shows the results. I have included a lower study on the chart to show exactly when the $1 gain (blue line) and when a $1 decline (red line) is recorded for each bar on the chart within the last month.