I’m trying to write a simple code to get the lowest price since a given high, and the highest price since a given low. In the code below I have hard coded the “given high” and “given low” but of course that will later be dynamic as part of a larger script.
The issue is, I have gotten it to work for “highest price since given low”, but the exact same code for “lowest price since given high” is not working.
Any help would be appreciated. Here is the code:
//@version=5
indicator("My script")
tmp_1 = ta.barssince(low == 19874.25)
tmp_2 = ta.highest(not na(tmp_1) and tmp_1 > 0 ? tmp_1 : 1)
l = label.new(bar_index, close, str.tostring(tmp_2), color=color.white, style=label.style_label_left)
label.delete(l[1])
plotchar(tmp_1, "tmp_1", display=display.data_window)
plotchar(tmp_2, "tmp_2", display=display.data_window)
//// Above code works perfectly fine if I comment out the code below
tmp_3 = ta.barssince(high == 20273.25)
tmp_4 = ta.lowest(not na(tmp_3) and tmp_3 > 0 ? tmp_3 : 1)
l2 = label.new(bar_index, close, str.tostring(tmp_4), color=color.white, style=label.style_label_right)
label.delete(l2[1])
plotchar(tmp_3, "tmp_3", display=display.data_window)
plotchar(tmp_4, "tmp_4", display=display.data_window)
I originally wanted simply highest_since_low = ta.highest(ta.barssince(19874.25)) but quickly realised that ta.highest needs int > 0. Hence the ternary code. Worked like a charm for the highest_since_low, so i’m completely perplexed by why its not working for lowest_since_high.
Of note, the “given high” will be fed to the script some time after it has formed, so I cannot have live calculation tracking the low since the high.