如何获得2点之间的最高值? [英] How to get the highest value between 2 points?

查看:57
本文介绍了如何获得2点之间的最高值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得 2 个条目之间的最高点(例如 2 个 ema 十字架之间,如图像示例).这超出了我的头脑,我尝试了 barssince() 没有运气.欢迎任何帮助!

I want to get the highest point between 2 entries (ex. between 2 ema crosses, like the image example). It's over my head, I tried with barssince() without luck. Any help would be welcomed!

//@version=4
study("My Script", overlay = true)

ema1 = ema(close, 20)
ema2 = ema(close, 50)
plot(ema1)
plot(ema2, color = color.yellow)

buy = crossover(ema1, ema2)
sell = crossunder(ema1, ema2)

highest_buy = highestbars(high, barssince(buy))

plot(highest_buy)

推荐答案

sell信号出现highest_buy等于na且标签为不显示.有必要取前一个柱上的值.

When sell signal appears highest_buy is equal na and the label is not displayed. It is necessary to take the values on the previous bar.

//@version=4

study("Help prof (My Script)", overlay = true)

var bool    track       = false
var float   highest_buy = na

ema1 = ema(close, 20)
ema2 = ema(close, 50)

buy  = crossover(ema1, ema2)
sell = crossunder(ema1, ema2)

if buy
    track := true
else if sell
    track := false

highest_buy := track ? max(nz(highest_buy), high) : na

plot(ema1)
plot(ema2,        color=color.yellow)
plot(highest_buy, color=color.purple, style=plot.style_linebr)

buy_entry = valuewhen(buy, close, 0)
plot(buy_entry, color = buy_entry == buy_entry[1] and ema1 > ema2? color.lime :na)

if sell 
    label1 = label.new(bar_index, highest_buy[1], text=tostring(highest_buy[1] - buy_entry[1]) , style=label.style_label_down, color=color.black, textcolor=color.white)

这篇关于如何获得2点之间的最高值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