我使用hist来表示基于MACD指示器的直方图数据。
我正在尝试创建一个买入信号,当直方图是大于过去24天之前直方图数据的平均值的正数时,买入将被放置。
然而,直方图数据可以是正的也可以是负的,数字,无论是正的还是负的,都无关紧要,但我找不到比这更好的解决方案,但必须有。
目前我每天取hist * hist /2的倍数,然后除以整体。这看起来很笨拙和不必要,但我不知道另一种方法。
任何帮助都将不胜感激!
hist = macdDaily - signalDaily
histGreater24 = hist[0] > ((((hist[1] * hist[1]) / 2) + ((hist[2] * hist[2]) / 2) + ((hist[3] * hist[3]) / 2) + ((hist[4] * hist[4]) / 2) + ((hist[5] * hist[5]) / 2) + ((hist[6] * hist[6]) / 2) + ((hist[7] * hist[7]) / 2) + ((hist[8] * hist[8]) / 2) + ((hist[9] * hist[9]) / 2) + ((hist[10] * hist[10]) / 2) + ((hist[11] * hist[11]) / 2) + ((hist[12] * hist[12]) / 2) + ((hist[13] * hist[13]) / 2) + ((hist[14] * hist[14]) / 2) + ((hist[15] * hist[15]) / 2) + ((hist[16] * hist[16]) / 2) + ((hist[17] * hist[17]) / 2) + ((hist[18] * hist[18]) / 2) + ((hist[19] * hist[19]) / 2) + ((hist[20] * hist[20]) / 2) + ((hist[21] * hist[21]) / 2) + ((hist[22] * hist[22]) / 2) + ((hist[23] * hist[23]) / 2) + ((hist[24] * hist[24]) / 2)) / 24)发布于 2021-11-10 04:53:08
sma(source,length)函数将计算最后'n‘条的平均值。
使用sma()函数代替您正在使用的代码,它将执行与您想要的相同的功能
histGreater24 =hist>sma((hist*hist)/2,24)发布于 2021-11-10 10:38:28
我认为您必须使用security()从较高的时间范围(每日)获取数据来计算hist的平均值,或者您可以使用不同的来源,如hl2 hlc3 ohlc4。(V5)尝试此代码->
htf_src = math.avg(number0 = ta.highest(source = hist, length = 1), number1 = ta.lowest(source = hist, length = 1))
f_security(_symbol, _tf, _src) => request.security(symbol = _symbol, timeframe = _tf, expression = _src[barstate.isrealtime ? 1 : 0])
htf_source = f_security(syminfo.tickerid, "D", htf_src) // Here the expression hist could be replaced by hl2 hlc3 ohlc4 or any source you want to get from the "D" - Daily timeframe
condition_1 = hist[1] > 0
condition_2 = hist[1] > htf_source
signal_condition = condition_1 and condition_2
plotchar(
series = signal_condition,
title = "HIST Condition",
char = "☀",
location = location.abovebar,
color = color.new(color = color.lime, transp = 0),
size = size.normal
)
// # ========================================================================= #
// * # The opposite condition
// * >
// * > condition_3 = hist[1] < 0
// * > signal_bottom_condition = condition_3 and not condition_2
// * > plotchar(series = signal_bottom_condition, "Hist Down Conditoin", char = "*", location = location.abovebar, color = color.new(color = color.red, transp = 0), size = size.normal)
// # ========================================================================= #https://stackoverflow.com/questions/69906363
复制相似问题