REF post #1
i must be missing something. i tried to put your code in a chart and add a loop at the end, but it causes errors on c = ask.
i added this in, which used to work in another study, but not now , this causes an error too ?
def bid1 = close(priceType = "Bid");
def ask1 = close(priceType = "Ask");
maybe tos changed how to read bid and ask in a chart ?
i added a fold loop after your code, to look at previous bars, to find when tot had a value greater than totminvalue.
i changed c =ask , to c = close
# copied form my engulfing code, posted on here somewhere
input lookback = 100;
def totminvalue = 5;
# i have no idea what this should be. just a guess
# if while is used, fold loops as long as while statement is true
# when while becomes false, the loop stops, even if fold hasn't reached the highest count value
def barcnt = fold k = 1 to (lookback + 1)
with p
# this looks for smaller bars before the current bar
# while (high > getvalue(high, k) and low < getvalue(low, k))
while ( getvalue(tot, k) < totminvalue )
do p + 1;
# barcnt will = the offset # , pointing back to the bar with the desired value of tot
def prev_tot = if barcnt < lookback then getvalue( tot, barcnt ) else 0;
def bn = barnumber();
# display some variables for debugging
addchartbubble(1, low, bn + "\n" + tot + "\n" + barcnt + "\n" + prev_tot, color.yellow, no);
================================================
if i replace def c = ask;
with this def c = close;
it doesn't have errors
it looks like tot has values of 1 or 2
here is my modified code, using close, instead of ask
Ruby:
def bn = BarNumber();
# lines_bidask_00
def bid1 = close(priceType = "Bid");
def ask1 = close(priceType = "Ask");
def Mark1 = close(priceType = "Mark");
def Last1 = close(priceType = "Last");
def opicka = open[1];
def zachodik = close[1];
#calculate 50% of candle
def midik = (opicka + zachodik) / 2;
#measure range of yesterday
def rangik = (zachodik - opicka) / opicka * 100;
def ran = if rangik < 8 then 0 else 10;
#compare last price with midcandle
#def c = ask;
#def porovnavacka = (ask / midik - 1) * 100;
#def c = ask1;
def c = close;
def porovnavacka = ( c / midik - 1) * 100;
#3 conditions..best result is 3 false
def condition1 = porovnavacka > 0;
def condition2 = porovnavacka < 3;
def condition3 = ran == 10;
def fin = if condition3 then 8 else 0;
def tot = condition1 + condition2 + fin;
#plot z = tot;
# this shows errors for tot on all bars
#addchartbubble(1, low, tot , color.yellow, no);
# this has good values
#addchartbubble(1, low, "O " + opicka + "\n" + "c " + zachodik + "\n" + "m " + midik, color.yellow, no);
# cond1 and 2 have n/a errors
#addchartbubble(1, low, "1 " + condition1 + "\n" + "2 " + condition2 + "\n" + "3 " + condition3 , color.yellow, no);
#addchartbubble(1, low, "c " + c + "\n" + "p " + porovnavacka , color.yellow, no);
# ------------------------------------
# copied form my engulfing code, posted on here somewhere
input lookback = 100;
def totminvalue = 5;
# i have no idea what this should be. just a guess
# if while is used, fold loops as long as while statement is true
# when while becomes false, the loop stops, even if fold hasn't reached the highest count value
def barcnt = fold k = 1 to ( lookback + 1)
with p
# this looks for smaller bars before the current bar
# while (high > getvalue(high, k) and low < getvalue(low, k))
# this compares prev values of tot to the constant, totminvalue.
# it keeps looping as long as tot is smaller.
# if tot is bigger, the loop stops , and p value is transferred to barcnt,
while ( getvalue(tot, k) < totminvalue )
do p + 1;
# barcnt will = the offset # , pointing back to the bar with the desired value of tot
def prev_tot = if barcnt < lookback then getvalue( tot, barcnt ) else 0;
#def bn = barnumber();
# display some variables for debugging
addchartbubble(1, low, bn + "\n" + tot + "\n" + barcnt + "\n" + prev_tot, color.yellow, no);