Repaints TTM_ScalperAlert for ThinkorSwim

Repaints

diazlaz

Well-known member
2019 Donor
VIP
TTM_ScalperAlert reversed engineered / duplicated by Mobius.

Ruby:
# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# jpwel added alerts 06/26/2015

input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);
def A = if (Firstbar > n
            and h == Highest(h, n)
            and Highest)
            then h
            else Double.NaN;
def Lowest = fold j = 1
            to n + 1
            with q = 1
            while q
            do l < GetValue(l, -j);
def B = if (Firstbar > n
            and l == Lowest(l, n)
            and Lowest)
            then l
            else Double.NaN;
rec Al = if !IsNaN(A)
             then A
             else Al[1];
rec Bl = if !IsNaN(B)
             then B
             else Bl[1];

plot ph = Round(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot hL = if Al > 0
                       then Al
                       else Double.NaN;
hL.SetHiding(!ShowLines);
hL.SetPaintingStrategy(PaintingStrategy.DASHES);
hL.SetDefaultColor(Color.GREEN);

plot pl = Round(B, 2);
pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot ll = if Bl > 0
                      then Bl
                      else Double.NaN;
ll.SetHiding(!ShowLines);
ll.SetPaintingStrategy(PaintingStrategy.DASHES);
ll.SetDefaultColor(Color.RED);
 
Last edited by a moderator:
TTM Scalper as well as ZigZagHighLow uses future bars to repaint pivots and that is the reason why they look "so good". This was reemphasized by Mobius several years ago when someone asked him a similar query
 
Last edited by a moderator:
Hi, I want to build a TTM_ScalperAlert scan, can someone please help me fix this code. i try to mimic the TTM_Squeeze scan but it show error.

Code:
# TTM_ScalperAlert
def ScalpBuy = TTM_ScalperAlert().Scan == 1 and TTM_ScalperAlert().Scan[1] == 0
def ScalpSell = TTM_ScalperAlert().Scan == -1 and TTM_ScalperAlert().Scan[1] == 0
AddLabel(ScalpBuy, "BUY", color.white);
AddLabel(ScalpSell, "SELL", color.white);
AssignBackgroundColor(if ScalpBuy then color.green else if ScalpSell then color.red else color.black);

Thanks for the help
 
May want to read the comment posted by @tomsk before even consider using it.

In short, the TTM_Scalper is a lagging indicator. Adding alerts to it is useless.
 
Last edited by a moderator:
Hey everyone,

I came across this Mobius Study titled: "TTM Scalper Replica" or maybe "High_Low_Pivots" in the Convert TTM Scalper Indicator to Strategy? thread from a little while back. I really like this study, but it has one flaw that I am hoping someone may know how to fix! When you load the indicator for the first time, it plots everything where it should be with no issues. BUT when the market is open, for some reason the indicator does not want to update as time moves along. If you go to 'Edit Study' and just click 'Apply' the indicator does update it's information and looks perfectly normal again. So, for backtesting purposes this is not a problem due to the system automatically updating previous data, but it for some reason doesn't want to update it's real-time / present data. But once you "Re-Apply" / refresh the indicator it works.

I would rather not manually update my indicators every 30 seconds / I don't think anyone would...so if there is any way to fix this, it would be greatly appreciated!
 
Last edited by a moderator:
@Shooters_Gotta_Shoot
In the LoungeArchieves there was a conversation:
11:07 Mobius: uncle.. TTM Scalper looks so good because it uses Future Bars to confirm the pivot. Any signal will be at minimum 3 bars late.

11:10 Mobius: kathy - You can move that signal by using your existing condition as a definition and assgining the plot an index. But like the TTM Scalper if you index to the future to move the plot back it will plot that amount of bars

12:10 MTS1: Pretty sure it uses future data to determine pivots; hence it 'repaints'; the results change as candles are added.

12:11 ron6875: So future data cannot have alerts?

12:12 MTS1: (Or lowPivot). Not if it plots on historical candles once confirmed.

12:12 ron6875: ohh, so once historical candles are confirmed an alert cant happen?

12:19 FoxTechnicals: I'd be extremely impressed if someone made a working strategy out of the TTM scalper. One of the most misleading indciators I've ever come across

Mobius: TTM scalper repaints as does zigzag making it useless

18:23 bradleyj: I have been backtesting the TTM Scalper Alert and it seems to work pretty good for Index futures on 15 min charts.
18:24 bradleyj: So you have a Study that could do the same thing?
18:24 Mobius: It's Perfect since it confirms pivots with future bars. Just think if you could only trade that way
18:24 Mobius: That study is pure "D" crap
 
Last edited:
This one has already been reversed engineered / duplicated by Mobius.

Ruby:
# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# jpwel added alerts 06/26/2015

input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);
def A = if (Firstbar > n
            and h == Highest(h, n)
            and Highest)
            then h
            else Double.NaN;
