0

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

enter image description here

Red arrow pointing bar is mother bar and blue arrow pointing white bar is inside bar within motherbar range. so i'm trying to compare current bar with mother bar, if current bar is inside the range of mother bar is compare immediate previous bar but i tried to add decrements n value if code condition true but its not working don't know why. Please refer image too for better clarity

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

1 Answers1

0

I found it easier to write out the for loops

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();
Ceres
  • 3,524
  • 3
  • 18
  • 25