如何在不同的时间范围内使用MACD?

时间:2020-05-10 18:47:06

标签: pine-script

我已经开发了以下简单代码,以通过SL和TP在MACD上查找上升趋势和下降趋势。

我目前正在将30M作为一个时间范围工作,并且希望能够说“如果较低时间范围(15M)的MACD相反,请平仓”。请问如何实现此代码?

strategy(title =“ MACD example strategy”,overlay = false,default_qty_value = 3, initial_capital = 10000,currency = currency.EUR)

fastLen = input(title="Fast Length", type=integer, defval=12)
slowLen = input(title="Slow Length", type=integer, defval=26)
sigLen  = input(title="Signal Length", type=integer, defval=9)

// Get MACD values
[macdLine, signalLine, _] = macd(close, fastLen, slowLen, sigLen)

// Plot MACD values and line
plot(series=macdLine, color=#6495ED, linewidth=2)
plot(series=signalLine, color=orange, linewidth=2)


hline(price=0, title="Zero", color=gray, linewidth=5, linestyle=dashed)

// Determine long and short conditions
longCondition  = crossover(macdLine, signalLine)
shortCondition = crossunder(macdLine, signalLine)


sl_inp = input(100, title='Stop Loss in Ticks', type=integer)
tp_inp = input(50, title='Take Profit in Ticks', type=integer)

// Submit orders
strategy.entry(id="Long Entry", long=true, when=longCondition)
strategy.entry(id="Short Entry", long=false, when=shortCondition)

strategy.exit("Stop Loss/TP", "Simple SMA Entry", loss=sl_inp, profit=tp_inp)```

thank you all in advance!

0 个答案:

没有答案