# TTM_ScalperAlert Source Code for ThinkorSwim

#### Steve2286

##### New member
2019 Donor
Is there a way to turn Mobius's TTM Scalper into a watchlist column that would indicate when a higher high or lower low is formed on chart?

Code:
``````# Mobius

# TTM Scalper Replica or High_Low_Pivots

# V001.06.2012

input n = 8;

input ShowLines = 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);

Solution
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...

#### Superfast

##### New member
Is the source code for TTM Scalper Alert available in ThinkorSwim? I was trying to convert the TTM Scalper alert to a Strategy and found the following script online (from tradingview I believe. Could someone convert it to in TOS?

Code:
``````strategy(title="TTM scalper indicator", overlay = true)
triggerSell = iff(iff(close[1] < close,1,0) and (close[2] < close[1] or close[3] <close[1]),1,0)
triggerBuy = iff(iff(close[1] > close,1,0) and (close[2] > close[1] or close[3] > close[1]),1,0)
clr = iff(clr_s == 0 , red , green)
pos = iff(clr == green, 1,
iff(clr == red, -1, nz(pos[1], 0)))
possig = iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos))
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(SBS, color=clr, title="TTM", style = circles, linewidth = 2)``````

This scalper only gives an alert after three up bars or three down bars - by the time you get the signal, it may be too late. Not sure if it makes sense to test out this strategy.............Other persons may have had better luck with this, pls share.

Last edited by a moderator:

#### diazlaz

##### Well-known member
2019 Donor
VIP
This one has already been reversed engineered / duplicated by Mobius.

Ruby:
``````# Mobius
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012

input n = 8;
input ShowLines = 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);``````

#### diazlaz

##### Well-known member
2019 Donor
VIP
thanks @LucidDreamer I took a quick pass at coding it just to get a eye on it - still working on it. but this is the result of it, using SPY Friday as an example:

This is just the moving averages taking the buy and sell alerts as outlined above.

#### 2sureshk

##### Member
Please help with a scanner with Lower High and Higher Low from previous Bar (DAY) and the size of the bar should be Less than 60% of previous.

#### tomsk

##### Well-known member
VIP
@2sureshk from your description seems like you're looking for an inside bar transition from the previous bar to the current bar. That by definition is what a lower high and and a higher low is. Here is your requested scan. I have assumed that the size of the bar excludes the wicks. Here then is your requested scan. Make sure you run this on a daily aggregation on the scanner. I obtained 93 hits on a daily scan of the S&P 500.

Code:
``````# START
def barSize = AbsValue(open-close);
plot scan = high < high[1] and low > low[1] and barsize - barSize[1] < 0.6;
# END``````

#### tomsk

##### Well-known member
VIP
@cherif @Miket TTM Scalper as well as ZigZagHighLow uses future bars to confirm 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

#### kaneshaflowers

##### New member
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
AssignBackgroundColor(if ScalpBuy then color.green else if ScalpSell then color.red else color.black);``````

Thanks for the help

#### BenTen

Staff member
Staff
VIP
May want to read the comment posted by @Superfast before even consider using it.

In short, the TTM_Scalper is a lagging indicator. Adding alerts to it is useless.

Last edited:

#### tabs999

##### Member
Is there a higher high lower low indicator vice versa script out there floating around for ToS?

This is what I was able to find.

Bars until the next higher high _DMonkey

Code:
``````#I am unclear as to what you where trying to accomplish, but the here is an example of a forward loop...it starts with a simple condition to define a peak, then from there it loops forward and stops when the condition is meet. it checks to see if a high breaks above the peak.Again, I dont know what your goal was, but the fault usually lays in the logic....you should be able to figure out what your after from here. It displays how many bars after the peak it takes to make a break of that condition in your selected length.if it does not happen in your determined length no criteria is recorded.
input n = 13;
def h = high;
def bar = barnumber();
def peak = if sum(h > h[1],2)>=2 && h[-1] < h
then bar
else peak[1];
def hh2 = if bar == peak
then h
else hh2[1];
plot NextHigh = if bar == peak
then
fold i = 0 to n + 1
with price = Double.NaN
while IsNaN(price)
do if getValue(h, -i,( -n - 1)) > getvalue(hh2,-i,(-n - 1))
then i
else double.nan
else double.nan;

