pine-script - 因为要计算从绿色三角形到红色三角形而不是绿色三角形到另一个绿色的距离
问题描述
我有一个用于多头的绿色三角形和一个用于短裤的红色三角形。Barssince 正在从绿色三角形到另一个绿色三角形,从一个红色到另一个红色。我想要的是从绿色到红色三角形。
fastSMA = sma(close, 15)
slowSMA = sma(close, 45)
enterLong = crossover(fastSMA, slowSMA)
enterShort = crossunder(fastSMA, slowSMA)
entryPrice = valuewhen(enterLong or enterShort, close, 0)
plot(barsSinceLong, color = color.yellow)
plot(barsSinceShort, color = color.purple)
if barsSinceLong == 0 and barsSinceShort == 0
c := c_NOT_IN_TRADE
if barsSinceLong > 0 and close < entryPrice
c := c_LONG_ABOVE_ENTRYPRICE
else if barsSinceLong > 0 and close > entryPrice
c := c_LONG_BELOW_ENTRYPRICE
else if barsSinceShort > 0 and close > entryPrice
c := c_SHORT_BELOW_ENTRYPRICE
else if barsSinceShort > 0 and close < entryPrice
c := c_SHORT_ABOVE_ENTRYPRICE
解决方案
你已经绘制了两个 barsince(),所以你可以看到这个函数是如何工作的,你可以做一个cross(barsSinceLong, barsSinceShort)
,这样你就可以从长到短。
推荐阅读
- kotlin - 有没有可以在 Dart 中编写像 Future&then 这样的挂起函数的函数?
- java - JMH Benchmark 性能怪异,因为 @Param 注释
- postman - 如何在邮递员中为 2 路 TLS 添加我信任的服务器证书?
- typescript - TypeScript [需要,导入] 错误 | 外部节点模块 | 吞咽
- python - 在这种情况下,如何使用 barh() 在条形图上显示每个条形的值?
- postgresql - 带有 pl/sh 语言问题的 Postgresql 上的 AFTER UPDATE 触发器
- r - R中基于继承的顺序
- html - 如何为 devtools 指定 bundle.js.map(source map) 文件路径
- rust - Rust 通过 HashSet 示例借用不可变(错误 E0502)
- javascript - 用于测试假值的运算符,将零视为真值