【问题标题】:Plot only Trading View historical data仅绘制交易视图历史数据
【发布时间】:2021-12-16 20:41:05
【问题描述】:

我最大的问题是我只想要指标上的历史数据,因为实时变化太大,会打印出一堆我不想要的买入/卖出信号。以下是我到目前为止的代码。

基本上,我想要历史警报,并且我只想在加载电视时显示历史数据。

免责声明:我使用了 Mehdi 的这个开源代码,并且一直在对其进行编辑以修复它/从中获取我需要的东西。

感谢您抽出宝贵时间提供帮助。

// © SRJRainey
//@version=2
strategy("TDI - Traders Dynamic Index ", shorttitle="TDIMH")

rsiPeriod = input(13, minval = 1, title = "RSI Period")
bandLength = input(34, minval = 1, title = "Band Length")
lengthrsipl = input(1, minval = 0, title = "Fast MA on RSI")
lengthtradesl = input(9, minval = 1, title = "Slow MA on RSI")
p1 = input("15", title = "Signal Timeframe", type = string)

src = close // Source of Calculations (Close of Bar)

r = rsi(src, rsiPeriod) // RSI of Close
ma = sma(r, bandLength) // Moving Average of RSI
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(50)
indexHighTf = barstate.isrealtime ? 1 : 0
indexCurrTf = barstate.isrealtime ? 0 : 1
slowMA1 = security(tickerid, p1, slowMA)
fastMA1 = security(tickerid, p1, fastMA)
up1 = security(tickerid, p1, up)
dn1 = security(tickerid, p1, dn)
mid1 = security(tickerid, p1, mid)

plot(up1, "Upper Band", color = #3286c3, linewidth = 2) // Upper Band
plot(dn1, "Lower Band", color = #3286c3, linewidth = 2) // Lower Band
plot(mid1, "Middle of Bands", color = yellow, linewidth = 2) // Middle of Bands
plot(slowMA1, "Slow MA", color=green, linewidth=2) // Plot Slow MA
plot(fastMA1, "Fast MA", color=red, linewidth=1) // Plot Fast MA

if (crossover(fastMA1, slowMA1)) strategy.entry("sell", strategy.long, comment="Buy")

if (crossunder(fastMA1, slowMA1)) strategy.entry("Sell", strategy.short, comment="Sell")

【问题讨论】:

    标签: pine-script algorithmic-trading


    【解决方案1】:

    您可以使用History reference operator 访问历史数据。

    例如,你可以这样做

    crossover(fastMA1[1], slowMA1[1]) 看看交叉是否发生在一个小节之前。

    【讨论】:

      猜你喜欢
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      • 2016-01-31
      • 1970-01-01
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 2012-04-26
      相关资源
      最近更新 更多