nexthigh.setpaintingStrategy(PaintingStrategy.VALUES_ABOVE);``````

#### Shooters_Gotta_Shoot

##### Member
VIP
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:

#### MerryDay

Staff member
Staff
VIP
@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:

#### MColb

##### Member
Does anyone have an indicator that colors the candles when they close higher than the previous candle?

#### XeoNoX

##### Well-known member
VIP
Does anyone have an indicator that colors the candles when they close higher than the previous candle?

@MColb

Colors the candle Blue if the Close is greater than the previous Candle

Code:
``````#By XeoNoX via usethinkscript.com
def scan = close>high[1];
AssignPriceColor(if scan then color.BLUE else color.white);``````

#### TOS Rookie

##### New member
I’m looking to create a counter, this is so basic, but learning.
1) Counter that only looks at red candles . After reaching a new low, each higher high Red candle (indicated by absolute highest price of the wick for day) would be counted. The first high red candle is 1, then next higher high red is 2, etc.... cycle runs forward until we terminate at a reversal in which we see lower low Red candles.
2) Now on to downside from a Peak, the first Red candle down is 1, and if the next Red candle is at least >=50% of previous candle body, then it would be counted as 2, same count continues downward until we terminate at new low.

Code:
``````Def Red = Close < Open;
Def HigherRed = Close < Open and  Absolute high price > Red (-1)
Def LowerRed = Close < Open and Absolute high price => 50% of Red (-1)
If HigherRed > Red, 1, else 0
Count # +1
If LowerRed < Red, 1, else 0
Count #+1``````

Something along these lines... and they can repaint over if a new Red Higher or Lower bar displaces the last one in value. Thanks for any guidance.

#### XeoNoX

##### Well-known member
VIP
@TOS Rookie
your scan will result in 0 results every time as it contradicts/nulls itself

#### TOS Rookie

##### New member
@TOS Rookie
your scan will result in 0 results every time as it contradicts/nulls itself
I just put that together as a concept of what I’m trying to achieve. No idea how to make it work, I’ve been studying the tutorial but maybe I’m just missing the basics here.

#### XeoNoX

##### Well-known member
VIP
I’m looking to create a counter, this is so basic, but learning.
1) Counter that only looks at red candles . After reaching a new low, each higher high Red candle (indicated by absolute highest price of the wick for day) would be counted. The first high red candle is 1, then next higher high red is 2, etc.... cycle runs forward until we terminate at a reversal in which we see lower low Red candles.
2) Now on to downside from a Peak, the first Red candle down is 1, and if the next Red candle is at least >=50% of previous candle body, then it would be counted as 2, same count continues downward until we terminate at new low.

Code:
``````Def Red = Close < Open;
Def HigherRed = Close < Open and  Absolute high price > Red (-1)
Def LowerRed = Close < Open and Absolute high price => 50% of Red (-1)
If HigherRed > Red, 1, else 0
Count # +1
If LowerRed < Red, 1, else 0
Count #+1``````

Something along these lines... and they can repaint over if a new Red Higher or Lower bar displaces the last one in value. Thanks for any guidance.

I just put that together as a concept of what I’m trying to achieve. No idea how to make it work, I’ve been studying the tutorial but maybe I’m just missing the basics here.
here goes your "concept" you requested:
Code:
``````def red_cande_high = if close<open then high else 0;
def higher_red_candle = red_cande_high > red_cande_high[1];
def Count_red_highs = CompoundValue(1, if higher_red_candle  then Count_red_highs[1] + 1 else 0, 0);
def Final_scan = if Count_red_highs and low>low[1] then 0 else Count_red_highs;
plot scan = Final_scan;``````

#### swazz

##### New member
VIP
@Steve2286 were you able to figure a watchlist for the ttm scalper alert. i tried but couldn't make progress. @BenTen can you guide?

#### british43

##### Member
Hello,

I'm trying to plot a low line at the low of the high scalp candle. Any help is greatly appeciated.

Code:
``````input n = 8;
input ShowLines = 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 Al = if !IsNaN(A)
then A
else Al[1];

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

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