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) : 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)
解决方案
//@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)
推荐阅读
- mongodb - 如何在 mongo shell 中打印带有数字名称的字段?
- java - 在android studio上制作的应用程序没有在我的an中打开
- javascript - 使用受控状态更新反应表单
- algorithm - 如何设置hashtable的阈值,避免频繁rehash?
- magento - Magento 2 REST API。列出具有父/子关系的产品
- tcp - erlang VM 占用大约 600 个 os/windows 机器线程
- javascript - 简单赋值帮助:调用函数向其传递参数并获取其返回值
- javascript - 异步方法返回未定义
- python - Extracting a numerical value from .csv files
- wordpress - 将自定义属性添加到联系表单本身(wordpress 插件)