TradingView多安全策略和解决方案设置 [英] Tradingview multi-security strategy and resolution setiings

查看:13
本文介绍了TradingView多安全策略和解决方案设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的Pine脚本,下面提供了一个供参考,我希望帮助澄清两个概念。

  1. 如何设置此策略的分辨率,以便可以查看一年、五年、一年等图表,但始终以特定的分辨率运行策略(例如每日条形图)。我在这方面做了几次尝试,您可以在代码中看到注释,但我认为它不能正常工作;我想看看更有经验的人如何实现这一点。

  2. 我想写一个同时分析多个证券的策略,但是,我在TradingView中找不到一个好的方法来做到这一点。我之前使用的是QuantConnect,在这个系统中,我可以选择我想操作的任何数量的证券。例如,下面的策略是相对较低的交易频率(大约每年四次),所以我想使用多个证券来运行此策略,以潜在地减少停机时间。对于我来说,不能运行一种分析和交易多种证券的策略是一个相当大的缺点。

感谢您所能提供的一切帮助。下面提供了引用的代码。

    //@version=4
strategy(title="Basic Bollinger",
     overlay=true,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=95)

// Strategy Rules:
// 1. Enter trade when price crosses above the lower band
// 2. Exit trade when price touches the upper band
// 

// Chart Properties
testStartYear = input(2018, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, 0, 0)

testStopYear = input(2021, "Backtest Stop Year")
testStopMonth = input(1, "Backtest Stop Month")
testStopDay = input(1, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)

// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=input.bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and time >= testPeriodStart and time <= testPeriodStop ? #6c6f6c : na
bgcolor(testPeriodBackgroundColor, transp=97)

// User provided values
smaLength = input(title="SMA Length", type=input.integer, defval=20) // Middle band period length (moving average)
stdLength = input(title="StdDev Length", type=input.integer, defval=20) // Range to apply bands to
ubOffset = input(title="Upper Band Offset", type=input.float, defval=2.0, step=0.5) // Number of standard deviations above MA
lbOffset = input(title="Lower Band Offset", type=input.float, defval=2.0, step=0.5) // Number of standard deviation below MA
res = input(title='Resolution', type=input.resolution, defval='1D') // Resolution

testPeriod() =>
    time >= testPeriodStart and time <= testPeriodStop ? true : false

//closePrice = security(syminfo.tickerid, res, close)
stdDev = stdev(close, stdLength) // security(syminfo.tickerid, res, stdev(close, stdLength)) // Standard Deviation
smaValue = sma(close, smaLength) // security(syminfo.tickerid, res, sma(close, smaLength)) // Middle band
upperBand = smaValue + stdDev * ubOffset // Top band
lowerBand = smaValue - stdDev * lbOffset // Bottom band

// Plot Bands
plot(series=smaValue, title="SMA", color=color.blue)
plot(series=upperBand, title="UB", color=color.green, linewidth=2)
plot(series=lowerBand, title="LB", color=color.red, linewidth=2)

longCondition = (crossover(close, lowerBand))
closeLongCondition = (close >= upperBand)

if (longCondition and testPeriod())
    strategy.entry(id="CALL", long=true)

strategy.close(id="CALL", when=closeLongCondition)

推荐答案

1

您需要做的是使用TradingView的security()函数将所有src值替换为如下所示的每日分辨率:

src = security(syminfo.ticker, "D", close)

然后,只需将所有close替换为src,它现在应该可以在任何时间范围内工作。

但请注意,如果您的时间段比每天更长,则会丢失数据,这是因为Security()不打算用于从较短的时间段导入数据。


对于2号

您可以创建如下屏幕: 这也可以使用security()函数来完成。 下面是一个例子:

ema_5 = ema(close, 5)
getConditions()=>
    buy = crossover(close, ema_5)
    sell = crossunder(close, ema_5)
    [buy, sell]

[btc_buy, btc_sell] = security("BINANCE:BTCUSDTPERP", timeframe.period, getConditions())
[ltc_buy, ltc_sell] = security("BINANCE:LTCUSDTPERP", timeframe.period, getConditions())
[eth_buy, eth_sell] = security("BINANCE:ETHUSDTPERP", timeframe.period, getConditions())

然后您可以使用这些值将其显示在表等上。

但是,如果你只想分析净利润%,利润系数,或者用你的战略脚本回测不同的符号和时间框架,那么你就需要一个网络刮刀。您可以构建一个来为您完成此操作,而不是手动逐个检查每个符号和时间范围。

这篇关于TradingView多安全策略和解决方案设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