请用pine语言写一下缠论笔的代码,注意处理包含关系,并使能够在tradingview中运行
时间: 2024-03-07 17:50:03 浏览: 341
缠论插件源码
以下是一个简单的PINE语言代码示例,用于计算缠论笔的高低点:
```
//@version=4
study("Chande's TrendScore")
// 计算笔的高低点
var high = high[1]
var low = low[1]
var lastPen = 0
var lastDirection = 0
var penCount = 0
for i = 1 to bar_index
if high[i] > high
high := high[i]
endif
if low[i] < low
low := low[i]
endif
if high[i] >= high and low[i] <= low
if lastPen == 0
lastPen := high
lastDirection := 1
elseif lastDirection == -1
penCount := penCount + 1
lastPen := low
lastDirection := 1
endif
endif
if low[i] <= low and high[i] >= high
if lastPen == 0
lastPen := low
lastDirection := -1
elseif lastDirection == 1
penCount := penCount + 1
lastPen := high
lastDirection := -1
endif
endif
plot(lastPen, color = penCount % 2 == 0 ? color.green : color.red)
// 处理包含关系
isUp = high > high[1] and low > low[1]
isDown = high < high[1] and low < low[1]
// 显示趋势得分
trendScore = 0.0
if isUp
trendScore := 100.0
elseif isDown
trendScore := -100.0
endif
plot(trendScore, style = plot.style_cross, linewidth = 3, color = color.blue)
```
这个代码会在TradingView图表上显示缠论笔的高低点,并且处理包含关系。它还计算趋势得分,并在图表上显示。请注意,这只是一个简单的示例代码,您可能需要根据自己的需求进行调整和修改。
阅读全文