# Relative Price Oscillator for ThinkorSwim

#### BenTen

Staff member
Staff
VIP
Here is a new experimental indicator we've been working on. The idea was to compare two EMA's of period midpoints to the actual closing price. The steps that were taken are listed below:
1. Calculate an EMA based on each period's midpoint ((High * Low) /2) for the last 9 periods.
2. Calculate an EMA based on each period's midpoint for the last 100 periods.
3. Divide the difference of the two EMA's by the closing price. ((EMA1 - EMA2) / Close).
4. Smooth the value from step #3 with an 18 period EMA . Multiply by 1000 for better scaling/visibility.
Using:
• Bullish when line is green, bearish when line is red. Buy on first green, then sell on first red.

### thinkScript Code

Code:
``````#
# RelativePriceOscillator (RPO)
# Assembled by Kory Gill (@korygill) for BenTen at useThinkScript.com
#

declare lower;
declare once_per_bar;

input lenFast = 9; #Hint lenFast: Length of Fast EMA
input lenSlow = 100; #Hint lenSlow: Length of Slow EMA
input lenSmooth = 18; #Hint lenFast: Length of Smoothing EMA
input ColorCandles = no; #Hint ColorCancles: Color cancles based on RPO color
def vHL2 = hl2;
def vClose = close;

def fast = MovingAverage(AverageType.EXPONENTIAL, vHL2, lenFast);
def slow = MovingAverage(AverageType.EXPONENTIAL, vHL2, lenSlow);
def diff = (fast - slow) / vClose;
def smoothedDiff = MovingAverage(AverageType.EXPONENTIAL, diff, lenSmooth);
def bullish = smoothedDiff >= smoothedDiff[1];

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.YELLOW);

plot RPO = smoothedDiff;
RPO.AssignValueColor(if bullish then Color.GREEN else Color.RED);

AssignPriceColor(if ColorCandles then RPO.TakeValueColor() else Color.CURRENT);

# END - RelativePriceOscillator (RPO)``````

@BenTen Does this work on lower time frames also

@BenTen Does this work on lower time frames also

@Billions - if you are going to use for lower time frames I would add a super smoother to it. Then subtract the indicator from the super smoother and use the difference to confirm your entries. I would not use as a stand alone.

As an example - you could use SLIM Ribbon, Absolute Strength and some type of price moving average to begin your testing with. I have found mid-point moving averages work well as the price MA.

Last edited:
Great thanks Ill try that

87k+ Posts
371 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?