Reputation: 186
I would like to get the highest value between 2 bars with bar index
say I have 2 bar index 100 and 150. I would like to get the highest value between these 2 candles.
How would I do so?
Upvotes: 0
Views: 2059
Reputation: 1043
This can be done easily as follows, let's denote your first bar index as a
and the second one as b
where a < b
, the highest value within that range can be computed as follows:
highest = highest(close,b-a)
val = valuewhen(bar_index==b,highest,0)
with val
returning the maximum value in range [a,b]
. You can get the lowest value using the function lowest
instead of highest
.
In the case you want to find the highest value within two occurrences, you can use:
max = 0.
ma20 = sma(close,20)
ma50 = sma(close,50)
max := crossover(ma20,ma50) or crossunder(ma20,ma50) ? close : max(close,max[1])
here max
is the current highest value, and reset when one of the conditions is true.
Upvotes: 1