Trading View 振荡器中多个因素的交叉函数

Crossover function for multiple factors in an oscillator on Trading View

我想在 Trading View(开源,震荡指标)上为以下指标添加警报。简而言之,必须满足多个条件才能触发不同类型的警报(多头入场、多头早出、多头晚出、空头入场、空头早出、空头晚出)。我有三个因素,slowMA + fastMA + 基于 RSI 或移动平均线的中线 (midl)。

多头进场:slowMA 向上交叉 fastMA + slowMA 向上交叉 midl + fastMA 向上交叉 midl

多头提前退出:fastMA 向上交叉 slowMA + slowMA 向上交叉 midl + fastMA 向上交叉 midl

多头后期退出:fastMA 向上交叉 slowMA + midl 向上交叉 slowMA + midl 向上交叉 fastMA

空头进场:FastMA 向上交叉 slowMA + midl 向上交叉 slowMA + midl 向下向上交叉 fastMA

空头提前退出:slowMA 向上交叉 fastMA + midl 向上交叉 slowMA + midl 向上交叉 fastMA

空头尾盘:slowMA 向上交叉 fastMA + slowMA 向上交叉 midl + fastMA 向上交叉 midl

我以前完全没有编码经验。我收到以下错误。非常感谢您的帮助!:

第 35 行:无法使用 'y'=plot 调用 'crossover'。参数的类型应该是:series[float]; 第 36 行:无法使用 'y'=plot 调用 'crossover'。参数的类型应该是:series[float]; 第 37 行:无法使用 'x'=plot 调用 'crossover'。参数的类型应该是:series[float]; 第 38 行:无法使用 'x'=plot 调用 'crossover'。参数的类型应该是:series[float]; 第 39 行:无法使用 'x'=plot 调用 'crossover'。参数的类型应该是:series[float]; 第 40 行:无法使用 'y'=plot 调用 'crossover'。参数的类型应该是:series[float]; 第 42 行:未声明的标识符 'longopen'; 第 43 行:未声明的标识符 'longcloseearly'; 第 44 行:未声明的标识符 'longcloselate'; 第 45 行:未声明的标识符 'shortopen'; 第 46 行:未声明的标识符 'shortcloseearly'; 第 47 行:未声明的标识符 'shortcloselate'

//@version=4
study("TDI + RSI + BB [Market Makers Method]", shorttitle="MMM")

rsiPeriod = input(21, minval = 1, title = "RSI Period")
bandLength = input(34, minval = 1, title = "Band Length")
lengthrsipl = input(7, minval = 0, title = "Fast MA on RSI")
lengthtradesl = input(2, minval = 1, title = "Slow MA on RSI")

src = close                                                             // Source of Calculations (Close of Bar)
r = rsi(src, rsiPeriod)                                                 // RSI of Close
ma = sma(r, bandLength)                                                 // Moving Average of RSI [current]
offs = (1.6185 * stdev(r, bandLength))                                  // Offset
up = ma + offs                                                          // Upper Bands
dn = ma - offs                                                          // Lower Bands
mid = (up + dn) / 2                                                     // Average of Upper and Lower Bands
fastMA = sma(r, lengthrsipl)                                            // Moving Average of RSI 2 bars back
slowMA = sma(r, lengthtradesl)                                          // Moving Average of RSI 7 bars back

hline(32)                                                               // ExtremelyOversold
hline(37)                                                               // Oversold
hline(50)                                                               // Midline
hline(63)                                                               // Overbought
hline(68)                                                               // ExtremelyOverbought

upl = plot(up, "Upper Band", color = #3286c3, linewidth = 2)               // Upper Band
dnl = plot(dn, "Lower Band", color = #3286c3, linewidth = 2)               // Lower Band
midl = plot(mid, "Middle of Bands", color = #ffff00, linewidth = 2)      // Middle of Bands 

plot(slowMA, "Slow MA", color = #00AB08, linewidth=2)                       // Plot Slow MA
plot(fastMA, "Fast MA", color = #ff0000, linewidth=1)                         // Plot Fast MA

longopen = crossover(slowMA, fastMA) and crossover(fastMA, midl) and crossover(slowMA, midl) 
longcloseearly = crossover(fastMA, slowMA) and crossover(slowMA, midl) and crossover(fastMA, midl)
longcloselate = crossover(fastMA, slowMA) and crossover (midl, slowMA) and crossover(midl, fastMA)
shortopen = crossover(fastMA, slowMA) and crossover(midl, slowMA) and crossover(midl, fastMA)
shortcloseearly = crossover(slowMA, fastMA) and crossover(midl, slowMA) and crossover(midl, fastMA)
shortcloselate = crossover(slowMA, fastMA) and crossover(slowMA, midl) and crossover(fastMA, midl)

alertcondition(longopen, title='Long Open', message='Long Open')
alertcondition(longcloseearly, title='Long Close Early', message='Long Close Early')
alertcondition(longcloselate, title='Long Close Late', message='Long Close Late')
alertcondition(shortopen, title='Short Open', message='Short Open')
alertcondition(shortcloseearly, title='Short Close Early', message='Short Close Early')
alertcondition(shortcloselate, title='Short Close Late', message='Short Close Late')
Cannot call 'crossover' with 'y'=plot.

表示您正在尝试在函数 crossover 中使用绘图,这不是兼容的选项:您应该将 series[float] 传递给它。

在您的 crossover() 函数中,尝试使用 mid 而不是 midl,例如:

longopen = crossover(slowMA, fastMA) and crossover(fastMA, mid) and crossover(slowMA, mid)