[英]How to get the high from a whole timeperiod in the past where one ema crossed above the other? Pinescript
我迫切需要你的帮助来解决我 2 天以来面临的问题。 我无法得到我想要的结果。 我确实想将蜡烛的高价存储在一个变量中以供以后使用,并在高点发生的地方画一条水平线。 问题是,我想要整个时期的高点(但不是最近的时期..),其中一个 ema 跨越另一个。 我想要从过去的高点到现在的高点,基本上是最后一次发生的时间:我希望我表达清楚,但更详细的,请看图片:
一个EMA跨越另一个EMA的过去时期的高点
然而,自从 emas 交叉后,我能够从当前时期获得价格:
GetHighestSince(condition, series=high) =>
var float highestValueSince = na
if condition or series > highestValueSince
highestValueSince := series
highestValueSince
不幸的是,这些数据不是我需要的。 我尝试使用 for 循环,但我无法得到我想要的。 我对编码仍然很陌生,并且很难理解每根蜡烛都在触发脚本的全新运行。 这对我来说太难了。 谢谢您的帮助!
我会这样做:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// @eldlr
//@version=5
indicator("Test", overlay=true)
emaGreen = ta.sma(close, 7)
emaRed = ta.sma(close, 30)
barsBack = ta.barssince(ta.crossover(emaGreen, emaRed))
// this needs to be increased by 1 because the evaluation trigger condition can only be true on a latter bar
highestOffset = ta.highestbars(high, nz(barsBack) + 1)
var int highestBar = na
// your period is over, offset is final
if ta.crossunder(emaGreen, emaRed)
// if offset 0 we need to reduce it by 1 in order to exclude current candle after condition close
highestBar := bar_index + (highestOffset == 0 ? -1 : highestOffset)
label.new(highestBar, high, "Highest " + str.tostring(highestOffset), yloc = yloc.abovebar)
plot(emaGreen, color = color.green )
plot(emaRed, color = color.red)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.