Adaptive Ergodic Oscillator For ThinkOrSwim

bigboss

Active member
This is the Adaptive Ergodic Oscillator converted from pinescript to thinkscript.


Code:
# Adaptive Ergodic Candlestick Oscillator [LazyBear]
# Converted to ThinkScript by bigboss.

declare lower;

DefineGlobalColor("Up",CreateColor(0,128,0));
DefineGlobalColor("Neutral",CreateColor(255,127,0));
DefineGlobalColor("Down",CreateColor(255,0,0));

script stoch {
    input c = close;
    input h = high;
    input l = low;
    input length = 14;
    plot ret = 100 * (c - lowest(l, length)) / (highest(h, length) - lowest(l, length));
}

script nz {
    input val = 0;
    plot ret = if IsNaN(val) then 0 else val;
}

input length = 14;
input smooth_length = 5; #ep
input signal_length = 9; #sl
input paintBars = no;

def vrb = AbsValue(stoch(close, high, low, length) - 50) / 50;
def mep = 2 / (smooth_length + 1);
def ce = barnumber() <= ((length + smooth_length) * 2);
def came1 = If(ce, close - open, nz(came1[1]) + mep * vrb * ((close - open) - nz(came1[1])));
def came2 = If(ce, high - low, nz(came2[1]) + mep * vrb * ((high - low) - nz(came2[1])));
def came11 = If(ce, came1, nz(came11[1]) + mep * vrb * (came1 - nz(came11[1])));
def came22 = If(ce, came2, nz(came22[1]) + mep * vrb * (came2 - nz(came22[1])));
def eco = came11 / came22 * 100.0;
def se = ExpAverage(eco, signal_length);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.WHITE);

plot aeco = eco;
aeco.SetLineWeight(2);

plot aeco_hist = eco;
aeco_hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);


aeco_hist.AssignValueColor(
    if eco > 0 then
        if eco > eco[1] then GlobalColor("Up") else GlobalColor("Neutral")
    else if eco < eco[1] then  GlobalColor("Down") else  GlobalColor("Neutral"));

aeco.AssignValueColor(
    if eco > 0 then
        if eco > eco[1] then GlobalColor("Up") else  GlobalColor("Neutral")
    else if eco < eco[1] then  GlobalColor("Down") else  GlobalColor("Neutral"));

AssignPriceColor(
    if !paintbars then color.current else
    if eco > 0 then
        if eco > se then GlobalColor("Up") else  GlobalColor("Neutral")
    else if eco < se then  GlobalColor("Down") else  GlobalColor("Neutral"));
 

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

Here is a little more compress version of this nice Adaptive Ergodic Oscillator. This version do not paint upper candles

Code:
# Adaptive Ergodic Candlestick Oscillator [LazyBear]
# Converted to ThinkScript by bigboss.

declare lower;

input length = 20;
input smooth_length = 5; #ep
input signal_length = 9; #sl

def vrb = AbsValue(100 * (close - Lowest(low, length)) / (Highest(high, length) - Lowest(low, length)) - 50) / 50;
def mep = 2 / (smooth_length + 1);
def ce = BarNumber() <= ((length + smooth_length) * 2);

def came1 = If(ce, close - open, came1[1] + mep * vrb * ((close - open) - came1[1]));
def came2 = If(ce, high - low, came2[1] + mep * vrb * ((high - low) - came2[1]));
def came11 = If(ce, came1, came11[1] + mep * vrb * (came1 - came11[1]));
def came22 = If(ce, came2, came22[1] + mep * vrb * (came2 - came22[1]));

def eco = came11 / came22 * 100.0;
def se = ExpAverage(eco, signal_length);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.WHITE);

plot aeco = eco;
aeco.SetLineWeight(2);
aeco.AssignValueColor(if eco > 0 then
                      if eco > eco[1] then CreateColor(0, 150, 0) else CreateColor(85,0,0) else
                      if eco < eco[1] then CreateColor(255, 0, 0) else CreateColor(0, 60, 0));

plot aeco_hist = eco;
aeco_hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
aeco_hist.AssignValueColor(if eco > 0 then
                           if eco > eco[1] then CreateColor(0, 150, 0) else CreateColor(85,0,0) else
                           if eco < eco[1] then  CreateColor(255, 0, 0) else  CreateColor(0, 60, 0));


have fun!
 
Last edited by a moderator:
This is the Adaptive Ergodic Oscillator converted from pinescript to thinkscript.


Code:
# Adaptive Ergodic Candlestick Oscillator [LazyBear]
# Converted to ThinkScript by bigboss.

declare lower;

DefineGlobalColor("Up",CreateColor(0,128,0));
DefineGlobalColor("Neutral",CreateColor(255,127,0));
DefineGlobalColor("Down",CreateColor(255,0,0));

script stoch {
    input c = close;
    input h = high;
    input l = low;
    input length = 14;
    plot ret = 100 * (c - lowest(l, length)) / (highest(h, length) - lowest(l, length));
}

script nz {
    input val = 0;
    plot ret = if IsNaN(val) then 0 else val;
}

input length = 14;
input smooth_length = 5; #ep
input signal_length = 9; #sl
input paintBars = no;

def vrb = AbsValue(stoch(close, high, low, length) - 50) / 50;
def mep = 2 / (smooth_length + 1);
def ce = barnumber() <= ((length + smooth_length) * 2);
def came1 = If(ce, close - open, nz(came1[1]) + mep * vrb * ((close - open) - nz(came1[1])));
def came2 = If(ce, high - low, nz(came2[1]) + mep * vrb * ((high - low) - nz(came2[1])));
def came11 = If(ce, came1, nz(came11[1]) + mep * vrb * (came1 - nz(came11[1])));
def came22 = If(ce, came2, nz(came22[1]) + mep * vrb * (came2 - nz(came22[1])));
def eco = came11 / came22 * 100.0;
def se = ExpAverage(eco, signal_length);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.WHITE);

plot aeco = eco;
aeco.SetLineWeight(2);

plot aeco_hist = eco;
aeco_hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);


aeco_hist.AssignValueColor(
    if eco > 0 then
        if eco > eco[1] then GlobalColor("Up") else GlobalColor("Neutral")
    else if eco < eco[1] then  GlobalColor("Down") else  GlobalColor("Neutral"));

aeco.AssignValueColor(
    if eco > 0 then
        if eco > eco[1] then GlobalColor("Up") else  GlobalColor("Neutral")
    else if eco < eco[1] then  GlobalColor("Down") else  GlobalColor("Neutral"));

AssignPriceColor(
    if !paintbars then color.current else
    if eco > 0 then
        if eco > se then GlobalColor("Up") else  GlobalColor("Neutral")
    else if eco < se then  GlobalColor("Down") else  GlobalColor("Neutral"));
Copied the Adaptive Ergodic Candlestick Oscillator but my candlesticks do not look the same. Is there something I have to do to correct this?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
475 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