Sequential Indicators for ThinkorSwim

Okay, so now I have made it to where it plots a horizontal line to where the low is on a ascending count. which is great, just what ive been trying to do. But the horizontal line only shows under 1 bar, im trying to figure out how to extend it to current time. Then after solving this, i need the line to disappear after price closes below it

Code:
def SetUpCount = CompoundValue(1, if close > close[4]
                 then SetUpCount[1] + 1
                 else if close < close[4]
                 then 0
                 else SetUpCount[1], 1);
def setup9 = setupcount == 9;

plot Count = if SetUpCount == 0 or
                SetUpCount == SetUPCount[1] or
                SetUpCount > 9
             then double.nan
             else SetUpCount;
     Count.SetPaintingStrategy(PaintingStrategy.Values_Above);
     Count.Setdefaultcolor(color.cyan);

Def lowInPeriod = if SetUpCount == 9 then Lowest(low, 9) else double.nan;
plot low = lowInPeriod;
low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Can anyone give me some insight on the error I am getting. (not the best at working thru the logic).

SequenceCounter()."Perfect Buy" is true within 2 bars (on 1 hour)

Get the following error.. Folding: integer 'to' is expected. NaN

what am I missing? thanks
 
Interesting issue since this study code works.

Code:
plot A = if SequenceCounter()."Perfect Buy" is true within 2 bars
         then close()
         else Double.NaN;
A.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

I tried using the "perfect buy" formula as well but that ended in tears.
 
@Sean_C I'm not sure that the SequenceCounter() function is broken but it's definitely a bit quirky...

Edited to add: I found this information on Jim Shinglers site:
The use of the TOS 'SequenceCounter', for intra-day trading, has an advantage when the count can be viewed to multiple aggregations simultaneously. This can be done by setting up a grid of 4 components, as an example. The below picture illustrates doing this. Also configure the chart to synchronize the cursor across all grid charts via Chart settings/general tab/Synchronize crosshair position. A tick chart seems to present a neat plot. Regular grids is suggested in lieu of flexible grids.

The example picture is no longer available on his site...
 
Last edited by a moderator:
I am looking for TD Combo indicator to use in addition to SequenceCounter (already a TOS indicator).

Your help is greatly appreciated.
 
@alokranjan3 The TD Combo Indicator identifies when a trend is near exhaustion. This forum already has several trend exhaustion studies:
https://usethinkscript.com/threads/trend-building-exhausting-for-thinkorswim.1347/
https://usethinkscript.com/threads/trend-exhaustion-indicator-for-thinkorswim.333/
https://usethinkscript.com/threads/leledc-exhaustion-indicator-for-thinkorswim.3369/
Just to name a few.

Have you been using the TD combo? If you really want to garner interest for your indicator, your best bet would be to explain in detail why you think yours is superior and to illustrate with screenshots: the comparisons, and differences between them. When you put effort into providing the images, the differences, and in explaining how this will improve our trading. It makes it feel more like a team effort. Then armed with all those details, some enterprising poster might become interested in making enhancements to one of the TOS Trend Exhaustion Indicators that already exists.
https://usethinkscript.com/threads/how-to-insert-image-in-a-post-thread.277/
HTH
 
MerryDay
Thanks for the links to trend exhaustion indicator. I will test these to see if I can use one of these.

I am testing TD sequential and TD Combo. It's difficult to test TD combo since I am counting "TD countdown bars" manually and it takes a long time to to be certain that I am counting it correctly.
 
@BenTen Thanks for sharing these scans. Question how would you modify it so its finding the 1st in the count sequence? This finds the 9th or the end.
TIA
 
@MoreFunn those scans cannot be modified but have a look at the counter studies in post#3; perhaps one of them can help you?
 
Okay, so now I have made it to where it plots a horizontal line to where the low is on a ascending count. which is great, just what ive been trying to do. But the horizontal line only shows under 1 bar, im trying to figure out how to extend it to current time. Then after solving this, i need the line to disappear after price closes below it

