This is the code, comments are from the original script (how to find the highest value between two points). Right now the lowest value between two points is...zero and I can't see the logic behind it.
//@version=4
study("Help prof (My Script)", overlay = true)
var bool track = false
var float highest_sell = 10e10 //from highest_buy = na
ema1 = ema(close, 20)
ema2 = ema(close, 50)
buy = crossover(ema1, ema2)
sell = crossunder(ema1, ema2)
if sell
track := true
else if buy
track := false //from buy track = true and sell track = false
highest_sell := track ? min(nz(highest_sell), low) : na //from highest_buy := track ? ma(nz(highest_buy), high) : na
plot(ema1)
plot(ema2, color=color.yellow)
plot(highest_sell, color=color.purple, style=plot.style_linebr)
sell_entry = valuewhen(sell, close, 0)
plot(sell_entry, color = sell_entry == sell_entry[1] and ema1 < ema2? color.lime :na)
if buy
label1 = label.new(bar_index, highest_sell[1], text=tostring(highest_sell[1] - sell_entry[1]) , style=label.style_label_up, color=color.black, textcolor=color.white)