This was a conversion request from another thread. Posting as a new indicator.
https://usethinkscript.com/threads/convert-tradingview-indicator-to-thinkorswim.3302/post-48296
@Shasha here you go. Let us know how it works.
Not bad with USD/CAD pair.
https://usethinkscript.com/threads/convert-tradingview-indicator-to-thinkorswim.3302/post-48296
@Shasha here you go. Let us know how it works.
Code:
# Beep Boop
# Converted from TradingView
# v1 - 20210115 barbaros
# v2 - 20210117 barbaros - Added filter to show only in long term direction
declare lower;
declare zerobase;
input FastLength = 12; # Fast Length
input SlowLength = 26; # Slow Length
input EMATrend = 50; # EMA Trend
input EMAFilter = no; # Only show in the direction of the trend
input EMAFilterPeriod = 200; # EMA Filter Trend Period
input Source = close; # Source
input SignalLength = 9; # Signal Smoothing, minval = 1, maxval = 50
input SMASource = no; # Simple MA(Oscillator)
input SMASignal = no; # Simple MA(Signal Line)
input ShowLabel = yes; # Show indicator label
def fast_ma = if SMASource then SimpleMovingAvg(Source, FastLength) else MovAvgExponential(Source, FastLength);
def slow_ma = if SMASource then SimpleMovingAvg(Source, SlowLength) else MovAvgExponential(Source, SlowLength);
def macd = fast_ma - slow_ma;
def signal = if SMASignal then SimpleMovingAvg(macd, SignalLength) else MovAvgExponential(macd, SignalLength);
def histVal = macd - signal;
def fastMA = MovAvgExponential(Source, EMATrend);
def longtermMA = MovAvgExponential(Source, EMAFilterPeriod);
plot hist = if histVal > 0 and (!EMAFilter or low > longtermMA) then 0.1
else if histVal < 0 and (!EMAFilter or high < longtermMA) then 0.09
else if EMAFilter then Double.NaN else histVal;
hist.defineColor("col_grow_above", CreateColor(38, 166, 154));
hist.defineColor("col_grow_below", CreateColor(255, 0, 0));
hist.defineColor("col_fall_above", CreateColor(255, 255, 255));
hist.defineColor("col_fall_below", CreateColor(255, 255, 255));
hist.defineColor("col_macd", CreateColor(0, 148, 255));
hist.defineColor("col_signal", CreateColor(255, 106, 0));
hist.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.assignValueColor(if hist == 0.1 then
if (hist == 0.1) and (close > fastMA) and (open > fastMA) and (low > fastMA) then
hist.Color("col_grow_above")
else
hist.Color("col_fall_above")
else
if (hist == 0.09) and (close < fastMA) and (open < fastMA) and (high < fastMA) then
hist.Color("col_grow_below")
else
hist.Color("col_fall_below"));
AddLabel(ShowLabel,
if hist == 0.1 then
if (hist == 0.1) and (close > fastMA) and (open > fastMA) and (low > fastMA) then
"Grow Above"
else
"Fall Above"
else
if (hist == 0.09) and (close < fastMA) and (open < fastMA) and (high < fastMA) then
"Grow Below"
else
"FallBelow",
if hist == 0.1 then
if (hist == 0.1) and (close > fastMA) and (open > fastMA) and (low > fastMA) then
hist.Color("col_grow_above")
else
hist.Color("col_fall_above")
else
if (hist == 0.09) and (close < fastMA) and (open < fastMA) and (high < fastMA) then
hist.Color("col_grow_below")
else
hist.Color("col_fall_below")
);
Not bad with USD/CAD pair.
Last edited: