The ROC (Rate of Change) indicator is a momentum oscillator used in technical analysis that measures the percentage change in price between the current price and the price a certain number of periods ago. The ROC indicator is primarily used to identify overbought or oversold conditions in a market, as well as to detect divergences which may indicate potential market reversals.
ROC[N](price)
This function calculates the Rate of Change for a given price over the last N periods. Here, N represents the number of periods over which the change is measured, and price specifies the price data (e.g., close, open, high, low) to be used.
ROC = ((price - price[N]) * 100) / price[N]
The ROC is calculated by taking the difference between the current price and the price N periods ago, dividing this difference by the price N periods ago, and then multiplying the result by 100 to express it as a percentage.
i1 = ROC[1](close)
i2 = ROC[1](close[1])
majorchange = i1 / i2
RETURN majorchange
In this example, i1 calculates the Rate of Change of the closing price from the previous period to the current period. i2 calculates the Rate of Change of the closing price from two periods ago to one period ago. The variable majorchange then finds the ratio of these two ROC values, which could be used to analyze acceleration in price changes.
This indicator is useful for traders looking to gauge the strength of a price trend and to anticipate potential points where the price trend may reverse.