Code:
def SetUpCount = CompoundValue(1, if close > close[4]
                 then SetUpCount[1] + 1
                 else if close < close[4]
                 then 0
                 else SetUpCount[1], 1);
def setup9 = setupcount == 9;

plot Count = if SetUpCount == 0 or
                SetUpCount == SetUPCount[1] or
                SetUpCount > 9
             then double.nan
             else SetUpCount;
     Count.SetPaintingStrategy(PaintingStrategy.Values_Above);
     Count.Setdefaultcolor(color.cyan);

Def lowInPeriod = if SetUpCount == 9 then Lowest(low, 9) else double.nan;
plot low = lowInPeriod;
low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Been a while but thought I'd try. I want to add support and resistance line as well as trend lines eventually if I get really clever. I tried your code and get the same under 1 bar. Did you ever improve upon this? Thanks (if you see this).
 
Okay, so now I have made it to where it plots a horizontal line to where the low is on a ascending count. which is great, just what ive been trying to do. But the horizontal line only shows under 1 bar, im trying to figure out how to extend it to current time. Then after solving this, i need the line to disappear after price closes below it

Code:
def SetUpCount = CompoundValue(1, if close > close[4]
                 then SetUpCount[1] + 1
                 else if close < close[4]
                 then 0
                 else SetUpCount[1], 1);
def setup9 = setupcount == 9;

plot Count = if SetUpCount == 0 or
                SetUpCount == SetUPCount[1] or
                SetUpCount > 9
             then double.nan
             else SetUpCount;
     Count.SetPaintingStrategy(PaintingStrategy.Values_Above);
     Count.Setdefaultcolor(color.cyan);

Def lowInPeriod = if SetUpCount == 9 then Lowest(low, 9) else double.nan;
plot low = lowInPeriod;
low.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


reply to post21 , fateownzyou
not sure if the poster is still around, but thought someone would find this interesting


this draws lines, at the lowest price, in each series of numbers.

the original study creates sequential numbers and plots them above the bars.
the count can run up to 9, but may stop at a smaller number.

this looks for bars with a count = 1, then looks ahead for the lowest low, on the bars with a count number, in the same sequence.
it draws the line until the next series line. (i didn't make it stop drawing)

after the numbers stop,
if a low goes below the line, a yellow arrow is drawn
if close crosses below the line, a red arrow is drawn


there are 2 different methods for plotting the lines, to make the horizontal and separate from the next line.
alt_plot , is used to choose 1 of them.
no = plot gray lines, using (PaintingStrategy.HORIZONTAL). without this, a diagonal line would connect all the lines.
yes = plot yellow and cyan lines. count the quantity of lines. plot odd/even in alternating colors. use 2 plots so the lines are separate, not connected by a diagonal line.


Ruby:
# SequenceCounter_lines_1

def bn = BarNumber();
def na = Double.NaN;
input alt_plot = no;

def SetUpCount = CompoundValue(1, if close > close[4]
                 then SetUpCount[1] + 1
                 else if close < close[4]
                 then 0
                 else SetUpCount[1], 1);
def setup9 = SetUpCount == 9;

plot Count = if SetUpCount == 0 or
                SetUpCount == SetUpCount[1] or
                SetUpCount > 9
             then Double.NaN
             else SetUpCount;
Count.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
Count.SetDefaultColor(Color.CYAN);

def lowInPeriod = if SetUpCount == 9 then Lowest(low, 9) else Double.NaN;
plot low2 = lowInPeriod;
low2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);


# if count = 1 then look for 9 or 0, end of series
def n1 = 80;
def lastoffset;
def serieslastbn;
def low3;
if bn == 1 or IsNaN(close) then {
  lastoffset = na;
  serieslastbn = na;
  low3 = na;

} else if Count == 1 then {
# look for 9 or 0 , end of series
lastoffset = fold i = 1 to n1
  with p
  while (GetValue(SetUpCount, -i) <> 0 and GetValue(SetUpCount, -i) <> 9)
  do p + 1;

serieslastbn = bn + lastoffset;

low3 = fold k = 0 to (serieslastbn - bn + 1)
  with q = 999999
  do Min(GetValue(low, -k), q);

} else {
  lastoffset = lastoffset[1];
  serieslastbn = serieslastbn[1];
  low3 = low3[1];
}


