TTM_ScalperAlert Source Code for ThinkorSwim

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)
reverse = input(false, title="Trade reverse")
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)
buySellSwitch = iff(triggerSell, 1, iff(triggerBuy, 0, nz(buySellSwitch[1])))
SBS = iff(triggerSell and buySellSwitch[1] == false, high, iff(triggerBuy and buySellSwitch[1], low, nz(SBS[1])))
clr_s = iff(triggerSell and buySellSwitch[1] == false, 1, iff(triggerBuy and buySellSwitch[1], 0, nz(clr_s[1])))
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:
Solution
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 ==...

diazlaz

Well-known member
2019 Donor
VIP
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);
 
Solution

LucidDreamer

New member
Looking for a code using scalp arrows as indicators (or have the candles change color) when the following conditions are met for the 1 Day 1 Min and 1 Day 5 Min using the TOS platform

Buy alert: The 10, 23 and 50 simple moving averages are above one another (in that order) in BOTH the 1 min and 5 min timeframes.

Sell alert: 10 simple moving average crosses the 23 on the 1 min timeframe

Also looking for a scanner to signal when a stock is testing the top VWAP

Let me know if anyone can help. Thanks!
 

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:

9poJ69m.png


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

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
 

ilovetrading

New member
Hello, I just downloaded this code and installed this study on my TOS charts. Can you tell me how this works? When are the lines formed? Is there anything else I need to customize? Also, it doesn't appear that my lines are auto populating. I have to reload the study to make them show up each time.

@tomsk @BenTen can you help me understand how to use this code? i installed it and have it up on TOS but need some assistance with it.

Code:
# TTM Scalper Alert
# blt
# 9.19.2016
# http://tos.mx/OqSUuM##

# Since the TTM Scalper uses 2 future bars and then back plots the
# arrow, it delays the alert. Hence here are the alerts and 1 condition
# that needs to be true within 5 bars. The TTM Scalper is the primary
# control for when the alert will sound.   

input minswing = 0.0;

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

def condup = pl and RSI() < 50 within 5 bars;
def conddn = ph and RSI() > 50 within 5 bars;

Alert(conddn[2], "Down", Alert.BAR, Sound.Ding);
Alert(condup[2], "Up", Alert.BAR, Sound.Ding);

input showdebug = no;

plot cu = if showdebug == no then Double.NaN else conddn;
     cu.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
     cu.SetDefaultColor(Color.CYAN);

plot cd = if showdebug == no then Double.NaN else condup;
     cd.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
     cd.SetDefaultColor(Color.YELLOW);
 
Last edited:

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

BenTen

Administrative
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:

rad14733

Well-known member
VIP
Try looking at the TTM_ScalperAlert Study that comes with TOS... You can simply add Alerts to that code or make up your own... Or are you just looking for others to supply the code rather than learning how to help yourself...??? I know a lot of members would rather just ask for others to do all the work for them... I almost never ask for help in forums because to me logic problems are just another of lifes challenges... No offense intended, just curious...
 
D

Delber5940

Guest
Try looking at the TTM_ScalperAlert Study that comes with TOS... You can simply add Alerts to that code or make up your own... Or are you just looking for others to supply the code rather than learning how to help yourself...??? I know a lot of members would rather just ask for others to do all the work for them... I almost never ask for help in forums because to me logic problems are just another of lifes challenges... No offense intended, just curious...
I want to know how to do it! Do i just add a alert scrip to the end?
 
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!

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

Similar threads

Top