Convert TTM Scalper Indicator to Strategy?

S

Superfast

New member
Hello, I was trying to convert the TTM Scalper alert to a Strategy and found the following code 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)
 
Last edited by a moderator:
S

Superfast

New member
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.
 
D

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

Miket

Member
How do you use this? The original scalper put arrows in. This has horizontal lines.
 
C

cherif

Member
is this scalper similar to the ttm pivot scalper? does it signal after the third price candle?
 
T

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
 
I

ilovetrading

New member
VIP
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.
 
Last edited:
I

ilovetrading

New member
VIP
@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.
 
S

SparkyFlary

Member
@diazlaz Does this repaint and can it be useful as a trailing stop line of some sort when the price goes below a high or low line?
 
I

ianfaler

New member
Does this study not auto populate? you have to reload for this to show up? Any idea how to fix that?
 

Similar threads

Top