# cancel up trend , sell
# draw red down arrow, when price cosses below the  line
def upsell = if bn == 1 then 0 else if close crosses below low3 then 1 else 0;
plot upcancel = if upsell then high * 1.001 else na;
upcancel.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
upcancel.SetDefaultColor(Color.RED);
upcancel.SetLineWeight(2);
upcancel.HideBubble();

# warn up trend
# draw red down arrow, when price cosses below the  line
def upwarn = if bn == 1 then 0 else if (!upsell and close > low3 and low < low3 and high > low3) then 1 else 0;
plot upwarn2 = if upwarn then high * 1.001 else na;
upwarn2.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
upwarn2.SetDefaultColor(Color.yellow);
upwarn2.SetLineWeight(2);
upwarn2.HideBubble();


plot zz = if !alt_plot then low3 else na;
zz.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zz.SetDefaultColor(Color.LIGHT_GRAY);


#-------------------------------------------

input test1 = no;
#addchartbubble(1, low(), 
AddChartBubble(test1, low * 0.995, 
bn + " bn\n" +
SetUpCount + "\n" +
Count + "\n" +
lowInPeriod + "\n" +
 lastoffset + " off\n" +
 serieslastbn + " bn"
, Color.YELLOW, no);
#



# alt to using  (PaintingStrategy.HORIZONTAL)
# alternate between 2 plots , to draw separate , horz lines
# count the lines and determine when cnt is even
def linecnt = if bn == 1 then 0 else if IsNaN(low3[1]) then 0 else if low3 <> low3[1] then linecnt[1] + 1 else linecnt[1];
def iscnteven = if linecnt % 2 == 0 then 1 else 0;

#input alt_plot = no;
plot z1 = if alt_plot and iscnteven then low3 else na;
plot z2 = if alt_plot and !iscnteven then low3 else na;
z1.SetDefaultColor(Color.yellow);
z2.SetDefaultColor(Color.cyan);

#AddChartBubble(0, low, 
#low3 + "\n" +
#linecnt + "\n" +
#iscnteven
#, Color.YELLOW, no);
#


horizontal lines from bars with a #1, until the next 1
line price is low of bars with a count #
na55cQk.jpg



similar arrow code, in the 3 bar net line
this has code that stops drawing a line when crossed
https://usethinkscript.com/threads/help-coding-joseph-stowell-3-bar-net-cup-cap.5746/#post-99787
post10
 
@MoreFunn those scans cannot be modified but have a look at the counter studies in post#3; perhaps one of them can help you?
Hi MerryDay,

I got the study below from this forum but I can't find who created it. I like it because it only shows the 8, 9 and 13 values. I have been trying to get labels to show when the above values occur but I can't figure it out. Could you provide some guidance?

Thank you in advance!!!

DeMark Buy Sell Alerts"

# seqcnt_00

def na = double.nan;

def t1 = SequenceCounter()."Buy Formation";
def t2 = SequenceCounter()."Sell Formation";
def t3 = SequenceCounter()."Buy Array";
def t4 = SequenceCounter()."Sell Array";
def t5 = SequenceCounter()."Perfect Buy";
def t6 = SequenceCounter()."Perfect Sell";
def t7 = SequenceCounter()."Perfect Array Buy";
def t8 = SequenceCounter()."Perfect Array Sell";

input show_test_labels = no;
addlabel(show_test_labels , "seq1 " + t1, color.cyan);
addlabel(show_test_labels , "seq2 " + t2, color.cyan);
addlabel(show_test_labels , "seq3 " + t3, color.cyan);
addlabel(show_test_labels , "seq4 " + t4, color.cyan);
addlabel(show_test_labels , "seq5 " + t5, color.cyan);
addlabel(show_test_labels , "seq6 " + t6, color.cyan);
addlabel(show_test_labels , "seq7 " + t7, color.cyan);
addlabel(show_test_labels , "seq8 " + t8, color.cyan);

