INVITE-ONLY SCRIPT

EMA + MACD 综合信号带止盈止损

15
//version=5
indicator("EMA + MACD 综合信号带止盈止损", overlay=true)

// 输入参数
fastEMA = input.int(12,"快速EMA")
slowEMA = input.int(26,"慢速EMA")
signalEMA = input.int(9,"MACD信号")
mainEMA = input.int(50,"趋势EMA")
rsiLen = input.int(14,"RSI周期")
rsiOverB = input.int(70,"RSI超买")
rsiOverS = input.int(30,"RSI超卖")
stopATR = input.float(1.5,"止损ATR倍数")

// 核心指标计算
emaTrend = ta.ema(close, mainEMA)
[macdLine, signalLine, _] = ta.macd(close, fastEMA, slowEMA, signalEMA)
rsiVal = ta.rsi(close, rsiLen)
atrVal = ta.atr(14)

// 买卖条件
longCond = (close > emaTrend) and (macdLine > signalLine) and (rsiVal < rsiOverS)
shortCond = (close < emaTrend) and (macdLine < signalLine) and (rsiVal > rsiOverB)

// 画买入卖出点
plotshape(longCond, title="Buy", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(shortCond, title="Sell", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// 止损线(举例为ATR止损)
longStop = close - stopATR * atrVal
shortStop = close + stopATR * atrVal
plot(longCond ? longStop : na, color=color.orange, style=plot.style_linebr, linewidth=2, title="多头止损")
plot(shortCond ? shortStop : na, color=color.purple, style=plot.style_linebr, linewidth=2, title="空头止损")

// 主要参考线
plot(emaTrend, title="趋势EMA", color=color.blue)

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.