def Lowest = fold j = 1
            to n + 1
            with q = 1
            while q
            do l < GetValue(l, -j);
def B = if (Firstbar > n
            and l == Lowest(l, n)
            and Lowest)
            then l
            else Double.NaN;
rec Al = if !IsNaN(A)
             then A
             else Al[1];
rec Bl = if !IsNaN(B)
             then B
             else Bl[1];

plot ph = Round(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot hL = if Al > 0
                       then Al
                       else Double.NaN;
hL.SetHiding(!ShowLines);
hL.SetPaintingStrategy(PaintingStrategy.DASHES);
hL.SetDefaultColor(Color.GREEN);

plot pl = Round(B, 2);
pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot ll = if Bl > 0
                      then Bl
                      else Double.NaN;
ll.SetHiding(!ShowLines);
ll.SetPaintingStrategy(PaintingStrategy.DASHES);
ll.SetDefaultColor(Color.RED);
Hi,
Thanks for the sharing. I can't understand this logic though. Aren't those "Highest" and then calling Highest() function doing the same? But then I found that we can't ommit either of the tow.
 
Hi,
Thanks for the sharing. I can't understand this logic though. Aren't those "Highest" and then calling Highest() function doing the same? But then I found that we can't ommit either of the tow.
No you can't omit them, they call the Future Bars to confirm the pivot.
 
No you can't omit them, they call the Future Bars to confirm the pivot.
Thanks for the quick reply. Which one is using the future bars? The following?

Code:
def Highest = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);

I am having trouble understanding the GetValue function. The thinkscript documentation wasn't very clear for me.
 
Thanks for the quick reply. Which one is using the future bars? The following?

Code:
def Highest = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);

I am having trouble understanding the GetValue function. The thinkscript documentation wasn't very clear for me.
OK. I figured it out. You have to tweak it to your liking. The loop Highest and Lowest use future values to determine the Pivot points. Yes, it is lagging but you can change the code a little bit to determine how many future bars you want to look at. If you change the future bars to be checked to say 3 bars (opposed to the default of 8 bars in this code), you will be able to enter the trade three bars later. The number of future bars determines the accuracy as well. More future bars you look, more accurate but more useless it becomes for trading. So Keep the future bars low to get a quick signal but then add some other indicator to tell you when to ignore it.
 
OK. I figured it out. You have to tweak it to your liking. The loop Highest and Lowest use future values to determine the Pivot points. Yes, it is lagging but you can change the code a little bit to determine how many future bars you want to look at. If you change the future bars to be checked to say 3 bars (opposed to the default of 8 bars in this code), you will be able to enter the trade three bars later. The number of future bars determines the accuracy as well. More future bars you look, more accurate but more useless it becomes for trading. So Keep the future bars low to get a quick signal but then add some other indicator to tell you when to ignore it.
I figured that this code is similar but NOT SAME as TTM Scalper. I am trying to make it better (Not trying to make is exactly same as TTM scalper)> Will post here when done.
 
I figured that this code is similar but NOT SAME as TTM Scalper. I am trying to make it better (Not trying to make is exactly same as TTM scalper)> Will post here when done.
Hi, did you ever fix the TTM Scalper? I use 3 bars in TTM Scalper and use HA 2grn bars no down tail on bars to confirm.
 
Hi, did you ever fix the TTM Scalper? I use 3 bars in TTM Scalper and use HA 2grn bars no down tail on bars to confirm.
I have TTM Scalper set up to give a sound alert and give an up arrow on the third bar after the signal. This bar gives the buy or sell signal. I can share if you want. What I am after actually is to have a code/logic that can simulate that so that I can place automated trades via TDAmeritrade Software APIs.
 
Need some help trying to edit this code to work for OTC Pennies. The problem I'm having is with the lines:

plot ph = Round(A, 2);
plot pL = Round(B, 2);


It works fine for anything trading above .99 but with the lower penny stocks that trade more than two decimal places, it rounds the plot to the nearest hundredth.
0ZPcuct.png


I tried to modify the code myself, by using

plot ph =GetValue(A, 2);
plot pL = GetValue(B, 2);


I was successful in getting the rest of the decimal places to plot, but now they're plotting within the lines rather than above and below.
i5nLhbj.png


Anyone able to help me get these values to plot back above and below the lines?

Code:
# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# jpwel added alerts 06/26/2015

input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);
def A = if (Firstbar > n
            and h == Highest(h, n)
            and Highest)
            then h
            else Double.NaN;
def Lowest = fold j = 1
            to n + 1
            with q = 1
            while q
            do l < GetValue(l, -j);
def B = if (Firstbar > n
            and l == Lowest(l, n)
            and Lowest)
            then l
            else Double.NaN;
rec Al = if !IsNaN(A)
             then A
             else Al[1];
rec Bl = if !IsNaN(B)
             then B
             else Bl[1];

plot ph = Round(A, 2);
#plot ph = GetValue(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot hL = if Al > 0
                       then Al
                       else Double.NaN;
hL.SetHiding(!ShowLines);
hL.SetPaintingStrategy(PaintingStrategy.DASHES);
hL.SetDefaultColor(Color.GREEN);

plot pl = Round(B,2);
#plot pl = GetValue(B, 2);
pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot ll = if Bl > 0
                      then Bl
                      else Double.NaN;
ll.SetHiding(!ShowLines);
ll.SetPaintingStrategy(PaintingStrategy.DASHES);
ll.SetDefaultColor(Color.RED);
 
Last edited:
Need some help trying to edit this code to work for OTC Pennies. The problem I'm having is with the lines:

plot ph = Round(A, 2);
plot pL = Round(B, 2);


It works fine for anything trading above .99 but with the lower penny stocks that trade more than two decimal places, it rounds the plot to the nearest hundredth.

I tried to modify the code myself, by using

plot ph =GetValue(A, 2);
plot pL = GetValue(B, 2);


I was successful in getting the rest of the decimal places to plot, but now they're plotting within the lines rather than above and below.

Anyone able to help me get these values to plot back above and below the lines?

good job on trying something. it wasn't right, but you tried. keep on experimenting and learning.

getvalue has nothing to do with rounding a number. it reads a variable , x bars away from the current bar.

in your case,
. plot ph = GetValue(A, 2);
is using an offset of 2 to read A.
that means it is looking back 2 bars and reading the value of A. that is why the numbers are 'on the line'.
the numbers are not from the candle that triggered the line to be drawn. they are the wrong numbers.

i added this to change how many digits are shown.
def digits = if close < 0.01 then 6 else if close < 1 then 4 else 2;
plot ph = Round(A, digits);
plot pL = Round(B, digits);

if there are trailing zeros, they will not be shown. ( 0.4100 will be 0.41 )

tested with
OGEN 0.4425
ACRX 0.4850
SGMD 0.00085


Ruby:
# peakhorzlines_6digits_00c

# add digits formula for rounding to 2,4,6 digits

# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# jpwel added alerts 06/26/2015

input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);
def A = if (Firstbar > n
            and h == Highest(h, n)
            and Highest)
            then h
            else Double.NaN;
def Lowest = fold j = 1
            to n + 1
            with q = 1
            while q
            do l < GetValue(l, -j);
def B = if (Firstbar > n
            and l == Lowest(l, n)
            and Lowest)
            then l
            else Double.NaN;
rec Al = if !IsNaN(A)
             then A
             else Al[1];
rec Bl = if !IsNaN(B)
             then B
             else Bl[1];


def digits = if close < 0.01 then 6 else if close < 1 then 4 else 2;

plot ph = Round(A, digits);
#plot ph = Round(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot hL = if Al > 0
                       then Al
                       else Double.NaN;
hL.SetHiding(!ShowLines);
hL.SetPaintingStrategy(PaintingStrategy.DASHES);
hL.SetDefaultColor(Color.GREEN);


plot pL = Round(B, digits);
#plot pl = Round(B,2);
pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot ll = if Bl > 0
                      then Bl
                      else Double.NaN;
ll.SetHiding(!ShowLines);
ll.SetPaintingStrategy(PaintingStrategy.DASHES);
ll.SetDefaultColor(Color.RED);
#

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetValue
 
good job on trying something. it wasn't right, but you tried. keep on experimenting and learning.

getvalue has nothing to do with rounding a number. it reads a variable , x bars away from the current bar.

in your case,
. plot ph = GetValue(A, 2);
is using an offset of 2 to read A.
that means it is looking back 2 bars and reading the value of A. that is why the numbers are 'on the line'.
the numbers are not from the candle that triggered the line to be drawn. they are the wrong numbers.

i added this to change how many digits are shown.
def digits = if close < 0.01 then 6 else if close < 1 then 4 else 2;
plot ph = Round(A, digits);
plot pL = Round(B, digits);

if there are trailing zeros, they will not be shown. ( 0.4100 will be 0.41 )

tested with
OGEN 0.4425
ACRX 0.4850
SGMD 0.00085


Ruby:
# peakhorzlines_6digits_00c

# add digits formula for rounding to 2,4,6 digits

# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# jpwel added alerts 06/26/2015

input n = 8;
input ShowLines = yes;
input SoundAlerts = yes;

def h = high;
def l = low;
def Firstbar = BarNumber();
def Highest = fold i = 1
             to n + 1
             with p = 1
             while p
             do h > GetValue(h, -i);
def A = if (Firstbar > n
            and h == Highest(h, n)
            and Highest)
            then h
            else Double.NaN;
def Lowest = fold j = 1
            to n + 1
            with q = 1
            while q
            do l < GetValue(l, -j);
def B = if (Firstbar > n
            and l == Lowest(l, n)
            and Lowest)
            then l
            else Double.NaN;
rec Al = if !IsNaN(A)
             then A
             else Al[1];
rec Bl = if !IsNaN(B)
             then B
             else Bl[1];


def digits = if close < 0.01 then 6 else if close < 1 then 4 else 2;

plot ph = Round(A, digits);
#plot ph = Round(A, 2);
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

plot hL = if Al > 0
                       then Al
                       else Double.NaN;
hL.SetHiding(!ShowLines);
hL.SetPaintingStrategy(PaintingStrategy.DASHES);
hL.SetDefaultColor(Color.GREEN);


plot pL = Round(B, digits);
#plot pl = Round(B,2);
pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

plot ll = if Bl > 0
                      then Bl
                      else Double.NaN;
ll.SetHiding(!ShowLines);
ll.SetPaintingStrategy(PaintingStrategy.DASHES);
ll.SetDefaultColor(Color.RED);
#

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetValue
Thank you so so much! I really appreciate it. I really do try to not be one of those that just demands everyone write them code. I enjoy trying to figure it out on my own, and have had much success by just combing through posts on this site for hours. I have very basic experience when it comes to coding, but enough to the point where if I go through someone else's code I can usually figure out what's doing what.... but I sometimes struggle with the "why?" like with this one. I appreciate you answering the "why?" too, and sharing the info link. I understand now "why?", and I definitely would not have known how to remedy it. So again thank you for the updated code, and for being informative as well.

Have a safe journey through life! - Buster
 
Hi,

