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: