如何在 pine 脚本中以特定价格或时间范围获取 atr 值?
how to get atr value at particular price or time frame in pine script?
如果我们想看到 atr,我们可以绘制它会显示的任何证券的 atr 图
//@版本=4
学习("My Script")
情节(atr(14))
但是如果我想在这种情况下以编程方式计算特定价格的 atr 值
我想计算前一个枢轴低点的 atr 值,然后如何在松树中得到它?
请帮忙
假设在这张图表中,当我们将鼠标移到它上面时,5152.45 atr 的枢轴低点是 76.65,它显示了如何将其变成松树
谢谢
当您的脚本检测到您要从中保存 ATR 的条件时,您需要保存该值。理解 Pine's execution model 将帮助您概念化解决方案,这在编写脚本时经常出现。 Pine 脚本在每个柱上执行,因此只要有可能,在后续柱上保存您需要的值,而不是等到您需要这些值的那一刻,然后回头寻找它们,效率要高得多。
//@version=4
study("Atr at Pivot")
pivotLegs = 3
pHi = pivothigh(pivotLegs, pivotLegs)
atr = atr(14)
var float atrAtHiPivot = na
if not na(pHi)
// A pivot was detected. Since the pivot actually occurred `pivotLegs` bars back,
// fetch atr value from the same number of bars back.
atrAtHiPivot := atr[pivotLegs]
plotchar(not na(pHi), "not na(pHi)", "▼", location.top)
plot(atrAtHiPivot, "atrAtHiPivot")
plot(atr, "atr", color.aqua)
//@version=4
study("Atr at Pivot")
pivotLegs = 3
pHi = pivothigh(pivotLegs, pivotLegs)
atr = atr(14)
var float atrAtHiPivot = na
var float atrAtLoPivot = na
pLo = pivotlow(pivotLegs, pivotLegs)
if not na(pHi)
// A pivot was detected. Since the pivot actually occurred `pivotLegs` bars back,
// fetch atr value from the same number of bars back.
atrAtHiPivot := atr[pivotLegs]
//curious
if not na(pLo)
atrAtLoPivot := atr[pivotLegs]
plotchar(not na(pHi), "not na(pHi)", "▼", location.top)
plot(atrAtHiPivot, "atrAtHiPivot")
plot(atr, "atr", color.aqua)
//curious
plotchar(not na(pLo), "not na(pLo)", "▲", location.bottom)
plot(atrAtLoPivot,"atrAtLoPivot")
plot(atr,"atr",color.red)
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/Jdvdq.jpg
如果我们想看到 atr,我们可以绘制它会显示的任何证券的 atr 图
//@版本=4 学习("My Script")
情节(atr(14))
但是如果我想在这种情况下以编程方式计算特定价格的 atr 值
我想计算前一个枢轴低点的 atr 值,然后如何在松树中得到它?
请帮忙
假设在这张图表中,当我们将鼠标移到它上面时,5152.45 atr 的枢轴低点是 76.65,它显示了如何将其变成松树 谢谢
当您的脚本检测到您要从中保存 ATR 的条件时,您需要保存该值。理解 Pine's execution model 将帮助您概念化解决方案,这在编写脚本时经常出现。 Pine 脚本在每个柱上执行,因此只要有可能,在后续柱上保存您需要的值,而不是等到您需要这些值的那一刻,然后回头寻找它们,效率要高得多。
//@version=4
study("Atr at Pivot")
pivotLegs = 3
pHi = pivothigh(pivotLegs, pivotLegs)
atr = atr(14)
var float atrAtHiPivot = na
if not na(pHi)
// A pivot was detected. Since the pivot actually occurred `pivotLegs` bars back,
// fetch atr value from the same number of bars back.
atrAtHiPivot := atr[pivotLegs]
plotchar(not na(pHi), "not na(pHi)", "▼", location.top)
plot(atrAtHiPivot, "atrAtHiPivot")
plot(atr, "atr", color.aqua)
//@version=4
study("Atr at Pivot")
pivotLegs = 3
pHi = pivothigh(pivotLegs, pivotLegs)
atr = atr(14)
var float atrAtHiPivot = na
var float atrAtLoPivot = na
pLo = pivotlow(pivotLegs, pivotLegs)
if not na(pHi)
// A pivot was detected. Since the pivot actually occurred `pivotLegs` bars back,
// fetch atr value from the same number of bars back.
atrAtHiPivot := atr[pivotLegs]
//curious
if not na(pLo)
atrAtLoPivot := atr[pivotLegs]
plotchar(not na(pHi), "not na(pHi)", "▼", location.top)
plot(atrAtHiPivot, "atrAtHiPivot")
plot(atr, "atr", color.aqua)
//curious
plotchar(not na(pLo), "not na(pLo)", "▲", location.bottom)
plot(atrAtLoPivot,"atrAtLoPivot")
plot(atr,"atr",color.red)
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/Jdvdq.jpg