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