Beep Boop Indicator for ThinkorSwim

barbaros

Well-known member
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.

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.

OBvU3rL.png
 
Last edited:

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

Can anyone explain (@Shasha ?) what this is designed to show or how you would go about using it?

Nice work on the translation from TV to ToS, btw @barbaros.

It seems to work better if, after the declare lower; statement I include
Code:
declare zerobase;
otherwise, the 0.09 tall histogram bars just show up at the bottom of the plot -- but then again, perhaps that was the intended behaviour.

just my 0.002¢

-mashume
 
@barbaros , @mashume
Someone on another forum provided the following as a conversion to TOS. (I have no coding experience) Do either of you know which is actually closer to the original TV script.... barbaros's conversion or the following?? :

Code:
declare lower;
declare zerobase;

input fast_length = 12;
input slow_length = 26;
input EMATrend = 50;
input src = close;

input signal_length = 9;
input sma_source = {default "No", "Yes"};
input sma_signal = {default "No", "Yes"};

def fast_ma = if sma_source then SimpleMovingAvg(src, fast_length) else MovAvgExponential(src, fast_length);
def slow_ma = if sma_source then SimpleMovingAvg(src, slow_length) else MovAvgExponential(src, slow_length);

def macd = fast_ma - slow_ma;
def signal = if sma_signal then SimpleMovingAvg(macd, signal_length) else MovAvgExponential(macd, signal_length);
def hist = if macd - signal > 0 then 0.1 else if macd - signal < 0 then 0.09 else macd - signal;

def fastMA = MovAvgExponential(close, EMATrend);

plot histPlot = hist;

histPlot.DefineColor("grow_above", CreateColor(38, 166, 154));
histPlot.DefineColor("grow_below", CreateColor(255, 0, 0));
histPlot.DefineColor("fall_above", CreateColor(255, 255, 255));
histPlot.DefineColor("fall_below", CreateColor(255, 255, 255));
histPlot.DefineColor("macd", CreateColor(0, 148, 255));
histPlot.DefineColor("signal", CreateColor(255, 106, 0));

histPlot.AssignValueColor(
if hist == 0.1 and close > fastMA and open > fastMA and low > fastMA then
    histPlot.color("grow_above")
else if hist == 0.1 then
    histPlot.color("fall_above")
else if hist == 0.09 and close < fastMA and open < fastMA and high < fastMA then
    histPlot.color("grow_below")
else histPlot.color("fall_below")
);

histPlot.SetPaintingStrategy(paintingStrategy = PaintingStrategy.HISTOGRAM);
 
@Shasha This is interesting. It resembles my code very closely. Unless it was my twin doing the work, underlying implementation is the same, with a very minor difference. I have a label to show the current state of the bar.

BTW, This is pretty much MACD with a different presentation.

@BenTen Can you please change the title of this post. I don't know what I was thinking when I created it.

EDIT: never mind, it was done already.
 
@Shasha here is v2 (updated the first post). I have OCD when it comes to coding and can't let go. I added to hide bars that are not in the direction of the long term trend as it is described in the video. If you select EMAFilter to yes, it will hide the bars that are not in the direction of the long term trend. Check out the screenshot. You will need to figure out the profit target.
 
Last edited:
@barbaros Thanks. Your OCD gives me more peace of mind ;-) I see in your code long term as 200EMA as in vid. If i wanted to change that for instance to, 100 day EMA, i would just change it in the line "input EMAFilterPeriod = 200; # EMA Filter Trend Period" , correct?
I'll be giving it a shot in my day trading soon, after a little more backtesting. If you notice any improvement possibilities feel free to inform.
 
You don't need to change it in the code. You can edit the study parameters from ToS GUI, and yes, the EMAFilterPeriod is the one.

jIxBjo4.png
 
Last edited:
Here you go.

Python:
# Beep Boop MTF
# Converted from TradingView
# v1 - 20210115 barbaros
# v2 - 20210117 barbaros - Added filter to show only in long term direction
# v3 - 20210121 barbaros - Added MTF, Removed Source

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 Agg = AggregationPeriod.FIVE_MIN; # Aggregation Period
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(close(period = Agg), FastLength) else MovAvgExponential(close(period = Agg), FastLength);
def slow_ma = if SMASource then SimpleMovingAvg(close(period = Agg), SlowLength) else MovAvgExponential(close(period = Agg), 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(close(period = Agg), EMATrend);
def longtermMA = MovAvgExponential(close(period = Agg), 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")
);
 
I've been trying to apply to Futures /NQ, /YM, /GC, /HG, etc.. Doesn't seem to work well, at least with my calibrations. Any suggestions? I guess for forex it seems fairly justified
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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