Pine script 如何创建具有偏移量(步移)的Hala指标,以及基于该指标和一个长位置的简单策略脚本的策略

Pine script 如何创建具有偏移量(步移)的Hala指标,以及基于该指标和一个长位置的简单策略脚本的策略,pine-script,trading,Pine Script,Trading,我很抱歉要求为您解决这个小问题,但请帮助新手: 1.我想创建一个带有偏移的移动外壳指示器-我需要在指示器中实现偏移功能。 2.“带偏移的移动船体”的交叉策略基于长位置的简单策略脚本。 如果这不会让受人尊敬的有经验的人感到困难,我将非常感谢我在分析中的帮助 1.need to embed "//shift the step step_shift = input(0,"Step Shift")" //@version=4 study(title = "Hull M

我很抱歉要求为您解决这个小问题,但请帮助新手: 1.我想创建一个带有偏移的移动外壳指示器-我需要在指示器中实现偏移功能。 2.“带偏移的移动船体”的交叉策略基于长位置的简单策略脚本。 如果这不会让受人尊敬的有经验的人感到困难,我将非常感谢我在分析中的帮助

1.need to embed "//shift the step
                  step_shift = input(0,"Step Shift")"
//@version=4
study(title = "Hull MA", shorttitle="HMA", overlay = true)
length = input(9, minval=1)
src = input(close, title="Source")
hullma = wma(2*wma(src, length/2)-wma(src, length), round(sqrt(length)))
plot(hullma)



2.insert the received indicator into this strategy script long position only

//@version=4
strategy("My strategy", overlay=true)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)
2020年1月12日。 我还编辑了您的代码,以获得更必要的检查想法。现在仍需在此处应用校正,以便偏移生效

 //@version=4
strategy(title = "Hull MA", shorttitle="HMA", overlay = true)

fastLength  = input(14, minval=2)
offsetfastLength  = input(0)
src1   = input(close, title="Source")
slowLength  = input(28, minval=2)
offsetslowLength   = input(0)
src2   = input(open, title="Source")


fastHma = wma(2*wma(src1, fastLength/2)-wma(src1, fastLength), round(sqrt(fastLength)))
slowHma = wma(2*wma(src2, slowLength/2)-wma(src2, slowLength), round(sqrt(slowLength)))
longCondition   = crossover(fastHma, slowHma)
closeCondition  = crossunder(fastHma, slowHma)

strategy.entry("long",strategy.long,when = longCondition)
strategy.close("long",when = closeCondition)

plot(fastHma, "fastHma", color.orange, offset = offsetfastLength)
plot(slowHma, "slowHma", color.blue, offset = offsetslowLength)

非常感谢人类!现在我将为我申请和学习,这非常重要,谢谢你的帮助!)非常感谢你,天才这里有个问题。。。。该策略没有看到,也没有考虑“偏移”参数…更新了代码,但只允许向右偏移,因此使信号延迟。请告诉我为什么不能进行负偏移,但只能向右偏移?这是不可能的?因为现在偏移量在Hma计算上,所以相同的偏移量显示在绘图上。而calcs不能使用未来的数据,因为它还不存在,所以偏移量不能进入未来。您始终可以添加一个独立的偏移量,用于将来可能进行打印的打印,如我的第一个示例中所示。
//@version=4
strategy(title = "Hull MA", shorttitle="HMA", overlay = true)

fastLength  = input(14, minval=2)
slowLength  = input(28, minval=2)
offsetHMA   = input(0, "Offset in the future", minval=0)
src         = input(close, title="Source")

fastHma = wma(2*wma(src, fastLength/2)-wma(src, fastLength), round(sqrt(fastLength)))[offsetHMA]
slowHma = wma(2*wma(src, slowLength/2)-wma(src, slowLength), round(sqrt(slowLength)))[offsetHMA]
longCondition   = crossover(fastHma, slowHma)
shortCondition  = crossunder(fastHma, slowHma)

if longCondition
    strategy.entry("My Long Entry Id", strategy.long)
if shortCondition
    strategy.entry("My Short Entry Id", strategy.short)

plot(fastHma, "fastHma", color.orange)
plot(slowHma, "slowHma", color.blue)
plotchar(longCondition, "longCondition", "▲", location.belowbar, color.green)
plotchar(shortCondition, "shortCondition", "▼", location.abovebar, color.maroon)