Repaints TTM_ScalperAlert for ThinkorSwim

Repaints
I am trying to create a study Alert for the Mobius's TTM Scalper.
https://usethinkscript.com/threads/ttm_scalperalert-source-code-for-thinkorswim.914/

I would like an Alert when a new Pivot (Support/Resistance Line or High/Low Line) is plotted on the chart. I have been working on this with no results. Any and all thoughts would be greatly appreciated. Thank you in advance.
Attached below is the original 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);

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



# Alerts

Alert(SoundAlerts and h > al , "Up", Alert.BAR, Sound.Bell);

Alert(SoundAlerts and l < bl, "Down", Alert.BAR, Sound.Ding);
 

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

So, I understand that this indicator repaints by looking at the future bars. My question is how many bars in the future does it look (or rather wait to form) until it repaints the pivot in the past?
It looks like the line:
input n = 8;
controls the amount of future bars that the indicator looks at.
Is this correct?
 
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!
I have been testing this indicator out and I have the same problem. It doesn't paint or even repaint properly, but whenever I 'Edit Studies' and 'Apply' then it paints everything it missed.
I tested this on a MAC and Windows 10, and also tried uninstalling/reinstalling TOS but nothing seemed to change it. Also tested on TICK, TIME and RANGE charts, none made much of a difference.
It seems like the shorter N times caused more problems, but I'm not positive.
 
I have been testing this indicator out and I have the same problem. It doesn't paint or even repaint properly, but whenever I 'Edit Studies' and 'Apply' then it paints everything it missed.
I tested this on a MAC and Windows 10, and also tried uninstalling/reinstalling TOS but nothing seemed to change it. Also tested on TICK, TIME and RANGE charts, none made much of a difference.
It seems like the shorter N times caused more problems, but I'm not positive.

This should fix the lag and the need to refresh the screen.

Mobius TTM Scalper Replica is just a Fractal Pivot High/Low study as he indicates that. He defaulted to 8.

Ruby:
# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# 20221115 Fixed lagging plots by adding Abar/Bbar logic from Mobius Fractal Pivots

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];
rec Abar = if !IsNaN(A)
             then Firstbar
             else Al[1];
rec Bbar = if !IsNaN(B)
             then Firstbar
             else Bl[1];
def priorABar = if Al != Al[1]
                 then Abar[1]
                 else priorABar[1];

def priorBBar = if Bl != Bl[1]
                 then Bbar[1]
                 else priorBBar[1];

def HighPivots = Firstbar >= HighestAll(priorABar);
def LowPivots  = Firstbar >= HighestAll(priorBBar);

plot ph = if Firstbar == Abar then Round(A, 2) else Double.NaN;
ph.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

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

plot pl = if Firstbar == Bbar then Round(B, 2) else Double.NaN;
pl.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

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

# End Code
 
Last edited:
This is a strategy that uses the TOS TTM_ScalperAlert Indicator that I named the hidden code with.


with



Then after watching the indicator, I was able to create alerts and buy/sell strategy. It will repaint and sound alerts but then not actually change direction, so be careful. It does plot in real time and ONDemand. I have not looked at in years, so see if it might be useful to you.

Here is a usable TTM_ScalperAlert Study that plots real time with many options. It is the companion to the Strategy script that was posted.

In the image, the upper panel has the TTM_ScalperAlert Replica Study and below is the actual TTM_ScalperAlert Study.

Screenshot-2022-11-15-081808.png

Ruby:
#TTM_ScalperAlert_Replica
#Sleepyz
#Caution - This indicator repaints and plots will possibly change after a future bar's action

input horizontals   = yes;
input arrows        = yes;
input show_price    = yes;
input colorCandles  = Yes;
input minSwing      = 0.0;
input arrowOffset   = 1.5;
input SoundAlerts   = YES;

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

#Arrows @high/low
plot phigh = if PH then high + ticksize() * arrowoffset else Double.NaN;
plot plow  = if PL then low - ticksize() * arrowoffset else Double.NaN;
phigh.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
plow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
phigh.setdefaultColor(color.red);
plow.setdefaultColor(color.green);
phigh.sethiding(!arrows);
plow.sethiding(!arrows);

#Price Values @high/low
plot phi = if PH then high else Double.NaN;
plot plo = if PL then low else Double.NaN;
phi.SetPaintingStrategy(paintingStrategy.VALUES_ABOVE);
plo.SetPaintingStrategy(paintingStrategy.VALUES_below);
phi.setdefaultColor(color.red);
plo.setdefaultColor(color.green);
phi.sethiding(!show_price);
plo.sethiding(!show_price);

#Horizontal Lines
plot ph1 = if PH then high else Double.NaN;
plot pl1 = if PL then low else Double.NaN;

