UpTwoBucks
Active member
This indicator measures the rate of change of a stock's price over a given period. It does this by calculating the difference between the current high price and the previous high price, as well as the difference between the previous low price and the current low price. It then takes the average of these differences over an 8-period time frame, and computes the ratio of the average high difference to the sum of the average high and average low differences, which is multiplied by 100 to give the final Line value. The resulting Line value is plotted on the chart and can be used as a technical indicator to help identify potential trend reversals or price breakouts. Works great when used with support and resistance lines.
Ruby:
#Works best on a 5 minute chart.
declare lower;
#This line creates a new variable high_diff which measures the difference between the current high price and the previous high price. The Max(0, ...) function ensures that high_diff is always positive or zero.
def high_diff = Max(0, high - high[1]);
#This line creates a new variable low_diff which measures the difference between the previous low price and the current low price. The Max(0, ...) function ensures that low_diff is always positive or zero.
def low_diff = Max(0, low[1] - low);
# This line creates a new variable high_avg which computes the 8-period simple moving average of high_diff.
def high_avg = Average(high_diff,8);
#This line creates a new variable low_avg which computes the 8-period simple moving average of low_diff.
def low_avg = Average(low_diff,8);
#This line creates a new plot called Line. The if statement checks if both high_avg and low_avg are zero, and sets the value of Line to 0 in this case. Otherwise, it computes the ratio of high_avg to the sum of high_avg and low_avg, multiplies by 100, and sets the result as the value of the Line.
plot Line = if high_avg == 0 && low_avg == 0 then 0 else high_avg / (high_avg + low_avg) * 100;
#This line sets the default color.
Line.SetDefaultColor(GetColor(9));
Last edited: