pivot - 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)
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)
推荐阅读
- php - 如何将多个变量传递给模态
- javascript - 如何在 javascript .scroll() 之后调用函数
- opencv - 当 CMatrix 转换为 slice 时,Go-vet 抱怨 unsafeptr
- python - 如何简化这个缩写词生成器?
- python - 如何开发自学习梯度提升分类器
- npgsql - Unix 秒中的 date_trunc 值,CrateDB
- javascript - 在nodejs中的其他函数中调用带有(req,res)的函数?
- javascript - 在使用 React-Transition-Group 在 React 中安装组件之前,更新状态发送给子级
- spartacus-storefront - 延迟加载问题 | 斯巴达克斯 2.0.0
- android - 在flutter中检测ViewWillAppear,每次小部件加载时调用Api函数