在不同的时间范围内更改 RSI 的时间范围
大家好,谁能帮我为 RSI 策略设置一个不同的时间框架。例如,我想在 1 小时图表上查看 4 小时时间范围 RSI。只是想知道这是否可能,以及您是否可以帮我设置它。代码如下,如果您能告诉我需要添加什么才能使其工作,那将会很有帮助。提前致谢。
//@version=5
strategy(title="Relative Strength Index", shorttitle="RSI-SMA(f)", overlay=false, initial_capital=100, default_qty_type=strategy.cash, default_qty_value=50, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.07)
// Choose MA Type
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// RSI and MA inputs
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
// Plotting RSI and SMA
plot(rsi, "RSI", color=color.blue)
plot(rsiMA, "RSI-based MA", color=color.yellow)
// Conditions and Entries
longCondition= ta.crossover(rsi,rsiMA)
if (longCondition)
strategy.entry('Long', strategy.long)
shortCondition= ta.crossunder(rsi,rsiMA)
if (shortCondition)
strategy.entry('short', strategy.short)
// Exit Position
strategy.close('Long', when= shortCondition, comment= 'Exit Long')
strategy.close('short', when= longCondition, comment= 'Exit Short')
Hi guys can anyone help me set up a different time frame for the RSI strategy. For example I would like to view a 4hr timeframe rsi on a 1hr chart. Just wondering is that is possible and if you could help me set it up. Code is below and it would be helpful if you could tell me what i would have to add to make it work. Thanks in advance.
//@version=5
strategy(title="Relative Strength Index", shorttitle="RSI-SMA(f)", overlay=false, initial_capital=100, default_qty_type=strategy.cash, default_qty_value=50, currency=currency.USD, commission_type=strategy.commission.percent, commission_value=0.07)
// Choose MA Type
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"Bollinger Bands" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// RSI and MA inputs
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
rsiSourceInput = input.source(close, "Source", group="RSI Settings")
maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
maLengthInput = input.int(14, title="MA Length", group="MA Settings")
up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
// Plotting RSI and SMA
plot(rsi, "RSI", color=color.blue)
plot(rsiMA, "RSI-based MA", color=color.yellow)
// Conditions and Entries
longCondition= ta.crossover(rsi,rsiMA)
if (longCondition)
strategy.entry('Long', strategy.long)
shortCondition= ta.crossunder(rsi,rsiMA)
if (shortCondition)
strategy.entry('short', strategy.short)
// Exit Position
strategy.close('Long', when= shortCondition, comment= 'Exit Long')
strategy.close('short', when= longCondition, comment= 'Exit Short')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我制作了一个每日移动平均线,可以在较低的时间范围内查看。
您可以创建一个指标,并将其放在
D
或4h
上( 240) 在你的情况下。就像你展示的图片一样。但如果你想将其与其他逻辑混合,它就行不通,因为一切都将基于该时间范围,并且仅基于该时间范围。
我使用/滥用了 request.security 函数为了这。
以下是显示 4 小时收盘价的指标示例。如果这是您想要的行为,您可以在 2 小时图上查看。
I made a daily moving average that could be viewed on lower timeframes.
You can create for example a indicator and put that on
D
or4h
(240) in your case.Just like in the picture your showing. But if you want to mix this with other logic it would not work because everything would be based on that timeframe and that timeframe alone.
I used/abused the request.security function for this.
Here is a example of a indicator that will show you the close of the 4h. You can check it on the 2h chart, if this is the behaviour you want.