DeMark 9 For ThinkOrSwim

Code:
# demark9_01

#addlabel(1, "demark9_0", color.white);

# https://usethinkscript.com/threads/convert-tradingview-demark-9.11212/
#Convert Tradingview DeMark 9

#//DeMark_9_Indicator_Wealth_Insider
#study("DeMark9 Indicator",overlay=true)
#TD = close > close[4] ?nz(TD[1])+1:0
#TS = close < close[4] ?nz(TS[1])+1:0
#TDUp = TD - valuewhen(TD < TD[1], TD , 1 )
#TDDn = TS - valuewhen(TS < TS[1], TS , 1 )
#plotshape(TDUp==7?true:na,style=shape.triangledown,text="7",color=green,location=location.abovebar)
#plotshape(TDUp==8?true:na,style=shape.triangledown,text="8",color=green,location=location.abovebar)
#plotshape(TDUp==9?true:na,style=shape.triangledown,text="??",color=green,location=location.abovebar)
#plotshape(TDDn==7?true:na,style=shape.triangleup,text="7",color=red,location=location.belowbar)
#plotshape(TDDn==8?true:na,style=shape.triangleup,text="8",color=red,location=location.belowbar)
#plotshape(TDDn==9?true:na,style=shape.triangleup,text="?",color=red,location=location.belowbar)

#------------------------------
input bubbles_on = yes;
# ------------------------------

script ValueWhen {
# look for a previous occurance of a value, and return the value of a diff var
#  valuewhen(condition, return_var, nth occurrence)
#  nth occurrence, original pine code starts n at 0, so 1 is the 2nd
input cond = 0;
input pr = 0;
input n2 = 0;

def n = n2 + 1;
# start at 0 so it looks at current bar
def offset2 = fold j = 0 to 200
with p
while p < n + 1
do p + ( if p == n then j-n else if getvalue(cond, j) then 1 else 0 );
# def bnz = bn - offset2 + 1;
plot price = getvalue(pr, offset2-1);
plot offset = offset2;
}


#-------------------------------
script nz {
# test if number is valid
input a = 0;
def b = if isnan(a) then 0 else a;
plot c = b;
};
#-------------------------------

def bn = barnumber();
input prev_n_cond = 1;
#addlabel(1, "prev n cond " +  prev_n_cond, color.yellow);

#TD = close > close[4] ?nz(TD[1])+1:0
#TS = close < close[4] ?nz(TS[1])+1:0

def td_cls4 = close > close[4];
def ts_cls4 = close < close[4];

def TD = if close > close[4] then nz(TD[1])+1 else 0;
def TS = if close < close[4] then nz(TS[1])+1 else 0;


#  valuewhen(condition, return_price, nth occurrence)
#  n starts at 0, so 1 would be the 2nd prev occurance
#TDUp = TD - valuewhen(TD < TD[1], TD , 1 )
#TDDn = TS - valuewhen(TS < TS[1], TS , 1 )
def td1 = TD < TD[1];
def ts1 = TS < TS[1];
def td_vw = valuewhen(TD1, TD , prev_n_cond).price;
def ts_vw = valuewhen(TS1, TS , prev_n_cond).price;

#def TDUp = TD - valuewhen(TD1, TD , prev_n_cond);
#def TDDn = TS - valuewhen(TS1, TS , prev_n_cond);

plot TDUp = TD - td_vw;

plot TDDn = TS - ts_vw;




#plotshape(TDUp==7?true:na,style=shape.triangledown,text="7",color=green,location=location.abovebar)
addchartbubble( (bubbles_on and tdup >= 7 and tdup <= 9), high, tdup, color.green, yes);
#plotshape(TDDn==7?true:na,style=shape.triangleup,text="7",color=red,location=location.belowbar)
addchartbubble( (bubbles_on and tddn >= 7 and tddn <= 9), low, tddn, color.red, no);

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

def pr = valuewhen(TD1, TD , prev_n_cond).price;
def off = valuewhen(TD1, TD , prev_n_cond).offset;
#def pr2 = getvalue(td, off-1);


#def td_vw = valuewhen(TD1, TD , prev_n_cond);
input test1 = no;
addchartbubble(test1, (if td1 or td_cls4 then high*1.004 else low*0.996),
td1 + " td1\n" +
bn + " bn\n" +
pr + " pr\n" +
off + " off\n" +
(bn - off + 1) + " prev\n" +
" " + "\n" +
td_cls4 + " cls4\n" +
td + " td\n" +
td1 + " td1\n" +
td_vw + "\n" +
tdup + " tdup\n"
#pr2 + " pr2\n"
#close + " cls\n" +
#close[4] + " cls4"
, (if td1 then color.cyan else color.gray)
, (if td1 or td_cls4 then yes else no));
#


Your errors are not possible if you followed the directions.

1. copy & paste the study from https://usethinkscript.com/threads/demark-9-for-thinkorswim.11212/#post-99312
2. how to copy & paste: https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/


To create a scan:

replace these lines of code:

with these:


scan condition is:

or


Here is a tutorial for how to set up your scan condition in the scan hacker:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/

It is not possible to say where you went astray.
A wild guess would be that you ADDED the code instead of REPLACING the code.
I hope to scan for the 9. I tried substituting the lines of code and got the error that addlabel was not allowed in this context so I hashtagged out the addlabel (I have no idea what i am doing just tried something) and now i have the one plot expected error.

@MerryDay would you mind referencing which version of code I should use for the scan (which post) bc ppl are asking for adjustments to arrows and bubbles and I have no interest in that just want to scan for the 9.

thank you and I am sorry I couldnt substitute the code successfully.
 
Code:
# demark9_01

#addlabel(1, "demark9_0", color.white);

# https://usethinkscript.com/threads/convert-tradingview-demark-9.11212/
#Convert Tradingview DeMark 9

#//DeMark_9_Indicator_Wealth_Insider
#study("DeMark9 Indicator",overlay=true)
#TD = close > close[4] ?nz(TD[1])+1:0
#TS = close < close[4] ?nz(TS[1])+1:0
#TDUp = TD - valuewhen(TD < TD[1], TD , 1 )
#TDDn = TS - valuewhen(TS < TS[1], TS , 1 )
#plotshape(TDUp==7?true:na,style=shape.triangledown,text="7",color=green,location=location.abovebar)
#plotshape(TDUp==8?true:na,style=shape.triangledown,text="8",color=green,location=location.abovebar)
#plotshape(TDUp==9?true:na,style=shape.triangledown,text="??",color=green,location=location.abovebar)
#plotshape(TDDn==7?true:na,style=shape.triangleup,text="7",color=red,location=location.belowbar)
#plotshape(TDDn==8?true:na,style=shape.triangleup,text="8",color=red,location=location.belowbar)
#plotshape(TDDn==9?true:na,style=shape.triangleup,text="?",color=red,location=location.belowbar)

#------------------------------
input bubbles_on = yes;
# ------------------------------

script ValueWhen {
# look for a previous occurance of a value, and return the value of a diff var
#  valuewhen(condition, return_var, nth occurrence)
#  nth occurrence, original pine code starts n at 0, so 1 is the 2nd
input cond = 0;
input pr = 0;
input n2 = 0;

def n = n2 + 1;
# start at 0 so it looks at current bar
def offset2 = fold j = 0 to 200
with p
while p < n + 1
do p + ( if p == n then j-n else if getvalue(cond, j) then 1 else 0 );
# def bnz = bn - offset2 + 1;
plot price = getvalue(pr, offset2-1);
plot offset = offset2;
}


#-------------------------------
script nz {
# test if number is valid
input a = 0;
def b = if isnan(a) then 0 else a;
plot c = b;
};
#-------------------------------

def bn = barnumber();
input prev_n_cond = 1;
#addlabel(1, "prev n cond " +  prev_n_cond, color.yellow);

#TD = close > close[4] ?nz(TD[1])+1:0
#TS = close < close[4] ?nz(TS[1])+1:0

def td_cls4 = close > close[4];
def ts_cls4 = close < close[4];

def TD = if close > close[4] then nz(TD[1])+1 else 0;
def TS = if close < close[4] then nz(TS[1])+1 else 0;


#  valuewhen(condition, return_price, nth occurrence)
#  n starts at 0, so 1 would be the 2nd prev occurance
#TDUp = TD - valuewhen(TD < TD[1], TD , 1 )
#TDDn = TS - valuewhen(TS < TS[1], TS , 1 )
def td1 = TD < TD[1];
def ts1 = TS < TS[1];
def td_vw = valuewhen(TD1, TD , prev_n_cond).price;
def ts_vw = valuewhen(TS1, TS , prev_n_cond).price;

#def TDUp = TD - valuewhen(TD1, TD , prev_n_cond);
#def TDDn = TS - valuewhen(TS1, TS , prev_n_cond);

plot TDUp = TD - td_vw;

plot TDDn = TS - ts_vw;




#plotshape(TDUp==7?true:na,style=shape.triangledown,text="7",color=green,location=location.abovebar)
addchartbubble( (bubbles_on and tdup >= 7 and tdup <= 9), high, tdup, color.green, yes);
#plotshape(TDDn==7?true:na,style=shape.triangleup,text="7",color=red,location=location.belowbar)
addchartbubble( (bubbles_on and tddn >= 7 and tddn <= 9), low, tddn, color.red, no);

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

def pr = valuewhen(TD1, TD , prev_n_cond).price;
def off = valuewhen(TD1, TD , prev_n_cond).offset;
#def pr2 = getvalue(td, off-1);


#def td_vw = valuewhen(TD1, TD , prev_n_cond);
input test1 = no;
addchartbubble(test1, (if td1 or td_cls4 then high*1.004 else low*0.996),
td1 + " td1\n" +
bn + " bn\n" +
pr + " pr\n" +
off + " off\n" +
(bn - off + 1) + " prev\n" +
" " + "\n" +
td_cls4 + " cls4\n" +
td + " td\n" +
td1 + " td1\n" +
td_vw + "\n" +
tdup + " tdup\n"
#pr2 + " pr2\n"
#close + " cls\n" +
#close[4] + " cls4"
, (if td1 then color.cyan else color.gray)
, (if td1 or td_cls4 then yes else no));
#



I hope to scan for the 9. I tried substituting the lines of code and got the error that addlabel was not allowed in this context so I hashtagged out the addlabel (I have no idea what i am doing just tried something) and now i have the one plot expected error.

@MerryDay would you mind referencing which version of code I should use for the scan (which post) bc ppl are asking for adjustments to arrows and bubbles and I have no interest in that just want to scan for the 9.

thank you and I am sorry I couldnt substitute the code successfully.

Your error is only possible if you attempted to stuff code into the scan hacker.
Please don't!
Please follow the directions in the scan tutorial:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/


1. copy & paste the study from https://usethinkscript.com/threads/demark-9-for-thinkorswim.11212/#post-99312
2. how to copy & paste: https://usethinkscript.com/threads/how-to-import-existing-thinkscript-code-on-thinkorswim.10/


To create a scan:

replace these lines of code:
def TDUp = TD - td_vw;
def TDDn = TS - ts_vw;
with these:
plot TDUp = TD - td_vw;
plot TDDn = TS - ts_vw;

scan condition is:
tdup == 9
or
tddn == 9

Here is a tutorial for how to set up your scan condition in the scan hacker:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/
 

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