pine-script - 尝试用 Pine 编写我的交易视图策略
问题描述
在这些条件下,我需要一个做多或做空信号: - 当 RSI < 30 和 k<20 并且假设价格现在高于 100 SMA 时,给出做多信号。- 当 RSI > 70 且 k > 80 并且价格现在低于 100 SMA 时,会发出 SHORT 信号。现在在sma代码中,我没有考虑到价格,我请求你的帮助
这是我的代码:
//@version=4
strategy("Buy&Sell Strategy depends on AO+Stoch+RSI+ATR by SerdarYILMAZ", shorttitle="Buy&Sell Strategy")
//RSI
rsisource=input(title="rsi source",type=input.source,defval=close)
rsilength=input(title="rsi length",type=input.integer,defval=7)
rsi=rsi(rsisource,rsilength)
hline(70,color=color.orange)
hline(30,color=color.orange)
plot(rsi,color=color.orange)
//Stoch
K=input(title="K",type=input.integer,defval=14)
D=input(title="D",type=input.integer,defval=3)
smooth=input(title="smooth",type=input.integer,defval=3)
k=sma(stoch(close,high,low,K),D)
d=sma(k,smooth)
hline(80)
hline(20)
//ATR
atrlen=input(title="ATR Length", type=input.integer,defval=14)
atrvalue=rma(tr,atrlen)
LongCondition=k<20 and rsi<30
ShortCondition=k>80 and rsi>70
if (LongCondition)
stoploss=low-atrvalue
takeprofit=close+atrvalue
strategy.entry("LONG", strategy.long)
strategy.exit("TP/SL",stop=stoploss,limit=takeprofit)
if (ShortCondition)
stoploss=high+atrvalue
takeprofit=close-atrvalue
strategy.entry("SHORT",strategy.short)
strategy.exit("TP/SL",stop=stoploss,limit=takeprofit)
解决方案
价格现在高于/低于 100 SMA
但是,您没有包含任何基于 sma 100 的条件。在全局范围内引入 sma100 变量并将其添加到 Long/ShortCondition,如下例所示:
sma100 = sma(close, 100)
LongCondition=k<20 and rsi<30 and close > sma100
ShortCondition=k>80 and rsi>70 and close < sma100
推荐阅读
- r - tbl函数和data.frame有什么区别?
- android - 从 NYT API 获取 LARGE 嵌套的 Json
- json - ngFor 使用未知键迭代 json 子数组
- c++ - glFrustum 没有创建透视图
- angular - 循环时无法访问 Angular API 响应
- javascript - 使用缩放 css 时的边缘浏览器问题
- python-3.x - 将 9.90000000e+01 更改为 numpy nans
- java - 如何使用 GridLayout 和多个面板?
- html - 批量 base64 图像解码
- java - 模拟静态方法+运行参数化测试=“找不到匹配”