♥ 0 |
Hi Pete, Is there a universal way to use the same verbiage looking only for the current day with any script? If not, could you please help me again so that I don’t have to use the lookback? Thanks again! input lookback = 13; def pctGain = ((close – close[1]) / close[1]) * 100;
Marked as spam
|
Private answer
It seems you are referring to a previous solution: https://www.hahn-tech.com/ans/count-green-bars-only-current-day/ So please make sure to include a link for context. There are thousands of pairs of eyeballs viewing your thread. Let's make it easier for them to follow along. The answer to your question is yes. There is a "universal" way to capture this data for only the current day and not require the use of the lookback period. That universal way is called recursion. You can Google that if you want to learn what that means. However in this particular case we have a problem. That lookback period is being used to compute an average. What exactly did you have in mind here? The behavior of this code is going to change if we remove that lookback period and replace it with something else. Right now the code computes the 13 period simple moving average of the percent change from one bar's close to the next. So what does it look like when we take that out and replace it with only the current day's values? In case it's not obvious, I will explain. On bar one of current day, there is no percent difference from the previous bar, because there is no previous bar. So the computed value for the first bar of the day is zero. Let's move on the bar number two for the current day. Now we have a value to compute. Since we are on bar number 2 we can take that result and divide by 2. What happens on bar number 3? We have two values to compute, we add them together and then divide by 3. For each new bar on the chart for the current day the average we compute changes. (the values become diluted over time) In summary, how do you propose we modify the behavior without destroying the way your average percent change is being computed? Marked as spam
|
Please log in to post questions.