pine-script - 需要一个简单的 Pinescript 代码的帮助
问题描述
我可能拥有最简单的 pine 脚本之一,出于某种原因,我只能显示“卖出”绘图形状,而不能显示“买入”绘图形状。我不知道这段代码有什么问题,请有人帮忙!这是我的脚本:
// © tommyf1001
//@version=4
study(title="EMAs + Stoch RSI", overlay=true, resolution="")
// ---------- Indicators
smoothK = input(3, "K", minval=1, group="Stoch RSI")
smoothD = input(3, "D", minval=1, type=input.integer, group="Stoch RSI")
lengthRSI = input(14, "RSI Length", minval=1, group="Stoch RSI")
lengthStoch = input(14, "Stochastic Length", minval=1, group="Stoch RSI")
stoch_low = input(10, title="Stoch Low", group="Stoch RSI")
stoch_high = input(90, title="Stoch High", group="Stoch RSI")
ema_1 = input(21, "EMA Fast", group="EMAs")
ema_2 = input(50, "EMA Slow", group="EMAs")
// ------------- Functions
// --------- Stoch RSI
rsi1 = rsi(close, lengthRSI)
stoch_k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
stoch_d = sma(stoch_k, smoothD)
stoch_rsi_bull = (barssince(stoch_k < stoch_low) <= 10 and crossover(stoch_k, stoch_low))
stoch_rsi_bear = (barssince(stoch_k > stoch_high) <= 10 and crossunder(stoch_k, stoch_high))
// --------- EMAs
ema_bull = (ema_1 > ema_2)
ema_bear = (ema_1 < ema_2)
bull = (ema_bull and stoch_rsi_bull)
bear = (ema_bear and stoch_rsi_bear)
// -----------------------------------------------------------
// Plots
plotshape(bull ? close : na, title='Buy', style=shape.arrowup, location=location.belowbar, color=color.green, text='Buy', size=size.small)
plotshape(bear ? close : na, title='Sell', style=shape.arrowdown, location=location.abovebar, color=color.red, text='Sell', size=size.small)```
解决方案
我认为这正如预期的那样,ema_bull 和 ema_bear 之间存在负相关。如果 ema_bull 为真,那么 ema_bear 应该为假,反之亦然。如果 (ema_1 > ema_2) 为真,则 (ema_1 < ema_2) 为假。这就是为什么 plotshape 只绘制这两者之一的原因。
推荐阅读
- r - R 编程:当父母被移除时,悬空的子环境会发生什么?
- python - |U 和 U 关于字符串的 numpy dtype 说明符有什么区别
- javascript - 使用 AJAX 更改 iFrame Google Maps Src 标签
- asp.net-mvc - 来自外部帖子的路由视图
- python - 用户变量如何传递给主视图模板
- javascript - 在 box-shadow 属性上禁用 CSS 过渡
- python - 在 PyQtGraph 中设置 zValue
- python - 在 Python 中对回归函数使用详尽的优化算法
- docker - 将容器端口暴露给特定主机 IP
- java - Loaders 与 BroadcastReceivers 的优先级在主线程上启动