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

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

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.
#
 
Did you check out the default SequenceCounter indicator in ThinkorSwim? If not, you should.

Here are a few custom DeMark Sequence indicators I found in the thinkScript lounge.

Mobius' Version

Code:
# TD Buy Setup and Countdown Sequence
# Mobius
# V02.  Fixed 0 plot error

# Once TD Setup is complete, TD Countdown can begin, from the close
# of bar nine of TD Setup (inclusive), onward.
# • TD Setup compares the current close with the corresponding close
# four bars earlier,
# Whereas
# • TD Countdown compares the current close with the low two bars
# earlier for a potential buy, and compares the current close with the
# high two bars earlier for a prospective sell. This price relationship is
# an important distinction from TD Setup, because the market must
# be trending for TD Countdown to objectively identify the likely
# exhaustion point for a trend reversal.
# The first bar of a TD Buy Countdown occurs when a TD Buy Setup is in place.
# ? To Initiate TD Buy Countdown
# After
# TD Buy Setup is in place, initiation of a TD Buy Countdown.
# If
# Bar nine of a TD Buy Setup also has a close less than, or equal to, the low two bars
# earlier.
# Then,
# Bar nine of a TD Buy Setup becomes bar one of a TD Buy Countdown.
# If
# That condition is not met,
# Then
# TD Buy Countdown bar one is postponed until it does, and the TD Buy Countdown
# continues until there are a total of thirteen closes, each one less than, or equal to, # the low two bars earlier.
# ? To Complete a TD Buy Countdown
# 1. The low of TD Buy Countdown bar thirteen must be less than, or equal to, the
# close of TD Buy Countdown bar eight, and
# 2. The close of TD Buy Countdown bar thirteen must be less than, or equal to, the
# low two bars earlier.
# TD Buy is Broken if Price does not exceed 1.5 times 9 bar ATR or
# price breaks down below entry Bar low.

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

plot Count = if SetUpCount == 0 or
                SetUpCount == SetUPCount[1] or
                SetUpCount > 9
             then double.nan
             else SetUpCount;
     Count.SetPaintingStrategy(PaintingStrategy.Values_Above);
def Setup1 = if SetUpCount == 9 and
                close <= low[2]
             then 1
             else if SetUpCount < 9
                  then 0
             else if SetUpCount > 9 and
                     close <= low[2]
                  then Setup1[1] + 1
             else Setup1[1];

def BuyPoint1 = if Setup1 >= 13
           then high
           else BuyPoint1[1];
plot BuyPoint1Line = if BuyPoint1 > 0 then BuyPoint1 else Double.NaN;
     BuyPoint1Line.SetPaintingStrategy(PaintingStrategy.Dashes); 
def Bar8 = if SetUpCount == 8
           then BarNumber()
           else Bar8[1];
def Bar8close = if barNumber() == Bar8
              then close
              else Bar8close[1];
def Bar9 = if SetUpCount == 9
           then BarNumber()
           else Bar9[1];

def SetUp2 = if BarNumber() > Bar9 and
                low <= bar8close and
                close < low[2]
             then high
             else SetUp2[1];
plot BuyPoint2Line = highestAll(if isNaN(close[-1])
                             then SetUp2
                             else Double.NaN);
     BuyPoint2Line.SetPaintingStrategy(PaintingStrategy.Dashes);
plot BuyCross1 = close crosses above BuyPoint1;
     BuyCross1.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
     BuyCross1.SetDefaultColor(Color.Plum);
plot BuyCross2 = close crosses above SetUp2;
     BuyCross2.SetPaintingStrategy(PaintingStrategy.Boolean_Arrow_Up);
     BuyCross2.SetDefaultColor(Color.Green);
  
# End Code TD Buy Setup and Countdown Sequence

Here is another one, this is to be added as a Strategy.

Code:
# DeMark Sequence
# Mobius
# V003 012012

input count = 9;
input contracts = 2;

def o = open;
def h = high;
def l = low;
def c = close;

rec BuySwitch = if c[1] > c[5]
                then 1
                else if c[1] > c[4]
                then 0
                else BuySwitch[1];


rec BuyCountdown = fold i = 0 to 100
                   with p = if buyswitch == 1 then 1 else double.nan
                   while if BuySwitch[1] == 1 then 1 else double.nan
                   do if c[1] <= c[4]
                         then BuyCountdown[1] + 1
                         else if c[1] > c[4]
                         then double.nan
                         else BuyCountdown[1];

plot BuySequence = BuyCountdown;
BuySequence.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);

def BuyPoint = if BuySequence == count then c[1] else double.nan;

#AddOrder(type = OrderType.BUY_AUTO, condition = c > BuyPoint, price = open, tradeSize = contracts, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = concat("", o));
                
rec SellSwitch = if c[1] < c[5]
                then 1
                else if c[1] < c[4]
                then 0
                else SellSwitch[1];


rec SellCountdown = fold j = 0 to 100
                   with jp = if Sellswitch == 1 then 1 else double.nan
                   while if SellSwitch[1] == 1 then 1 else double.nan
                   do if c[1] <= c[4]
                         then SellCountdown[1] + 1
                         else if c[1] > c[4]
                         then double.nan
                         else SellCountdown[1];

plot SellSequence = SellCountdown;
SellSequence.SetPaintingStrategy(PaintingStrategy.VALUES_Below);

def SellPoint = if SellSequence == count then l[1] else double.nan;

#AddOrder(type = OrderType.Sell_AUTO, condition = c < SellPoint, price = open, tradeSize = contracts, tickcolor = Color.red, arrowcolor = Color.red, name = concat("", o));

# AddLabel(yes, concat("BuySwitch ", BuySwitch), color.white);
# AddLabel(yes, concat("BuyCountdown ", BuyCountdown), color.white);
# AddLabel(yes, concat("SellSwitch ", SellSwitch), color.white);
# AddLabel(yes, concat("SellCountdown ", SellCountdown), color.white);

Dilbert's Version

Code:
## OneNote Archive Name: Sequence Counter _Dilbert
## Archive Section:
## Suggested Tos Name: SequenceCounter_Dilbert
## Archive Date: 5.14.2018
## Archive Notes:

## "##" indicates an addition or adjustment by the OneNote Archivist

## Original Code Follows



#Dilbert_SC
# V1.5 - 021117 - Dilbert - Inputs to move arrows and bubbles
# V1.4 - 121316 - Dilbert - Make Length2 bubble color.cyan
# V1.3 - 121316 - Dilbert - Add 9 count support resistance line, and 13 count risk line.  Use same colors as vertical lines.
# V1.2 - 121016 - Dilbert - Use Length1/Length2 all the time instead of hardcode.
# V1.1 - 121016 - Dilbert - UT13Bar/DT13Bar only if UT13/DT13 == 1
# V1.0 - 121016 - Dilbert - 1st code cut, beta version still

# Posted by Amalia on 03.02.2018
#Hint Length1: Number of bars in setup
input Length1 = 9;
#Hint Length2: Number of bars in countdown
input Length2 = 13;
#Hint HorizontalLines: 1 == show, 0 == hide
input HorizontalLines = 1;
#Hint Bubbles: 1 == show, 0 == hide
input Bubbles = 1;
def H = high;
def L = low;
def C = close;
def BN = BarNumber();
def TS = TickSize();
input BubbleMult = 10;   # Move Bubble up/down
input ArrowMult = 50;  # Move Arrow up/down
#######################################################################################
#  Count to 9 with down trend
def DT9 = if C < C[4] then 1 else 0;
def DT9Sum = if DT9 == 0
then 0
else if DT9Sum[1] == Length1 and DT9 == 1  # if we reach 9 count to 9 again
then 1
else DT9Sum[1] + DT9;
#plot DT9Sum2 = DT9Sum;
def DT9Sum2 = DT9Sum;
plot DT9SumP = if DT9Sum != 0
              and DT9Sum < Length1 + 1
then DT9Sum
else Double.NaN;
DT9SumP.SetPaintingStrategy(paintingStrategy = PaintingStrategy.VALUES_BELOW);
DT9SumP.AssignValueColor(Color.WHITE);

######################################################################################
#
#  Count to 9 with up trend
def UT9X = if C > C[4] then 1 else 0;
def UT9 = if UT9X == 1
then 1
else if UT9X == 1
then 1
else 0;
def UT9Sum = if UT9 == 0
then 0
else if UT9Sum[1] == Length1 and UT9 == 1 # if we reach 9 count to 9 again
then 1
else UT9Sum[1] + UT9;
def UT9Sum2 = UT9Sum;
plot UT9SumP = if UT9Sum != 0
              and UT9Sum < Length1 + 1
then UT9Sum
else Double.NaN;
UT9SumP.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
UT9SumP.AssignValueColor(Color.WHITE);

#####################################################################################
# UT9Bar/DT9BAR logic
def DT9Bar = if DT9Sum == Length1 then BN else DT9Bar[1];
def UT9Bar = if UT9Sum == Length1 then BN else UT9Bar[1];
# Cancel the countdown if the opposite pattern is found
def DT9Active = if DT9Bar == BN then 1
           else if UT9Bar == BN then 0
                                else DT9Active[1];
def UT9Active = if UT9Bar == BN then 1
           else if DT9Bar == BN then 0
                                else UT9Active[1];
#####################################################################################
# 9 count trend lines
def UTH9 = if UT9Bar == BN then Highest(H,9) else UTH9[1];
def DTH9 = if DT9Bar == BN then Highest(H,9) else DTH9[1];
def UTL9 = if UT9Bar == BN then Lowest(L,9) else UTL9[1];
def DTL9 = if DT9Bar == BN then Lowest(L,9) else DTL9[1];          
plot UTH9P = if HorizontalLines then UTH9 else Double.NaN;
plot DTH9P = if HorizontalLines then DTH9 else Double.NaN;
plot UTL9P = if HorizontalLines then UTL9 else Double.NaN;
plot DTL9P = if HorizontalLines then DTL9 else Double.NaN;
UTH9P.SetDefaultColor(Color.Cyan);
DTH9P.SetDefaultColor(Color.Orange);
UTL9P.SetDefaultColor(Color.Cyan);
DTL9P.SetDefaultColor(Color.Orange);
#####################################################################################
# Count to 13 in down trend

def DT13 = if BN >= DT9Bar and DT9Active == 1 and C <= L[2] then 1 else 0;
def DT13Sum = if DT9Bar == BN
then DT13
else DT13Sum[1] + DT13;
def DT13SumP = if DT13Sum != 0
               and DT13Sum < Length2 + 1
               and DT13Sum != DT13Sum[1]
then DT13Sum
else Double.NaN;
AddChartBubble(DT13Sum != 0 and Bubbles == 1
           and DT13Sum < Length2 + 1
           and DT13Sum != DT13Sum[1], L - TS * BubbleMult, DT13Sum, if DT13Sum == Length2 then Color.Cyan else Color.GREEN, no);
#####################################################################################
#  Down Trend 13 risk line

def DT13LL;
def DT13LLBarRange;
if DT9Bar == BN
then {
DT13LL = L;
DT13LLBarRange = H - L;
}

else if DT9Active and DT13Sum <= 13 and DT13 == 1 and L < DT13LL[1]
then {
DT13LL = L;
DT13LLBarRange = H - L;
}
else {
DT13LL = DT13LL[1];
DT13LLBarRange = DT13LLBarRange[1];
};
plot DT13Risk = if HorizontalLines then DT13LL - DT13LLBarRange else Double.NaN;
DT13Risk.SetDefaultColor(Color.Green);

