首页 > 解决方案 > 在脚本中向前和向后移动?

问题描述

我是松树脚本的新手,所以如果问题很简单或不可能,请原谅。

这是我的想法:

如果可能的话,我想写一个松树脚本(在交易视图中),这样对于任何绿色蜡烛(每天的时间范围内)计算两个数字:

number_1:之后连续的绿色蜡烛数。

number_2:在此之前连续的绿色蜡烛的数量。

同样对于任何绿色蜡烛,我想在它上面写 number_1,我想在它下面写 number_2。

预先感谢您的帮助和评论。

标签: pine-script

解决方案


int greenCount = na

if close > open and close[1] < open[1]
    greenCount := 1
else if close > open and close[1] > open[1]
    greenCount := greenCount[1] + 1

if close < open and close[1] > open[1] and greenCount[1] > 1
    for i = 2 to greenCount[1]
        label.new(x = bar_index - i, y = high[i], style = label.style_label_down, color = #00000000, textcolor = color.blue, text = tostring(i - 1))

if not na(greenCount) and greenCount > 1
    label.new(x = bar_index, y = low, style = label.style_label_up, color = #00000000, textcolor = color.green, text = tostring(greenCount - 1))

推荐阅读