简体   繁体   English

用 pine 脚本编写每小时随机 RSI 策略代码

[英]Code hourly Stochastic RSI strategy in pine script

I am trying to code a stochastic rsi strategy in pine script to go long when the hourly K is above D and K is below, 80 as per below but it returns almost no trades when I backtested it unless I change from just the < to <= which tells me something is not right.当每小时 K 高于 D 且 K 低于 80 时,我正在尝试将 pine 脚本中的随机 rsi 策略编码为 go 长,如下所示,但当我对其进行回测时它几乎没有返回任何交易,除非我从 < 更改为 < = 这告诉我有些事情是不对的。 Can someone help please.有人可以帮忙吗?

kH = security(syminfo.tickerid, "60", sma(stoch(close, high, low, stochLength), 3))
dH = sma(kH, 3)

stochConditionH = kH < dH and kH < 80

To obtain that condition correctly it has to be done within the context of the security call.要正确获得该条件,必须在安全调用的上下文中完成。 Otherwise you aren't going to obtain the correct calculation for the one hour timeframe.否则您将无法获得一小时时间范围内的正确计算。 Let's say your chart is the 15 minute chart.假设您的图表是 15 分钟图表。

dh = sma(kH, 3)

Will give you the average of kH over the last 3 15 minute bars.将为您提供过去 3 个 15 分钟柱的平均 kH。 If you need to perform operations on the 60 minute timeframe, you need to wrap everything in function and pass that to the security call.如果您需要在 60 分钟的时间范围内执行操作,则需要将所有内容包装在 function 中并将其传递给安全调用。

f_stochConditionH(_close, _high, _low, _len) =>
    _kH = sma(stoch(_close, _high, _low, _len), 3)
    _dH = sma(_kH, 3)
    _stochConditionH = _kH < _dH and _kH < 80
    _stochConditionH


stochConditionH = security(syminfo.tickerid, "60", f_stochConditionH(close, high, low, stochLength))

This allows the operation to be done correctly on the one hour timeframe.这允许在一小时的时间范围内正确完成操作。 So now _dh = sma(_kH,3) inside the function is now the average of the last three one hour values of _kH when used within the security call.因此,现在_dh = sma(_kH,3)现在是安全调用中使用的_kH的最后三个一小时值的平均值。

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

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