偏移交叉策略问题

时间:2020-11-01 12:20:59

标签: pine-script tradingview-api

如您所见,我制作了2个均长75的船体MA。蓝色的我将偏移为-10。如何通过2 MA的交叉创建策略? 我的问题是,偏移量仅会改变图表,因此,如果我尝试使用crossover(hullma,hullma1),则什么也不会发生,因为tradingview认为这些线是相同的。 那么,向左移动10条指标并设置交叉策略是否有变化? 谢谢

enter image description here

1 个答案:

答案 0 :(得分:0)

使用负偏移量意味着您将当前数据偏移到过去,并且仅在延迟等于偏移值的情况下,才能确定实时蜡烛的交叉点。

这将使得不可能在发生交叉的同时创建交叉信号,但是您可以使用该信号对历史蜡烛进行分析。

请注意,您在最后10支蜡烛(等于偏移值)中将无法发现十字架。

//@version=4
study(title="HMA Cross the Offset HMA", overlay=true)

length = input(75, minval=1)
src = input(close, title="Source")
hullMa = wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)))

// Current Hull Moving Average
plot(hullMa, color = color.red)

// Hull Moving Average with a negative offset
plot(hullMa, color = color.blue, offset = -10)

float hullMaWithOffset = nz(hullMa[10])

bool cross = cross(hullMa, hullMaWithOffset)

// Mark Cross with Background color
// To spot the exact bar with a crossover we should use the equal offset value
bgcolor(cross? color.orange : na, offset = -10)

enter image description here