0

n= -1; Color = IIf((High < Ref(High,n) & Low > Ref(Low,n)), colorRed , colorWhite); Plot( Close, "Colored Price", Color, styleBar );

在此处输入图像描述

红色箭头指向条是母条,蓝色箭头指向白条是母条范围内的条内。所以我正在尝试将当前栏与母栏进行比较,如果当前栏在母栏的范围内,则直接比较前一个栏,但如果代码条件为真但它不工作不知道为什么,我尝试添加递减 n 值。请参考图片以获得更好的清晰度

n= -1; Color = IIf((High < Ref(High,n) & Low > Ref(Low,n)), colorRed && n= n--, colorWhite); Plot( Close, "Colored Price", Color, styleBar );

4

1 回答 1

0

我发现写出 for 循环更容易

function InsideBarColor() {

    local state;
    local isInsideBar;
    local index;
    
    local insideHigh;
    local insideLow;
    local priceColor;
    
    state = 0;
    isInsideBar = Inside();
    priceColor = colorDefault;
    
    for(index = 1; index < BarCount; index += 1) {
    
        if (state == 0 && isInsideBar[index] == True) {
        
            // Record the High/Low of the first inside bar.
            insideHigh = High[index-1];
            insideLow = Low[index-1];
            state = 1;
            priceColor[index] = colorRed;
        
        } else if(state == 1) {
        
            if (High[index] > insideHigh || Low[index] < insideLow) {
                // Price broke out of range
                priceColor[index] = colorWhite;
                state = 0;
            } else {
                // Price still inside range
                priceColor[index] = colorBlue;
            }
        
        } else {
            priceColor[index] = priceColor[index -1]; 
        }
    
    }
    
    return priceColor;

}

colors = InsideBarColor();
于 2020-09-10T23:34:03.097 回答