0

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)
edward
  • 596
  • 1
  • 4
  • 11
  • Indeed, the absolute lowest value in math is 0, but according to your cci example, the min lowest value of cci is... the lowest value of it, obviously, but for a reason, does not work the same with `min(low, ...)` (it's working with `max(low, ...)`, but it's useless). – edward Jan 29 '21 at 13:55
  • With `cci` it works because the values are negative. I was once again convinced that there are no universal answers. – AnyDozer Jan 29 '21 at 14:23

1 Answers1

2
//@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) : 10e10      //from highest_buy := track ? ma(nz(highest_buy), high) : na

plot(ema1)
plot(ema2,        color=color.yellow)
plot(track ? highest_sell : na , 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)
AnyDozer
  • 2,236
  • 2
  • 5
  • 22