Andean Oscillator For ThinkOrSwim

samer800

Conversion Expert
VIP
Lifetime
ilvwaGK.png


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 ----

lcKPWDK.png


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:
ilvwaGK.png


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----------------------------------------
I find that your color scheme to be confusing, I use a light to dark and then back to light more insightful for a trader, lighter colors for improving conditions and darker colors for worsening conditions

Code:
DefineGlobalColor("Sky1" , Color.Cyan);
DefineGlobalColor("Sky2" , CreateColor(50, 150, 200));
DefineGlobalColor("Sky4" , CreateColor(50, 150, 250));
DefineGlobalColor("Sky5" , Color.Blue);
DefineGlobalColor("Magenta1" , Color.Plum);
DefineGlobalColor("Magenta2" , Color.Magenta);
DefineGlobalColor("Magenta4" , CreateColor(225, 125, 225));
DefineGlobalColor("Magenta5" , CreateColor(225,175, 225));
 
I also added labels so that I can tell what the bar is
Code:
input label = Yes;
addlabel(Label == yes,"ExUp", GlobalColor(“Sky1”));
addlabel(Label == yes,"ExUp1", GlobalColor(“Sky2”));
addlabel(Label == yes," Up", GlobalColor(“Sky4”));
addlabel(Label == yes," Up11", GlobalColor(“Sky5”));
addlabel(Label == yes,"ExDn", GlobalColor(“Magenta1”));
addlabel(Label == yes,"ExDn1", GlobalColor(“Magenta2”));
addlabel(Label == yes,"Dn", GlobalColor(“Magenta4”));
addlabel(Label == yes,"Dn11", GlobalColor(“Magenta5”));
 

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
436 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