def hi        = if isnan(ph1) then hi[1] else ph1;
plot highline = if horizontals then hi else double.nan;
highline.setdefaultColor(color.red);
highline.setpaintingStrategy(paintingStrategy.DASHES);

def lo        = if isnan(pl1) then lo[1] else pl1;
plot lowline  = if horizontals then lo else double.nan;
lowline.setdefaultColor(color.green);
lowline.setpaintingStrategy(paintingStrategy.DASHES);

#Count of bars in trend
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 - Commented out for study
#plot scan = PH[2] == 1 or PL[2] == 1;

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

#Coloring Candles
AssignPriceColor(if colorCandles then if phc == 1 then Color.RED else Color.GREEN else Color.CURRENT);
 
Last edited:
Here is a usable TTM_ScalperAlert Study that plots real time with many options. It is the companion to the Strategy script that was posted.

In the image, the upper panel has the TTM_ScalperAlert Replica Study and below is the actual TTM_ScalperAlert Study.
@SleepyZ great job!! question, do you think it is possible to plot a arrow with the signal. thank you in advance
 
This should fix the lag and the need to refresh the screen.

Mobius TTM Scalper Replica is just a Fractal Pivot High/Low study as he indicates that. He defaulted to 8.
Thanks for posting that update! I call it lag free and am using it on a 5 range range put/call chart to show highs/lows. Works really well!
I'm still looking over the other scalper code.
 
This should fix the lag and the need to refresh the screen.

Mobius TTM Scalper Replica is just a Fractal Pivot High/Low study as he indicates that. He defaulted to 8.
Hi @SleepyZ, do you know how I could update this to change the candles below the high to red (downtrend) and the candles above the low green (uptrend). I attempted it but not getting good results.

Update: I was also trying to configure the high / low candle be red / green and the rest white.

Ruby:
# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# 20221115 Fixed lagging plots by adding Abar/Bbar logic from Mobius Fractal Pivots

input n            = 20;
input ShowLines    = yes;
input colorCandles = Yes;

def price = close;
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];
rec Abar = if !IsNaN(A)
             then Firstbar
             else Al[1];
rec Bbar = if !IsNaN(B)
             then Firstbar
             else Bl[1];
def priorABar = if Al != Al[1]
                 then Abar[1]
                 else priorABar[1];

def priorBBar = if Bl != Bl[1]
                 then Bbar[1]
                 else priorBBar[1];

def HighPivots = Firstbar >= HighestAll(priorABar);
def LowPivots  = Firstbar >= HighestAll(priorBBar);

plot ph = if Firstbar == Abar then Round(A, 2) else Double.NaN;
ph.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

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

plot pl = if Firstbar == Bbar then Round(B, 2) else Double.NaN;
pl.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

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

AssignPriceColor(if colorCandles and (price < hL)

                 then Color.RED

                 else if colorCandles and (price > ll)

                      then Color.GREEN

                      else Color.CURRENT);


# End Code
 
Last edited:
Hi @SleepyZ, do you know how I could update this to change the candles below the high to red (downtrend) and the candles above the low green (uptrend). I attempted it but not getting good results.

Update: I was also trying to configure the high / low candle be red / green and the rest white.

Here is the red/green request.

Screenshot-2022-12-12-093023.png
Ruby:
# Mobius
# Mobius on My Trade
# TTM Scalper Replica or High_Low_Pivots
# V001.06.2012
# 20221115 Fixed lagging plots by adding Abar/Bbar logic from Mobius Fractal Pivots

input n            = 20;
input ShowLines    = yes;
input colorCandles = Yes;

def price = close;
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];
rec Abar = if !IsNaN(A)
             then Firstbar
             else Al[1];
rec Bbar = if !IsNaN(B)
             then Firstbar
             else Bl[1];
def priorABar = if Al != Al[1]
                 then Abar[1]
                 else priorABar[1];

def priorBBar = if Bl != Bl[1]
                 then Bbar[1]
                 else priorBBar[1];

def HighPivots = Firstbar >= HighestAll(priorABar);
def LowPivots  = Firstbar >= HighestAll(priorBBar);

plot ph = if Firstbar == Abar then Round(A, 2) else Double.NaN;
ph.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);

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

plot pl = if Firstbar == Bbar then Round(B, 2) else Double.NaN;
pl.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

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

def green = if  Firstbar == Bbar then 1 else if Firstbar == Abar then -1 else green[1];

AssignPriceColor(if colorCandles and green==-1

                 then Color.RED

                 else if colorCandles and green==1

                      then Color.GREEN

                      else Color.CURRENT);


# End Code
 
Hi all - most of you have probably seen the TTM Squeeze Indicator and some of the code that allows the watchlists to show green/red signals that the squeeze has fired or may be soon be close to doing so. I have also played with the TTM Scalper Alert indicator which shows opportunities (up or down arrows) to consider buys/sells based on where the price action lays on the TTM histogram.