#####################################################################################
# Count to 13 in up trend
def UT13 = if BN >= UT9Bar and UT9Active == 1 and C >= H[2] then 1 else 0;
def UT13Sum = if UT9Bar == BN
then UT13
else UT13Sum[1] + UT13;

def UT13SumP = if UT13Sum != 0
               and UT13Sum < Length2 + 1
               and UT13Sum != UT13Sum[1]
then UT13Sum
else Double.NaN;
AddChartBubble(UT13Sum != 0 and Bubbles == 1
           and UT13Sum < Length2 + 1
           and UT13Sum != UT13Sum[1], H + TS * BubbleMult, UT13Sum, if UT13Sum == Length2 then Color.Cyan else Color.RED, yes);
#####################################################################################
#  Up Trend 13 risk line

def UT13HH;
def UT13HHBarRange;
if UT9Bar == BN
then {
UT13HH = H;
UT13HHBarRange = H - L;
}
else if UT9Active and UT13Sum <= Length2 and UT13 == 1 and H > UT13HH[1]
then {
UT13HH = H;
UT13HHBarRange = H - L;
}
else {
UT13HH = UT13HH[1];
UT13HHBarRange = UT13HHBarRange[1];
};
plot UT13Risk = if HorizontalLines then UT13HH + UT13HHBarRange else Double.NaN;
UT13Risk.SetDefaultColor(Color.Red);
#####################################################################################
# UT13Bar/DT13BAR logic
def DT13Bar = if DT13Sum == Length2 and DT13 == 1 then BN else DT13Bar[1];
def UT13Bar = if UT13Sum == Length2 and UT13 == 1 then BN else UT13Bar[1];
# Cancel the countdown if the opposite pattern is found
#def DT13Active = if DT9Bar == BN then 1
#           else if UT9Bar == BN then 0
#                                else DT13Active[1];
#def UT13Active = if UT9Bar == BN then 1
#           else if DT9Bar == BN then 0
#                                else UT13Active[1];
######################################################################################
#Perfect 9 down trend logic
plot P9Buy = if DT9Bar == BN and (L < L[2] and L < L[3] or L[1] < L[2] and L[1] < L[3])
            then L - TS * ArrowMult else Double.NaN;
P9Buy.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
P9Buy.AssignValueColor(Color.WHITE);
######################################################################################
######################################################################################
#Perfect 9 up trend logic
plot P9Sell = if UT9Bar == BN and (H > H[2] and high > high[3] or H[1] > H[2] and H[1] > high[3]) then H + TS * ArrowMult else Double.NaN;
P9Sell.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
P9Sell.AssignValueColor(Color.WHITE);

######################################################################################
#Perfect 13 down trend logic
plot P13Buy = if DT13Bar == BN and L <= C[5] then L - TS * ArrowMult else Double.NaN;

P13Buy.SetPaintingStrategy(PaintingStrategy.ARROW_Up);
P13Buy.AssignValueColor(Color.RED);
######################################################################################
#Perfect 13 up trend logic
plot P13Sell = if UT13Bar == BN and H >= C[5]then H + TS * ArrowMult else Double.NaN;
P13Sell.SetPaintingStrategy(PaintingStrategy.ARROW_Down);
P13Sell.AssignValueColor(Color.RED);

AddVerticalLine(DT9Bar == BN, "", Color.ORANGE, curve.SHORT_DASH);
AddVerticalLine(UT9Bar == BN, "", Color.Cyan, curve.SHORT_DASH);
AddVerticalLine(DT13Bar == BN, "", Color.Green, curve.SHORT_DASH);
AddVerticalLine(UT13Bar == BN, "", Color.Red, curve.SHORT_DASH);
Pls, Where can I find the new Dilbert's Version?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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