编码HMA多头和空头头寸

  • 本文关键字:编码 HMA pine-script
  • 更新时间 :
  • 英文 :


我正试图使用我编码的HMA指示符在pine编辑器上编码一个多头/空头头寸条目。

`//@version=3
study(title="HMA", overlay=true)
n=input(title="period",type=integer,defval=14)
//HMA calculation for current day
wma1=2*wma(close,round(n/2))
wma2=wma(close,n)
diff=wma1-wma2
sqn=round(sqrt(n))
//HMA calculation for previous day
NextDaywma1=2*wma(close[1],round(n/2))
NextDaywma2=wma(close[1],n)
NextDaydiff=NextDaywma1-NextDaywma2
//different colors depending on the trend of the HMA
hma=wma(diff,sqn)
hma2=wma(NextDaydiff,sqn)
c=hma>hma2?blue:orange
plot(hma,color=c, linewidth=3)`

我还添加了一个完整的随机性,但我想我现在只关注这一件事。

非常感谢您的帮助。谢谢

我从pine编辑器中获取了一个空白策略模板(您可以通过单击打开并按load-black-strategy来加载这些模板(,并将其转储到您的条件中。我还将您升级到了版本5。(如果你要学松木,学一次会更容易,而且会更好(。注意,我使用了你MA的颜色规则中的长或短。还有其他选择,比如交叉,但这会让你继续前进。

//@version=5
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)
n           = input(title='period', defval=14)
//HMA calculation for current day
wma1        = 2 * ta.wma(close, math.round(n / 2))
wma2        = ta.wma(close, n)
diff        = wma1 - wma2
sqn         = math.round(math.sqrt(n))
//HMA calculation for previous day
NextDaywma1 = 2 * ta.wma(close[1], math.round(n / 2))
NextDaywma2 = ta.wma(close[1], n)
NextDaydiff = NextDaywma1 - NextDaywma2
//different colors depending on the trend of the HMA
hma         = ta.wma(diff, sqn)
hma2        = ta.wma(NextDaydiff, sqn)
c           = hma > hma2 ? color.blue : color.orange
plot         (hma, color=c, linewidth=3)
long        = hma > hma2
short       = hma < hma2
if (long)
strategy.entry("My Long Entry Id", strategy.long)
if (short)
strategy.entry("My Short Entry Id", strategy.short)

为您的交易和编码干杯,祝您好运

最新更新