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"));