我正在 TradingView 的 Pine 编辑器中尝试 DMI + RSI 反转策略,但交易继续在下一个柱上退出,即使它不应该基于我的标准。有谁知道是什么导致了这个问题?我还尝试更改退出交易的标准(我将其从检查 diplus 分别高于或低于 60 或 10 转换为通过查看 RSI 值是否超买或超卖)分别高于 70 或低于 30)。即使我将标准更改为退出,它仍然会在下一根蜡烛进入交易后立即退出。
//@version=4
strategy("RSI-14, DI+, DI- Reversal Strategy", overlay=false)
/// DI+ DI- Code /// /// DI+ is the variable called "plus" and DI- is the variable called "minus"
///// INPUTS /////
adxlen = input(14, title="ADX Smoothing")
dilen = input(14, title="DI Length")
//keylevel = input(23, title = "Key Level for ADX")
//adxLookbackEntry = input(3, title="Lookback Period for Slope (Entry)")
//adxLookbackExit = input(1, title="Lookback Period for Slope (Exit)")
[diplus, diminus, adx] = dmi(dilen, adxlen)
//buysignal = (adx[0] - adx[adxLookbackEntry] > 0) and adx > keyLevel and diplus > diminus
//shortsignal = (adx[0] - adx[adxLookbackEntry] > 0) and adx > keyLevel and diplus < diminus
//dirmov(len) =>
// up = change(high)
// down = -change(low)
// plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
// minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
// truerange = rma(tr, len)
// plus = fixnan(100 * rma(plusDM, len) / truerange)
// minus = fixnan(100 * rma(minusDM, len) / truerange)
// [plus, minus]
//adx(dilen, adxlen) =>
// [plus, minus] = dirmov(dilen)
// sum = plus + minus
// adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
//sig = adx(dilen, adxlen)
//plot(sig, color=color.red, title="ADX")
///// RSI Code /////
rsi = rsi(close,14)
//rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsi_ob = rsi >= 70
rsi_os = rsi <= 30
///// MovAvg Code /////
sma5 = sma(close,5)
sma200 = sma(close,200)
////////// Strategy Entries and Exits //////////
//long the ticker//
minus_ob = diminus >= 60
plus_long_reversal = diplus[1] <= 10 and diplus[1] < diplus
minus_long_reversal = diminus[1] >= 60 and diminus[1] > diminus
exit_long_trade = diplus >= 60
//short the ticker//
plus_short_reversal = diplus[1] >= 60 and diplus[1] > diplus
minus_short_reversal = diminus[1] <= 10 and diminus[1] < diminus
exit_short_trade = diplus <= 10
isLongEntry = rsi_os and plus_long_reversal and minus_long_reversal
isLongExit = exit_short_trade
isShortEntry = rsi_ob and plus_short_reversal and minus_short_reversal// and close < open
isShortExit = exit_long_trade
t = time(timeframe.period, "0830-1500")
session_open = na(t) ? false : true
if (session_open)
strategy.entry("Long", strategy.long, 100.0, when = isLongEntry)
strategy.entry("Short", strategy.short, 100.0, when = isShortEntry)
strategy.close("Long", when = isLongExit)
strategy.close("Short", when = isShortExit)
//else
// strategy.close_all()
rsi_graph_correction = 30
level_70 = 70-rsi_graph_correction
level_70rsi = rsi_graph_correction > level_70 ? rsi_graph_correction : level_70
level_30 = 30-rsi_graph_correction
level_30rsi = rsi_graph_correction < level_30 ? rsi_graph_correction: level_30
di_line_1 = hline(price=60,color=color.blue)
di_line_2 = hline(price = 10, color=color.yellow)
line_1 = hline(price=50-rsi_graph_correction)
line_2 = hline(price=70-rsi_graph_correction, color=color.red)
line_3 = hline(price=30-rsi_graph_correction,color=color.green)
p1 = plot(series = level_70, color=color.red, linewidth=1, transp=100)
p2 = plot(series = level_70rsi, color=color.red, linewidth=1, transp=100)
p3 = plot(series = level_30, color=color.green, linewidth=1, transp=100)
p4 = plot(series = level_30rsi, color=color.green, linewidth=1, transp=100)
p5 = plot(rsi-rsi_graph_correction,color=color.gray, transp=50)
p6 = plot(diplus,color=color.green)
p7 = plot(diminus,color=color.red)
//plotshape(isLongEntry, style=shape.arrowup, color=color.green, location=location.bottom)
plotshape(isLongEntry, style=shape.arrowup, color=color.green, location=location.bottom)
plotshape(isShortEntry, style=shape.arrowdown, color=color.red, location=location.top)
bgcolor(session_open ? color.green : na)
barcolor(isLongEntry ? color.blue : na)
barcolor(isLongExit ? color.purple : na)
barcolor(isShortEntry ? color.aqua : na)
barcolor(isShortExit ? color.yellow : na)
任何帮助都可以解决问题