Premium & Discount Oscillator for ThinkOrSwim

samer800

Conversion Expert
VIP
Lifetime
uWQrMAt.png


Author Message:
This oscillator allows the user to see objectively if the price is in his fair value, his premium pricing, or his discount pricing.
This indicator comprehends 2 different lines, one that is based on the Williams % oscillator, and the other one that has a unique formula calculated using different parameters and normalizing them.
The first line can be chosen to use volume in the calculation or not.

CODE :
CSS:
#// © TommasoRossini
#indicator("Premium & Discount Oscillator", "Zone Calculator")
# converted and mod by Sam4Cok@Samer800 - 02/2023
declare lower;
input BarColor = yes;
input ShowHistogram = yes;
input IncludeVolume = no;        # "Include volume"
input Length = 50;               # "Lenght"
input LevelsHightPercent = 25;   # "Levels hight percent"

def na = Double.NaN;
def last = isNaN(close[1]);
def plevel1 = 100 - LevelsHightPercent;
def dlevel = LevelsHightPercent - 50;
def plevel = plevel1 - 50;

def accdist = (2 * close - high - low) / ((high - low) * volume);
def obv =  TotalSum(Sign(close - close[1]) * volume);
def accdistHull = HullMovingAvg(accdist, Length);
def obvHull     = HullMovingAvg(obv, Length);

def closeHull =  HullMovingAvg(close, Length);
def hl2Hull   =  HullMovingAvg(hl2, Length);

def out1 = (accdist + obvHull + accdistHull) / 3;
def out2 = (close +  closeHull + hl2Hull) / 3;

def out3 = if IncludeVolume then out1 else
           if !IncludeVolume then out2 else out3[1];
def out4 = RSI(PRICE = out3, LENGTH = Length);

def out5 = (out3 - Lowest(out3, Length)) / (Highest(out3, Length) - Lowest(out3, Length)) * 100;
def out6 = (out5 + out4) / 2;
def out7 = 100 + (WilliamsPercentR(LENGTH = Length));
def out8 = HullMovingAvg(out7, (Length / 3));

plot LevelLine = out6 - 50;    # "Level line"
LevelLine.SetLineWeight(2);
LevelLine.AssignValueColor(CreateColor(out6*2.55,255-out6*2.55,0));
plot SecondLine = if !ShowHistogram then na else out8 - 50;   # "Second line"
SecondLine.SetLineWeight(3);
SecondLine.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SecondLine.AssignValueColor(if SecondLine > 0 then
                            if SecondLine > SecondLine[1] then Color.GRAY else Color.DARK_GRAY else
                            if SecondLine < SecondLine[1] then Color.GRAY else Color.DARK_GRAY);
def p111 = if last then na else -50;
def p112 = dlevel;
def p113 = plevel;
def p114 = if last then na else 50;
plot ZeroLie = if last then na else 0;
ZeroLie.SetDefaultColor(Color.DARK_GRAY);

plot UpPoint = if (LevelLine < p112) then LevelLine else na;
UpPoint.SetPaintingStrategy(PaintingStrategy.POINTS);
UpPoint.SetDefaultColor(Color.GREEN);

plot DnPoint = if (LevelLine > p113) then LevelLine else na;
DnPoint.SetPaintingStrategy(PaintingStrategy.POINTS);
DnPoint.SetDefaultColor(Color.RED);


AddCloud(p112, p111, CreateColor(0,47,178), CreateColor(0,47,178), ShowHistogram);        # "Discount area"
AddCloud(p114, p113, CreateColor(186,18,75), CreateColor(186,18,75), ShowHistogram);      # "Premum area"
#AddCloud(p113, p112, Color.DARK_GRAY);              # "Neutral area"

AssignPriceColor(if !BarColor then Color.CURRENT else  CreateColor(255-out6*2.55,out6*2.55, 0));
#---- END CODE
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
466 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

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?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top