如何访问最后一个指标值 [英] How to access the last indicator values
本文介绍了如何访问最后一个指标值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个显示枢轴点的指标:
I've got an indicator which shows pivot points:
//@version=4
study("Trend", overlay=false)
leftBars = input(3)
rightBars = input(3)
ph = pivothigh(high, leftBars, rightBars)
pl = pivotlow(low, leftBars, rightBars)
如何检查最后一个 ph 值是否高于之前的 ph 值?(我想检查上升趋势或下降趋势)
How can I check if the last ph was higher than the ph before? (I'd like to check for an uptrend or downtrend)
推荐答案
您可以尝试以下代码(包括您的原始代码,如您所见):
You can try the following code (including your original, as you see):
//@version=4
study("Trend", overlay=false)
leftBars = input(3)
rightBars = input(3)
ph = pivothigh(high, leftBars, rightBars)
pl = pivotlow(low, leftBars, rightBars)
//INIT VARIABLES
var int ph_uptrend_flag = 0
var float ph_valid = 0
var float ph_valid_old = 1e99 // use any very high non meaningful number here for initialization only
ph_non_na = nz(ph,0) // stores 0's instead of na's for non-pivot-pointed bars
// re-calculate uptrend flag every time a new pivot comes in, otherwise keep last known value for uptrend flag
if ph_non_na != 0
ph_valid := ph_non_na
ph_uptrend_flag := ph_valid > ph_valid_old ? 1 : 0
ph_valid_old := ph_valid
else
ph_valid := ph_valid
ph_valid_old := ph_valid_old
//plot uptrend flag and mark background accordingly
plot(ph_uptrend_flag,title="ph uptrend indication",linewidth=4,color=color.white)
//plot(ph,title="ph value",color=color.lime,style=8) //plot ph values (better used with overlay=true)
这篇关于如何访问最后一个指标值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文