首页 > 解决方案 > 如何获得两点之间的最小值?

问题描述

这是代码,注释来自原始脚本(如何找到两点之间的最大值)。现在两点之间的最小值是......零,我看不出它背后的逻辑。

//@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)

标签: pine-script

解决方案


//@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)

推荐阅读