松脚本排序

时间:2020-06-29 19:26:47

标签: sorting pine-script

v4似乎缺少此基本功能,但是有没有办法破解解决方案?

我有几个移动平均线,想按它们离收盘价的距离排序。

1 个答案:

答案 0 :(得分:0)

我最终这样做了。不确定是否需要第一个for循环,但是否存在,以防案件顺序影响结果。

get_diff(up, src, series1, series2, series3) =>
    diff = src * 999
    for c = 1 to 2
        for i = 1 to 3
            val = 0.0
            if i == 1
                val := series1
            if i == 2
                val := series2
            if i == 3
                val := series3
            diff := up and val > src and val - src < diff ? val - src : not up and val < src and src - val < diff ? src - val : diff
                
    if diff == src * 999
        diff := 0
    diff

support1 = close - get_diff(false, close, ma1, ma2, ma3)
support2 = support1 - get_diff(false, support1, ma1, ma2, ma3)
support3 = support2 - get_diff(false, support2, ma1, ma2, ma3)
resistance1 = close + get_diff(true, close, ma1, ma2, ma3)
resistance2 = resistance1 + get_diff(true, resistance1, ma1, ma2, ma3)
resistance3 = resistance2 + get_diff(true, resistance2, ma1, ma2, ma3)