- Topics: 29
- Replies: 1,474
- Posts: 1,503
The easiest way to do this is with a Stochastic function. Essentially what the Stochastic does is look back through a range and take note of the highest and lowest prices. Then it compares the current price and provides us with a percentage value. This is a great way to normalize values for comparison.
If I was doing this on a chart, I would add a Fast Stochastic tool, set the %K to 1000 bars and hide %D (turn off “visible” in “D Plot Style”). Remember that you can save this to your tool bar from the actions menu (running man on a right click). Then you can apply this visually to price or any other indicator.
If you wanted to limit the calculation to the last year, just set %K to 252 (on a daily chart).
To achieve the same thing in scripting just use this script
If I wanted it on another indicator, I would first put that result in a variable
V1 = ADX().ADX;
Here you can see where I have this in a watchlist and on a chart.
Hope that helps