you may find full details on the indicator below.
https://alpaca.markets/learn/andean...ed-on-an-online-algorithm-for-trend-analysis/
TV original code
https://www.tradingview.com/script/x9qYvBYN-Andean-Oscillator/
CSS:
#https://alpaca.markets/learn/andean-oscillator-a-new-technical-indicator-based-on-an-online-algorithm-for-trend-analysis/
#https://www.tradingview.com/script/x9qYvBYN-Andean-Oscillator/
#/indicator("Andean Oscillator")
# Converted and mod by Sam4Cok@Samer800 - 07/2022
declare lower;
#//Settings
input length = 50;
input sig_length = 9; #'Signal Length')
input ShowCloud = yes;
input BullBearLines = yes;
input SignalLine = yes;
input showHist = yes;
########## Colors ########
DefineGlobalColor("Sky1" , CreateColor(0, 221, 255));
DefineGlobalColor("Sky2" , CreateColor(4, 188, 217));
DefineGlobalColor("Sky4" , CreateColor(4, 127, 145));
DefineGlobalColor("Sky5" , CreateColor(4, 103, 117));
DefineGlobalColor("Magenta1" , CreateColor(216, 0, 255));
DefineGlobalColor("Magenta2" , CreateColor(187, 4, 219));
DefineGlobalColor("Magenta4" , CreateColor(123, 3, 143));
DefineGlobalColor("Magenta5" , CreateColor(100, 2, 117));
DefineGlobalColor("Blue" , CreateColor(17, 118, 242));
DefineGlobalColor("Lime" , CreateColor(1, 255, 0));
############
script nz {
input data = 1;
input repl = 0;
def ret_val = if IsNaN(data) then repl else data;
plot return = ret_val;
}
def na = Double.NaN;
#//Exponential Envelopes
def alpha = 2 / (length + 1);
def C = close;
def O = open;
def up1 = nz(Max(Max(C, O) , Max(up1[1] - (up1[1] - C) * alpha, C)));
def up2 = nz(Max(Max(C * C, O * O), Max(up2[1] - (up2[1] - C * C) * alpha, C * C)));
def dn1 = nz(Min(Min(C, O) , Min(dn1[1] + (C - dn1[1]) * alpha, C)));
def dn2 = nz(Min(Min(C * C, O * O), Min(dn2[1] + (C * C - dn2[1]) * alpha, C * C)));
#//Components
def bull = Sqrt(dn2 - dn1 * dn1);
def bear = Sqrt(up2 - up1 * up1);
def signal = ExpAverage(Max(bull, bear), sig_length);
def ExUp = bull > bear and bull > signal and bull > bull[1];
def ExUp1 = bull > bear and bull > signal and bull < bull[1];
def Up = bull > bear and bull < signal and bull > bull[1];
def Up11 = bull > bear and bull < signal and bull < bull[1];
def ExDn = bear > bull and bear > signal and bear > bear[1];
def ExDn1 = bear > bull and bear > signal and bear < bear[1];
def Dn = bear > bull and bear < signal and bear > bear[1];
def Dn11 = bear > bull and bear < signal and bear < bear[1];
#//Plots
plot bullLine = if BullBearLines then bull else na; #'Bullish Component'
bullLine.SetDefaultColor(GlobalColor("Lime"));
bullLine.SetLineWeight(2);
bullLine.HideTitle();
plot bearLine = if BullBearLines then bear else na; #'Bearish Component'
bearLine.SetDefaultColor(GlobalColor("Blue"));
bearLine.SetLineWeight(2);
bearLine.HideTitle();
plot SigLine = if SignalLine then signal else na;#'Signal'
SigLine.AssignValueColor(if ExUp then GlobalColor("Sky1") else
if ExUp1 then GlobalColor("Sky2") else
if up then GlobalColor("Sky4") else
if up11 then GlobalColor("Sky5") else
if ExDn then GlobalColor("Magenta1") else
if ExDn1 then GlobalColor("Magenta2") else
if Dn then GlobalColor("Magenta4") else
if Dn11 then GlobalColor("Magenta5") else color.GRAY);
SigLine.SetLineWeight(3);
SigLine.HideTitle();
plot SigHist = if ShowHist then signal else na;#'Signal'
SigHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
SigHist.SetLineWeight(2);
SigHist.AssignValueColor(if ExUp then GlobalColor("Sky1") else
if ExUp1 then GlobalColor("Sky2") else
if up then GlobalColor("Sky4") else
if up11 then GlobalColor("Sky5") else
if ExDn then GlobalColor("Magenta1") else
if ExDn1 then GlobalColor("Magenta2") else
if Dn then GlobalColor("Magenta4") else
if Dn11 then GlobalColor("Magenta5") else color.GRAY);
AddCloud(if ShowCloud then bullLine else na, bearLine, Color.DARK_GREEN, Color.DARK_RED);
#//----END----------------------------------------
New update ----
converted it to Andean-MACD ..
CODE:
CSS:
#https://alpaca.markets/learn/andean-oscillator-a-new-technical-indicator-based-on-an-online-algorithm-for-trend-analysis/
#https://www.tradingview.com/script/x9qYvBYN-Andean-Oscillator/
#/indicator("Andean Oscillator")
# Converted and mod by Sam4Cok@Samer800 - 07/2022.
# V1.5 included Histogram option, label, Background & bug fix. 08/2022.
declare lower;
#//Settings
input label = Yes;
input length = 50;
input sig_length = 9; #'Signal Length')
input ShowCloud = yes;
input showHist = yes;
########## Colors ########
DefineGlobalColor("Green1" , CreateColor(1, 255, 0));
DefineGlobalColor("Green2" , CreateColor(4, 181, 4));
DefineGlobalColor("Green3" , CreateColor(3, 145, 3));
DefineGlobalColor("Green4" , CreateColor(2, 117, 2));
DefineGlobalColor("Red1" , CreateColor(255, 5, 5));
DefineGlobalColor("Red2" , CreateColor(184, 6, 6));
DefineGlobalColor("Red3" , CreateColor(145, 3, 3));
DefineGlobalColor("Red4" , CreateColor(117, 2, 2));
############
script nz {
input data = Close;
input repl = 0;
def ret_val = if IsNaN(data) then repl else data;
plot return = ret_val;
}
def na = Double.NaN;
#//Exponential Envelopes
def alpha = 2 / (length + 1);
def up1;
def up2;
def dn1;
def dn2;
up1 = if isNaN(up1[1]) then 0 else nz(Max(Max(close, open), up1[1] - (up1[1] - close) * alpha), close);
up2 = if isNaN(up2[1]) then 0 else nz(Max(Max(Sqr(close), Sqr(open)), up2[1] - (up2[1] - Sqr(close)) * alpha), Sqr(Close));
dn1 = if isNaN(dn1[1]) then 0 else nz(Min(Min(close, open), dn1[1] + (close - dn1[1]) * alpha), close);
dn2 = if isNaN(dn2[1]) then 0 else nz(Min(Min(Sqr(close), Sqr(open)), dn2[1] + (Sqr(close) - dn2[1]) * alpha), Sqr(close));
#//Components
def bull = Sqrt(dn2 - dn1 * dn1);
def bear = Sqrt(up2 - up1 * up1);
def Signal = ExpAverage(Max(bull, bear), sig_length);
def sigBull = ExpAverage(bull, sig_length);
def sigBear = ExpAverage(bear, sig_length);
def differ = sigBull - sigBear;
def ExUp = bull > bear and bull > Signal and differ > differ[1] and differ >= 0;
def ExUp1 = bull > bear and bull > Signal and differ < differ[1] and differ >= 0;
def Up = bull > bear and bull < Signal and differ > differ[1] and differ >= 0;
def Up11 = bull > bear and bull < Signal and differ < differ[1] and differ >= 0;
def ExDn = bear > bull and bear > Signal and differ < differ[1] and differ < 0;
def ExDn1 = bear > bull and bear > Signal and differ > differ[1] and differ < 0;
def Dn = bear > bull and bear < Signal and differ < differ[1] and differ < 0;
def Dn11 = bear > bull and bear < Signal and differ > differ[1] and differ < 0;
#//Plots
plot SigLine = Signal;#'Signal'
SigLine.SetHiding(showHist);
SigLine.SetDefaultColor(Color.YELLOW);
plot bullLine = bull; #'Bullish Component'
bullLine.SetDefaultColor(Color.GREEN);
bullLine.SetLineWeight(2);
bullLine.SetHiding(showHist);
bullLine.HideTitle();
plot bearLine = bear; #'Bearish Component'
bearLine.SetDefaultColor(Color.RED);
bearLine.SetLineWeight(2);
bearLine.SetHiding(showHist);
bearLine.HideTitle();
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);
ZeroLine.SetHiding(!showHist);
plot diff = differ;
diff.SetDefaultColor(GetColor(5));
diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
diff.SetLineWeight(3);
diff.SetHiding(!showHist);
diff.AssignValueColor(if ExUp then GlobalColor("Green1") else
if ExUp1 then GlobalColor("Green2") else
if Up then GlobalColor("Green3") else
if Up11 then GlobalColor("Green4") else
if ExDn then GlobalColor("Red1") else
if ExDn1 then GlobalColor("Red2") else
if Dn then GlobalColor("Red3") else
if Dn11 then GlobalColor("Red4") else CreateColor(255, 241, 118));
plot diffLine = differ;
diffLine.SetHiding(!showHist);
diffLine.AssignValueColor( if diff >= 0 then GlobalColor("Green1") else
GlobalColor("Red1"));
AddCloud(if ShowCloud and !showHist then bull else na, bear , Color.DARK_GREEN, Color.DARK_RED);
AddCloud(if ShowCloud and !showHist then bear else na, Signal, Color.RED, Color.DARK_GREEN);
AddCloud(if ShowCloud and !showHist then bull else na, Signal, Color.GREEN, Color.DARK_RED);
AddCloud(if ShowCloud then if ExUp then Double.POSITIVE_INFINITY else
if ExDn then Double.NEGATIVE_INFINITY else na else na,
if ExUp then Double.NEGATIVE_INFINITY else
if ExDn then Double.POSITIVE_INFINITY else na,
GlobalColor("Green3"), GlobalColor("Red3"));
addlabel(Label and ExUp, "Xtrm Up", GlobalColor(“Green1”));
addlabel(Label and ExUp1,"Up", GlobalColor(“Green2”));
addlabel(Label and Up, "Weak Up", GlobalColor(“Green3”));
addlabel(Label and Up11, "X Weak Up",GlobalColor(“Green4”));
addlabel(Label and ExDn, "Xtrm Dwn", GlobalColor(“Red1”));
addlabel(Label and ExDn1,"Dwn", GlobalColor(“Red2”));
addlabel(Label and Dn, "Weak Dwn", GlobalColor(“Red3”));
addlabel(Label and Dn11, "X weak dwn", GlobalColor(“Red4”));
#//----END----------------------------------------
Last edited: