简体   繁体   English

TradingView Pine Script 策略多个时间范围

[英]TradingView Pine Script strategy multiple time frames

I am trying to apply Bollinger bands in Tradingnview using Pine script.我正在尝试使用 Pine 脚本在 Tradingnview 中应用布林带。 I have calculated all the variables (simple moving average, upper and lower bounds) and used close/open price using a 1-day frame, however, I want to implement a strategy that relies on this time frame, but executes the order on a lower resolution, eg 1-hour time frame.我已经计算了所有变量(简单移动平均线、上限和下限)并使用 1 天框架使用收盘价/开盘价,但是,我想实施一个依赖于这个时间框架的策略,但在较低的分辨率,例如 1 小时的时间范围。 Basically, I receive a trigger using 1-day information and want to execute the order as soon as possible.基本上,我收到一个使用 1 天信息的触发器,并希望尽快执行订单。 Did anyone come across this issue?有人遇到过这个问题吗?

For handling multi timeframe you can use the security() function.要处理多个时间范围,您可以使用security() function。

Let's say you want a buy signal on the 1h 7-RSI crossing above 30 on a day where 7-day MA is above 21-days MA.假设您希望在 7 天均线高于 21 天均线的某一天,在 1 小时 7-RSI 突破 30 时发出买入信号。

Set your chart timeframe to 1h (current timeframe) and use this for your script:将您的图表时间范围设置为 1h(当前时间范围)并将其用于您的脚本:

//@version=4

// Higher Time Frame
htf_fast_sma = security(syminfo.tickerid, "1D", sma(close, 7), lookahead=barmerge.lookahead_on)
htf_slow_sma = security(syminfo.tickerid, "1D", sma(close, 21), lookahead=barmerge.lookahead_on)

// Higher TF: Fast SMA above Slow SMA
high_tf_buy_signal = htf_fast_sma > htf_slow_sma

// Current TF: 7-RSI crossing over 30
curr_tf_buy_signal = crossover(rsi(close, 7), 30)

buy_signal = high_tf_buy_signal and curr_tf_buy_signal
plotshape(buy_signal ? low : na, 'Buy',  shape.labelup, location.belowbar)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM