本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=4
study("Improved Intraday Market Movement Prediction", shorttitle="IMMP", overlay = true)
// Input parameters
rsiPeriod = input(14, title="RSI Period")
macdShortPeriod = input(12, title="MACD Short Period")
macdLongPeriod = input(26, title="MACD Long Period")
macdSignalSmoothing = input(9, title="MACD Signal Smoothing")
emaShortPeriod = input(9, title="EMA Short Period")
emaLongPeriod = input(21, title="EMA Long Period")
atrPeriod = input(14, title="ATR Period")
atrMultiplier = input(1.5, title="ATR Multiplier for SL and TP")
// Calculate indicators
rsi = rsi(close, rsiPeriod)
[macdLine, signalLine, _] = macd(close, macdShortPeriod, macdLongPeriod, macdSignalSmoothing)
emaShort = ema(close, emaShortPeriod)
emaLong = ema(close, emaLongPeriod)
atr = atr(atrPeriod)
// Define buying conditions
buySignal = crossover(emaShort, emaLong) and rsi < 30 and crossover(macdLine, signalLine) and macdLine > 0
// Define selling conditions
sellSignal = crossunder(emaShort, emaLong) and rsi > 70 and crossunder(macdLine, signalLine) and macdLine < 0
// Calculate SL and TP levels
longSL = close - atr * atrMultiplier
longTP = close + atr * atrMultiplier
shortSL = close + atr * atrMultiplier
shortTP = close - atr * atrMultiplier
// Plotting
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.triangleup, title="Buy Signal")
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.triangledown, title="Sell Signal")
// Plot RSI and MACD on separate plots below the main chart
hline(70, "Overbought", color=color.red)
hline(30, "Oversold", color=color.green)
plot(rsi, "RSI", color=color.blue)
hline(0, "Zero", color=color.gray)
plot(macdLine - signalLine, "MACD Histogram", color=color.red, style=plot.style_histogram, linewidth=1)
// Plot SL and TP levels
line.new(x1=bar_index[1], y1=longSL[1], x2=bar_index, y2=longSL, color=color.red, width=1, style=line.style_dashed)
line.new(x1=bar_index[1], y1=longTP[1], x2=bar_index, y2=longTP, color=color.green, width=1, style=line.style_dashed)
line.new(x1=bar_index[1], y1=shortSL[1], x2=bar_index, y2=shortSL, color=color.red, width=1, style=line.style_dashed)
line.new(x1=bar_index[1], y1=shortTP[1], x2=bar_index, y2=shortTP, color=color.green, width=1, style=line.style_dashed)