I'm using the TTM Scalper Alert that comes with TOS. It prints an arrow on the chart when a specific sequence of candles shows up.
How do I set an alert so it can alert when the arrow prints?

Thanks
 
Hi all I am new here. The TTM Scalper Alert in TOS, can we add a bubble so the arrow would change from and Red sell or Green Buy to bubble Reversal. Has anyone used this before or have one already done? Thank you
 
Hi,

I'm using the TTM Scalper Alert that comes with TOS. It prints an arrow on the chart when a specific sequence of candles shows up.
How do I set an alert so it can alert when the arrow prints?

Thanks
Hi all I am new here. The TTM Scalper Alert in TOS, can we add a bubble so the arrow would change from and Red sell or Green Buy to bubble Reversal. Has anyone used this before or have one already done? Thank you
Because it uses future bars to confirm and then goes back in history to give the arrow. There is no alert because the alerts can't alert on re-written history. Also the considerable lag makes alerts not helpful.
https://usethinkscript.com/threads/ttm_scalperalert-source-code-for-thinkorswim.914/#post-48120
https://usethinkscript.com/threads/ttm_scalperalert-source-code-for-thinkorswim.914/#post-26412
 
Last edited:
Hi,

I'm using the TTM Scalper Alert that comes with TOS. It prints an arrow on the chart when a specific sequence of candles shows up.
How do I set an alert so it can alert when the arrow prints?

Thanks
Hi all I am new here. The TTM Scalper Alert in TOS, can we add a bubble so the arrow would change from and Red sell or Green Buy to bubble Reversal. Has anyone used this before or have one already done? Thank you

This was done awhile ago, but may help with both your requests. This uses a reference to the indicator as the actual indicator's code is hidden.

The code includes options for arrows, bubbles, alerts, scan, trend counts, and price coloring. Also, remember that this indicator repaints as it uses future bars to determine changes in trend. For example, the price color of the last 2 bars will change to red/green once 2 future bars are determined.

Capture.jpg
Ruby:
#TTM_ScalperAlert
#BLT

input minSwing = 0.0;
input tickOffset = .5;


def PH = TTM_ScalperAlert(minSwing).PivotHigh;
def PL = TTM_ScalperAlert(minSwing).PivotLow;

#Arrows
input showarrows = yes;
plot ph1 = if showarrows and PH then high else Double.NaN;
plot pl1 = if showarrows and PL then low else Double.NaN;
ph1.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
pl1.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ph1.SetDefaultColor(Color.RED);
pl1.SetDefaultColor(Color.GREEN);

#Bubbles
input showbubbles = yes;
AddChartBubble(showbubbles and ph1, high, "Sell", Color.RED);
AddChartBubble(showbubbles and pl1, low, "Buy", Color.GREEN, no);

#Trend Count Label
rec phc = if PH == 1 then 1 else if PL == 1 then 0 else phc[1];
rec plc = if PL == 1 then 1 else if PH == 1 then 0 else plc[1];
rec phcount = if phc[1] == 0 and phc == 1
              then 1
              else if phcount[1] >= 1 and phc == 1
              then phcount[1] + 1
              else 0;
rec plcount = if plc[1] == 0 and plc == 1
              then 1
              else if plcount[1] >= 1 and plc == 1
              then plcount[1] + 1
              else 0;
def phh = if phc[2] == 1 then 1 else 0;

input showlabel = yes;
AddLabel(showlabel, if phh == 1 then "DOWN " + (phcount[2] + 2) else "UP " + (plcount[2] + 2), if phh >= 1 then Color.RED else Color.GREEN);

#Scan Code
plot scan = PH[2] == 1 or PL[2] == 1;

#Alerts
input SoundAlerts = Yes;
Alert(SoundAlerts and PH[2] == 1, "Down", Alert.BAR, Sound.Ding);
Alert(SoundAlerts and PL[2] == 1, "Up", Alert.BAR, Sound.Ding);

#Candle Color
input colorPrice = Yes;
AssignPriceColor(if colorPrice then if phc == 1 then Color.RED else Color.GREEN else Color.CURRENT);
 

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