# t1 - lower white
# t2 - upper white
# t3 - lower red
# t4 - uper red

# keep 8, 9, and 13 , ignore other numbers
plot u1 = if t1 == 8 or t1 == 9 or t1 == 13 then t1 else na;
plot u2 = if t2 == 8 or t2 == 9 or t2 == 13 then t2 else na;
plot u3 = if t3 == 8 or t3 == 9 or t3 == 13 then t3 else na;
plot u4 = if t4 == 8 or t4 == 9 or t4 == 13 then t4 else na;

u1.SetPaintingStrategy(PaintingStrategy.VALUES_below);
u1.SetDefaultColor(Color.white);
u1.hidebubble();

u2.SetPaintingStrategy(PaintingStrategy.VALUES_above);
u2.SetDefaultColor(Color.white);
u2.hidebubble();

u3.SetPaintingStrategy(PaintingStrategy.VALUES_below);
u3.SetDefaultColor(Color.red);
u3.hidebubble();

u4.SetPaintingStrategy(PaintingStrategy.VALUES_above);
u4.SetDefaultColor(Color.red);
u4.hidebubble();

# LABELS
# Array

def BuyArray_13 = SequenceCounter()."Buy Array";
def SellArray_13 = SequenceCounter()."Sell Array";

def BuyArray = BuyArray_13 == 13;
def SellArray = SellArray_13 == 13;

AddLabel(BuyArray or SellArray, "DM.Array:13", If BuyArray then Color.DARK_GREEN else if SellArray then Color.RED else Color.Gray);

Alert(BuyArray, "BUY Array =13",Alert.BAR,Sound.Chimes);
Alert(SellArray, "SELL Array=13",Alert.BAR,Sound.Ding);


# Formation

def BuyFormation_9 = SequenceCounter()."Buy Formation";
def SellFormation_9 = SequenceCounter()."Sell Formation";

def BuyFormation = BuyFormation_9 == 9;
def SellFormation = SellFormation_9 == 9;

AddLabel(BuyFormation or SellFormation, "DM.Formation:9", If BuyFormation then Color.LIGHT_GREEN else if SellFormation then Color.MAGENTA else Color.Gray);

Alert(BuyFormation,"BUY Formation =9",Alert.BAR,Sound.Chimes);
Alert(SellFormation,"SELL Formation =9",Alert.BAR,Sound.Ding);

# Create a label that displays when a 9 or 13 is generated, with color coding


AddLabel(yes, if BuyArray then "DM:A.13" else if SellArray then "DM:A.13" else if BuyFormation then "DM:F.9" else if SellFormation then "DM:F.9" else "",
if BuyArray then Color.DARK_GREEN else if BuyFormation then Color.LIGHT_GREEN else if SellArray then Color.RED else if SellFormation then Color.MAGENTA else Color.GRAY);

# Create a label that displays when a 9 or 13 is generated, with color coding
AddLabel(yes, if BuyArray or BuyFormation then "9 or 13 BUY" else if SellArray or SellFormation then "9 or 13 SELL" else "",

if BuyArray then Color.LIGHT_GREEN else if BuyFormation then Color.GREEN else if SellArray then Color.PINK else if SellFormation then Color.MAGENTA else Color.GRAY);


# SequenceCounter
# https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/SequenceCounter
# plots
# Buy Formation Consists of "formation period" consecutive bars with: Close < Close[4 bars ago].
# Sell Formation Consists of "formation period" consecutive bars with: Close > Close[4 bars ago].
# Buy Array Displays "array period" bars satisfying the condition: Close <= Low[2 bars ago]
# Sell Array Displays "array period" bars satisfying the condition: Close >= High[2 bars ago]
# Perfect Buy Buy signals for Formation patterns meeting perfection criteria.
# Perfect Sell Sell signals for Formation patterns meeting perfection criteria.
# Perfect Array Buy Buy signals for Array patterns meeting perfection criteria.
# Perfect Array Sell Sell signals for Array patterns meeting perfection criteria.
#
 

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