What i am looking for is the code that might allow a watchlist to populate a signal when the up or down arrow fires on a TTM Scalper Alert. Rather than looking at each chart individually, having a watchlist with these signals will help speed the process of ID'ing when it might be time to buy or sell.

Thanks for your help!

Eric
 
Last edited:
I'm using the TD Ameritrade default TTM-Squeeze. I wanted to see if I can add an audible alert when a squeeze is fired

The only code shown is:

#
# TD Ameritrade IP Company, Inc. (c) 2009-2022
#
# Source code isn't available.

declare lower;

input price = CLOSE;
input length = 20;
input nK = 1.5;
input nBB = 2.0;
input alertLine = 1.0;

plot Histogram = Double.NaN;
plot VolComp = Double.NaN;
plot SqueezeAlert = Double.NaN;

Can anyone help?
 
Last edited by a moderator:
I'm using the TD Ameritrade default TTM-Squeeze. I wanted to see if I can add an audible alert when a squeeze is fired

The only code shown is:

#
# TD Ameritrade IP Company, Inc. (c) 2009-2022
#
# Source code isn't available.

declare lower;

input price = CLOSE;
input length = 20;
input nK = 1.5;
input nBB = 2.0;
input alertLine = 1.0;

plot Histogram = Double.NaN;
plot VolComp = Double.NaN;
plot SqueezeAlert = Double.NaN;

Can anyone help?

eloborate on what 'fired' means.
just the first bar , at the start of a squeeze?
or every bar during a squeeze?


an alert needs a true condition to be enabled.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Alert


if you want the output of a study to turn on an alert, you need to determine which plot variable to use.

you listed the variables. but If you don't know what they are, then look up the study and write down the plot variables.

TTM_Squeeze
https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/T-U/TTM-Squeeze

you can create a study that displays the values of those plot variables and then you can look at them and compare to what the chart is doing and determine which one you need to use.

Code:
declare lower;
def th = TTM_Squeeze().Histogram;
def tv = TTM_Squeeze().VolComp;
def ts = TTM_Squeeze().SqueezeAlert;
plot z = 0;
addchartbubble(1, 0,
th + " h\n" +
tv + " v\n" +
ts + " s"
, color.yellow, yes);
 
I want to find ONLY the most recent ScalpertAlert and ignore any others before it. The following code plots all the ScalpertAlert in a time frame. How can I display ONLY the most recent alert and ignore others?

declare lower;
input varEnd=20;

plot ScalperAlert = fold i = 0 to varEnd
with varTest=Double.NaN
while isNan(varTest) and
!isnan(Close)
do TTM_ScalperAlert().PivotLow;
 
I want to find ONLY the most recent ScalpertAlert and ignore any others before it. The following code plots all the ScalpertAlert in a time frame. How can I display ONLY the most recent alert and ignore others?

declare lower;
input varEnd=20;

plot ScalperAlert = fold i = 0 to varEnd
with varTest=Double.NaN
while isNan(varTest) and
!isnan(Close)
do TTM_ScalperAlert().PivotLow;


i made 2 plots
1 for pivot highs, one for pivot lows

Code:
# scalperalert_just_1_alert

#https://usethinkscript.com/threads/display-only-ttm_scalperalert-most-recent-alert.14397/
#display only TTM_ScalperAlert() most recent alert

declare lower;

def na = double.nan;
def bn = barnumber();
#def lastbar = (!isnan(close) and isnan(close[-1]));

input varEnd = 20;

def piv_hi = TTM_ScalperAlert().Pivothigh;
def piv_lo = TTM_ScalperAlert().PivotLow;

def phibn = if piv_hi then bn else 0;
def plobn = if piv_lo then bn else 0;

def phi_last = highestall(phibn);
def plo_last = highestall(plobn);

plot zhi = (phi_last == bn);
zhi.SetDefaultColor(Color.green);
zhi.hidebubble();

plot zlo = (plo_last == bn);
zlo.SetDefaultColor(Color.red);
zlo.hidebubble();

#

hp1gegp.jpg
 
Hi all - most of you have probably seen the TTM Squeeze Indicator and some of the code that allows the watchlists to show green/red signals that the squeeze has fired or may be soon be close to doing so. I have also played with the TTM Scalper Alert indicator which shows opportunities (up or down arrows) to consider buys/sells based on where the price action lays on the TTM histogram.

What i am looking for is the code that might allow a watchlist to populate a signal when the up or down arrow fires on a TTM Scalper Alert. Rather than looking at each chart individually, having a watchlist with these signals will help speed the process of ID'ing when it might be time to buy or sell.

Thanks for your help!

Eric
https://usethinkscript.com/threads/ttm_scalperalert-for-thinkorswim.914/#post-97393
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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