I'm not super familiar with the getValue function. It is always returning 1 in this case, is it because of the first argument? In the examples I've seen, the first argument is usually something like "close" or "high", e.g a value for that bar.
Ruby:def bn = BarNumber(); def cond = if close crosses above Average(close, 9) then bn else cond[1]; # this finds the highest barnumber , from a set of bars that have cond def last_cond_bn = HighestAll(cond); # read data from that bar, for example the high def last_cond_hi = GetValue(high, (bn - last_cond_bn)); AddLabel(1, last_cond_bn...
def bn = barnumber();
def cond = .....
# this finds the biggest barnumber , from a set of bars that have cond == 1
def last_cond_bn = highestAll( if cond == 1 then bn else 0);
#
# this is true on the last bar that cond is true
def islast_cond = (last_cond_bn == bn);
#
# read data from that bar
# i think this works...
def data = getvalue(cond, (bn - last_cond_bn) );
#
you can use highestall( ) to find the biggest barnumber for the bar that the condition is true. you can put an if-then in a highestall( )
Code:def bn = barnumber(); def cond = ..... # this finds the biggest barnumber , from a set of bars that have cond == 1 def last_cond_bn = highestAll( if cond == 1 then bn else 0); # # this is true on the last bar that cond is true def islast_cond = (last_cond_bn == bn); # # read data from that bar # i think this works... def data = getvalue(cond, (bn - last_cond_bn) ); #
I'm not super familiar with the getValue function. It is always returning 1 in this case, is it because of the first argument? In the examples I've seen, the first argument is usually something like "close" or "high", e.g a value for that bar.
Ruby:def bn = BarNumber(); def cond = if close crosses above Average(close, 9) then bn else cond[1]; # this finds the highest barnumber , from a set of bars that have cond def last_cond_bn = HighestAll(cond); # read data from that bar, for example the high def last_cond_hi = GetValue(high, (bn - last_cond_bn)); AddLabel(1, last_cond_bn + " " + last_cond_hi, Color.WHITE); #
def MACDValleyPrice = If(!IsNaN(MACDValley[0]), Lowest(low[-1], maxLookback4Price + 1), Double.NaN);
AddChartBubble(MACDValleyPrice && !lowerWindow, MACDValleyPrice, "bar " + barnumber() + " low" + MACDValleyPrice, Color.PINK, no);
Lowest(low[-1], maxLookback4Price + 1)
# this finds the highest barnumber , from a set of bars that have cond
def last_cond_bn = HighestAll(cond);
Cre8able,thanks. I was looking at he wrong version above. One gives a bar number and the other gives a price. I was using the wrong one
thanks
here is a post from robert p. , with some examples.Cre8able,
would it be possible to share the complete version of the code you got to work for finding bar that met a specific condition?
regards,
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
H | Future bars - find Highest price and lowest price | Questions | 2 | |
T | How t o find 4th highest close in last 100 bars? | Questions | 7 | |
S | Indicators to find increasing Open interest and volume | Questions | 4 | |
T | Where can I find all scans? | Questions | 2 | |
M | pls help me find this script | Questions | 1 |
Start a new thread and receive assistance from our community.
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.
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.