The code is quite simple but I can't manage to make it work on NT8. The indicator is a price oscillator with breakout lines:
# --- Price Oscillator w/ breakout lines 10/31/2018 ----
declare lower;
input price = hl2;
input HistoType = {default STD};
input SmoothLength = 5;
def valueDiff;
def value;
def showBands;
switch (HistoType) {
case STD:
value = Double.NaN;
valueDiff = 100 * (ExpAverage(price, 5) - ExpAverage(price, 9)) / ExpAverage(price, 9);
showBands = 1;
}
#------------BREAKOUT LINES-----------------------------
def coeff_num = 2;
def coeff_denom = 40;
def barNum = if IsNaN( close ) then Double.NaN else BarNumber();
def coeff = coeff_num / ( coeff_denom );
rec _upLine = if barNum == 1 then
if Valuediff >= 0 then
Valuediff * coeff + Valuediff * ( 1 - coeff )
else
0
else
if Valuediff >= 0 then
Valuediff * coeff + _upLine[1] * ( 1 - coeff )
else
_upLine[1];
rec _dnLine = if barNum == 1 then
if Valuediff < 0 then
Valuediff * coeff + Valuediff * ( 1 - coeff )
else
0
else
if Valuediff < 0 then
Valuediff * coeff + _dnLine[1] * ( 1 - coeff )
else
_dnLine[1];
plot UpLine = if showBands then _upLine else Double.NaN;
plot DownLine = if showBands then _dnLine else Double.NaN;
UpLine.SetDefaultColor(GetColor(9));
UpLine.SetLineWeight(1);
DownLine.SetDefaultColor(GetColor(9));
DownLine.SetLineWeight(1);
#---------------------PLOTS------------------------------
plot Osc = valueDiff;
Osc.SetDefaultColor(GetColor(5));
Osc.SetPaintingStrategy(PaintingStrategy.HISTOGRAM );
Osc.SetLineWeight(3);
Osc.DefineColor("Positive and Up", Color.GREEN);
Osc.DefineColor("Positive and Down", Color.DARK_GREEN);
Osc.DefineColor("Negative and Down", Color.RED);
Osc.DefineColor("Negative and Up", Color.DARK_RED);
Osc.AssignValueColor(if Osc > 0 then if Osc >= UpLine then Osc.Color("Positive and Up") else Osc.Color("Positive and Down") else if Osc <= DownLine then Osc.Color("Negative and Down") else Osc.Color("Negative and Up"));
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(7));
---------------------------------------------------------------END----------------------------------------------------------------------------------------------------------------------------------------------
Thanks!

Comment