ZigZagHighLow: Color Control

Carl-not-Karl

ToS Expert
VIP
I'm looking to have multi-color control of the ZigZagHighLow line rather than the default single color but my code is not quite there so seeking solution from the uTS community (see white arrows):

1747766074173.png

Code:
input priceH = high;
input priceL = low;
input percentageReversal = 0.01;
input absoluteReversal = 0;
input atrLength = 2;
input atrReversal = 3;
input tickReversal = 0;
input showBubbles = yes;

Assert(percentageReversal >= 0, "'percentage reversal' must not be negative: " + percentageReversal);
Assert(absoluteReversal >= 0, "'absolute reversal' must not be negative: " + absoluteReversal);
Assert(atrReversal >= 0, "'atr reversal' must not be negative: " + atrReversal);
Assert(tickReversal >= 0, "'ticks' must not be negative: " + tickReversal);
Assert(percentageReversal != 0 or absoluteReversal != 0 or atrReversal != 0 or tickReversal != 0, "Either 'percentage reversal' or 'absolute reversal' or 'atr reversal' or 'tick reversal' must not be zero");

def absReversal;
if (absoluteReversal != 0) {
    absReversal = absoluteReversal;
} else {
    absReversal = tickReversal * TickSize();
}

def hlPivot;
if (atrReversal != 0) {
    hlPivot = percentageReversal / 100 + WildersAverage(TrueRange(high, close, low), atrLength) / close * atrReversal;
} else {
    hlPivot = percentageReversal / 100;
}

def state = {default init, undefined, uptrend, downtrend};
def maxPriceH;
def minPriceL;
def newMax;
def newMin;
def prevMaxH = GetValue(maxPriceH, 1);
def prevMinL = GetValue(minPriceL, 1);

if GetValue(state, 1) == GetValue(state.init, 0) {
    maxPriceH = priceH;
    minPriceL = priceL;
    newMax = yes;
    newMin = yes;
    state = state.undefined;
} else if GetValue(state, 1) == GetValue(state.undefined, 0) {
    if priceH >= prevMaxH {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else if priceL <= prevMinL {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.undefined;
        maxPriceH = prevMaxH;
        minPriceL = prevMinL;
        newMax = no;
        newMin = no;
    }
} else if GetValue(state, 1) == GetValue(state.uptrend, 0) {
    if priceL <= prevMaxH - prevMaxH * hlPivot - absReversal {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.uptrend;
        if (priceH >= prevMaxH) {
            maxPriceH = priceH;
            newMax = yes;
        } else {
            maxPriceH = prevMaxH;
            newMax = no;
        }
        minPriceL = prevMinL;
        newMin = no;
    }
} else {
    if priceH >= prevMinL + prevMinL * hlPivot + absReversal {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        newMax = no;
        if (priceL <= prevMinL) {
            minPriceL = priceL;
            newMin = yes;
        } else {
            minPriceL = prevMinL;
            newMin = no;
        }
    }
}

def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(priceH), 0, barNumber));
def newState = GetValue(state, 0) != GetValue(state, 1);
def offset = barCount - barNumber + 1;
def highPoint = state == state.uptrend and priceH == maxPriceH;
def lowPoint = state == state.downtrend and priceL == minPriceL;

def lastH;
if highPoint and offset > 1 {
    lastH = fold iH = 1 to offset with tH = priceH while !IsNaN(tH) and !GetValue(newState, -iH) do if GetValue(newMax, -iH) or iH == offset - 1 and GetValue(priceH, -iH) == tH then Double.NaN else tH;
} else {
    lastH = Double.NaN;
}

def lastL;
if lowPoint and offset > 1 {
    lastL = fold iL = 1 to offset with tL = priceL while !IsNaN(tL) and !GetValue(newState, -iL) do if GetValue(newMin, -iL) or iL == offset - 1 and GetValue(priceL, -iL) == tL then Double.NaN else tL;
} else {
    lastL = Double.NaN;
}

plot ZZ;
if barNumber == 1 {
    ZZ = fold iF = 1 to offset with tP = Double.NaN while IsNaN(tP) do if GetValue(state, -iF) == GetValue(state.uptrend, 0) then priceL else if GetValue(state, -iF) == GetValue(state.downtrend, 0) then priceH else Double.NaN;
} else if barNumber == barCount {
    ZZ = if highPoint or state == state.downtrend and priceL > minPriceL then priceH else if lowPoint or state == state.uptrend and priceH < maxPriceH then priceL else Double.NaN;
} else {
    ZZ = if !IsNaN(lastH) then lastH else if !IsNaN(lastL) then lastL else Double.NaN;
}

def peak = (high > high[1] and high > high[2] and high > high[-1] and high > high[-2]);
def valley = (low < low[1] and low < low[2] and low < low[-1] and low < low[-2]);
def zzSave = if !IsNaN(ZZ) then priceH else GetValue(zzSave, 1);
def chg = priceH - GetValue(zzSave, 1);
def dir = if valley then -1 else if peak then 1 else dir[1];

ZZ.EnableApproximation();
ZZ.DefineColor("Up", Color.UPTICK);
ZZ.DefineColor("Down", Color.DOWNTICK);
zz.AssignValueColor(if dir > 0 then color.GREEN else if dir < 0 then color.RED else color.GRAY);
ZZ.SetLineWeight(2);
ZZ.SetStyle(1);
ZZ.HideBubble();
ZZ.HideTitle();
 
Last edited:
Solution
@Carl-not-Karl

change this code snippet:
def trend = if SignalBuy then 1 else if SignalSell then 0 else trend[1];
def pTrend = trend;

ZZ.AssignValueColor(
if pTrend then ZZ.Color("Up") else ZZ.Color("Down"));

to this:
def trend = if SignalBuy then 1 else if SignalSell then 0 else trend[1];
def pTrend = trend;

ZZ.AssignValueColor(
if !pTrend[1] and pTrend then ZZ.Color("Down") else
if pTrend[1] and !pTrend then ZZ.Color("Up") else
if pTrend then ZZ.Color("Up") else ZZ.Color("Down"));
8Ezh5Zu.png
What additional color are you trying to incorporate into the script, and what kind of condition will trigger it?
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

I'm looking to have multi-color control of the ZigZagHighLow line rather than the default single color but my code is not quite there so seeking solution from the uTS community (see white arrows):

View attachment 24796
Code:
input priceH = high;
input priceL = low;
input percentageReversal = 0.01;
input absoluteReversal = 0;
input atrLength = 2;
input atrReversal = 3;
input reversalAmount = 1.0;
input tickReversal = 0;
input showBubbles = yes;

Assert(percentageReversal >= 0, "'percentage reversal' must not be negative: " + percentageReversal);
Assert(absoluteReversal >= 0, "'absolute reversal' must not be negative: " + absoluteReversal);
Assert(atrReversal >= 0, "'atr reversal' must not be negative: " + atrReversal);
Assert(tickReversal >= 0, "'ticks' must not be negative: " + tickReversal);
Assert(percentageReversal != 0 or absoluteReversal != 0 or atrReversal != 0 or tickReversal != 0, "Either 'percentage reversal' or 'absolute reversal' or 'atr reversal' or 'tick reversal' must not be zero");

def absReversal;
if (absoluteReversal != 0) {
    absReversal = absoluteReversal;
} else {
    absReversal = tickReversal * TickSize();
}

def hlPivot;
if (atrReversal != 0) {
    hlPivot = percentageReversal / 100 + WildersAverage(TrueRange(high, close, low), atrLength) / close * atrReversal;
} else {
    hlPivot = percentageReversal / 100;
}

def state = {default init, undefined, uptrend, downtrend};
def maxPriceH;
def minPriceL;
def newMax;
def newMin;
def prevMaxH = GetValue(maxPriceH, 1);
def prevMinL = GetValue(minPriceL, 1);

if GetValue(state, 1) == GetValue(state.init, 0) {
    maxPriceH = priceH;
    minPriceL = priceL;
    newMax = yes;
    newMin = yes;
    state = state.undefined;
} else if GetValue(state, 1) == GetValue(state.undefined, 0) {
    if priceH >= prevMaxH {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else if priceL <= prevMinL {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.undefined;
        maxPriceH = prevMaxH;
        minPriceL = prevMinL;
        newMax = no;
        newMin = no;
    }
} else if GetValue(state, 1) == GetValue(state.uptrend, 0) {
    if priceL <= prevMaxH - prevMaxH * hlPivot - absReversal {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.uptrend;
        if (priceH >= prevMaxH) {
            maxPriceH = priceH;
            newMax = yes;
        } else {
            maxPriceH = prevMaxH;
            newMax = no;
        }
        minPriceL = prevMinL;
        newMin = no;
    }
} else {
    if priceH >= prevMinL + prevMinL * hlPivot + absReversal {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        newMax = no;
        if (priceL <= prevMinL) {
            minPriceL = priceL;
            newMin = yes;
        } else {
            minPriceL = prevMinL;
            newMin = no;
        }
    }
}

def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(priceH), 0, barNumber));
def newState = GetValue(state, 0) != GetValue(state, 1);
def offset = barCount - barNumber + 1;
def highPoint = state == state.uptrend and priceH == maxPriceH;
def lowPoint = state == state.downtrend and priceL == minPriceL;

def lastH;
if highPoint and offset > 1 {
    lastH = fold iH = 1 to offset with tH = priceH while !IsNaN(tH) and !GetValue(newState, -iH) do if GetValue(newMax, -iH) or iH == offset - 1 and GetValue(priceH, -iH) == tH then Double.NaN else tH;
} else {
    lastH = Double.NaN;
}

def lastL;
if lowPoint and offset > 1 {
    lastL = fold iL = 1 to offset with tL = priceL while !IsNaN(tL) and !GetValue(newState, -iL) do if GetValue(newMin, -iL) or iL == offset - 1 and GetValue(priceL, -iL) == tL then Double.NaN else tL;
} else {
    lastL = Double.NaN;
}

plot ZZ;
if barNumber == 1 {
    ZZ = fold iF = 1 to offset with tP = Double.NaN while IsNaN(tP) do if GetValue(state, -iF) == GetValue(state.uptrend, 0) then priceL else if GetValue(state, -iF) == GetValue(state.downtrend, 0) then priceH else Double.NaN;
} else if barNumber == barCount {
    ZZ = if highPoint or state == state.downtrend and priceL > minPriceL then priceH else if lowPoint or state == state.uptrend and priceH < maxPriceH then priceL else Double.NaN;
} else {
    ZZ = if !IsNaN(lastH) then lastH else if !IsNaN(lastL) then lastL else Double.NaN;
}

def zzSave = if !IsNaN(ZZ) then priceH else getValue(zzSave, 1);
def chg = priceH - getValue(zzSave, 1);
def isUp = chg >= 0;

ZZ.EnableApproximation();
ZZ.DefineColor("Up", Color.UPTICK);
ZZ.DefineColor("Down", Color.DOWNTICK);
#ZZ.AssignValueColor(if isUp then ZZ.Color("Up") else ZZ.Color("Down")); # from study: ZigZagSign
ZZ.AssignValueColor(if isUp then ZZ.Color("Up") else ZZ.Color("Down"));
ZZ.SetLineWeight(3);
ZZ.SetStyle(1);
ZZ.HideBubble();
ZZ.HideTitle();
#--------------------------
#def prevPivotHigh = GetValue(maxPriceH, 1);
#def prevPivotLow = GetValue(minPriceL, 1);

#AddChartBubble(showBubbles and !IsNaN(lastH), lastH, if lastH > prevPivotHigh then "HH" else "LH", if lastH > prevPivotHigh then Color.GREEN else Color.RED, no);
#AddChartBubble(showBubbles and !IsNaN(lastL), lastL, if lastL < prevPivotLow then "LL" else "HL", if lastL < prevPivotLow then Color.RED else Color.GREEN, yes);
#--------------------------
def na = Double.NaN;
def bn = BarNumber();
def big = 99999;

def peak = (high > high[1] and high > high[2] and high > high[-1] and high > high[-2]);
def valley = (low < low[1] and low < low[2] and low < low[-1] and low < low[-2]);

def pklevel;
def vallevel;
def pkval;
if bn == 1
then {
    pklevel = high;
    vallevel = big;
    pkval = 0;
} else if !IsNaN(ZZ) and peak
then {
# peak
    pklevel = high;
    vallevel = vallevel[1];
    pkval = 1;
} else if !IsNaN(ZZ) and valley
then {
# valley
    pklevel = pklevel[1];
    vallevel = low;
    pkval = -1;
} else {
    pklevel = pklevel[1];
    vallevel = vallevel[1];
    pkval = 0;
}

def EIH = ZigZagHighLow("Price H" = priceH, "Price L" = priceL,
 "percentage reversal" = .01,
 "absolute reversal"   = .01,
 "atr length"          = atrLength,
 "atr reversal"        = atrReversal).lastH;

def SignalSELL = !IsNaN(EIH);
AddChartBubble(SignalSELL, high, "3", Color.RED, yes);
#plot SignalSELL = !isNAN(EIH);
#SignalSELL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#SignalSELL.SetDefaultColor(Color.RED);

def EIL = ZigZagHighLow("Price H" = priceH, "Price L" = priceL,
 "percentage reversal" = .01,
 "absolute reversal"   = .01,
 "atr length"          = atrLength,
 "atr reversal"        = atrReversal).lastL;

def SignalBUY = !IsNaN(EIL);
AddChartBubble(SignalBUY, low, "3", Color.GREEN, no);
#plot SignalBUY = !isNaN(EIL);
#SignalBUY.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#SignalBUY.SetDefaultColor(Color.GREEN);

multi color?
the lines have 2 colors, what do you really want?

color is determined on every bar
here is a test bubble to to show some values

Code:
def zzSave = if !IsNaN(ZZ) then priceH else getValue(zzSave, 1);
def chg = priceH - getValue(zzSave, 1);
def isUp = chg >= 0;

addchartbubble(1, low,
zz + "\n" +
zzsave + "\n" +
priceh + "\n" +
chg + "\n" +
isup + "\n" 
,color.yellow, no);
 
What additional color are you trying to incorporate into the script, and what kind of condition will trigger it?
Basic: RED = Down | GREEN = Up
...with option to change to whatever color/transparency you want:

1747875616331.png


In the post #1 image you can see the Uptrend line starts RED and then transitions to GREEN at the white arrows.

Here is another instance where the uptrend line starts GREEN, turns RED for 1 bar, and then turns GREEN :

1747876079143.png


The majority of the code in post #1 is from the ZigZagHighLow study.
In the code the plot ZZ starts at row 128.
 
Chart share with no bar/candles displayed: https://tos.mx/!cTfOHSTs

There should be one continuous colored line for each trend direction but I cannot find the error in the code in post #1.

finally after 4 posts, you say what you want
'one continuous colored line for each trend direction'

i told you what the problem is in post 3. color is calaculated on every bar.

if you want a line of 1 color, then set a variable after peaks and valleys to represent that.
def dir = if valley then -1 else if peak then 1 else dir[1]
....if dir > 0 then color.green else if dir < 0 then color.red else color.gray....
 
finally after 4 posts, you say what you want
'one continuous colored line for each trend direction'

i told you what the problem is in post 3. color is calaculated on every bar.

if you want a line of 1 color, then set a variable after peaks and valleys to represent that.
def dir = if valley then -1 else if peak then 1 else dir[1]
....if dir > 0 then color.green else if dir < 0 then color.red else color.gray....
Post #1 Code has been slimmed down to just focus on the lines, no bubbles.
Uptrends should be all GREEN and downtrends all RED, no 3rd color.
It also incorporates what you posted in threads #3 and #7 (but with my interpretation and possibly incorrect).
Here is an image:

1747930172600.png
 
@Carl-not-Karl
does this further your quest?
O61mQk0.png

Ruby:
input priceH = high;
input priceL = low;
input percentageReversal = 0.01;
input absoluteReversal = 0;
input atrLength = 2;
input atrReversal = 3;
input reversalAmount = 1.0;
input tickReversal = 0;
input showBubbles = yes;

Assert(percentageReversal >= 0, "'percentage reversal' must not be negative: " + percentageReversal);
Assert(absoluteReversal >= 0, "'absolute reversal' must not be negative: " + absoluteReversal);
Assert(atrReversal >= 0, "'atr reversal' must not be negative: " + atrReversal);
Assert(tickReversal >= 0, "'ticks' must not be negative: " + tickReversal);
Assert(percentageReversal != 0 or absoluteReversal != 0 or atrReversal != 0 or tickReversal != 0, "Either 'percentage reversal' or 'absolute reversal' or 'atr reversal' or 'tick reversal' must not be zero");

def absReversal;
if (absoluteReversal != 0) {
    absReversal = absoluteReversal;
} else {
    absReversal = tickReversal * TickSize();
}

def hlPivot;
if (atrReversal != 0) {
    hlPivot = percentageReversal / 100 + WildersAverage(TrueRange(high, close, low), atrLength) / close * atrReversal;
} else {
    hlPivot = percentageReversal / 100;
}

def state = {default init, undefined, uptrend, downtrend};
def maxPriceH;
def minPriceL;
def newMax;
def newMin;
def prevMaxH = GetValue(maxPriceH, 1);
def prevMinL = GetValue(minPriceL, 1);

if GetValue(state, 1) == GetValue(state.init, 0) {
    maxPriceH = priceH;
    minPriceL = priceL;
    newMax = yes;
    newMin = yes;
    state = state.undefined;
} else if GetValue(state, 1) == GetValue(state.undefined, 0) {
    if priceH >= prevMaxH {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else if priceL <= prevMinL {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.undefined;
        maxPriceH = prevMaxH;
        minPriceL = prevMinL;
        newMax = no;
        newMin = no;
    }
} else if GetValue(state, 1) == GetValue(state.uptrend, 0) {
    if priceL <= prevMaxH - prevMaxH * hlPivot - absReversal {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        minPriceL = priceL;
        newMax = no;
        newMin = yes;
    } else {
        state = state.uptrend;
        if (priceH >= prevMaxH) {
            maxPriceH = priceH;
            newMax = yes;
        } else {
            maxPriceH = prevMaxH;
            newMax = no;
        }
        minPriceL = prevMinL;
        newMin = no;
    }
} else {
    if priceH >= prevMinL + prevMinL * hlPivot + absReversal {
        state = state.uptrend;
        maxPriceH = priceH;
        minPriceL = prevMinL;
        newMax = yes;
        newMin = no;
    } else {
        state = state.downtrend;
        maxPriceH = prevMaxH;
        newMax = no;
        if (priceL <= prevMinL) {
            minPriceL = priceL;
            newMin = yes;
        } else {
            minPriceL = prevMinL;
            newMin = no;
        }
    }
}

def barNumber = BarNumber();
def barCount = HighestAll(If(IsNaN(priceH), 0, barNumber));
def newState = GetValue(state, 0) != GetValue(state, 1);
def offset = barCount - barNumber + 1;
def highPoint = state == state.uptrend and priceH == maxPriceH;
def lowPoint = state == state.downtrend and priceL == minPriceL;

def lastH;
if highPoint and offset > 1 {
    lastH = fold iH = 1 to offset with tH = priceH while !IsNaN(tH) and !GetValue(newState, -iH) do if GetValue(newMax, -iH) or iH == offset - 1 and GetValue(priceH, -iH) == tH then Double.NaN else tH;
} else {
    lastH = Double.NaN;
}

def lastL;
if lowPoint and offset > 1 {
    lastL = fold iL = 1 to offset with tL = priceL while !IsNaN(tL) and !GetValue(newState, -iL) do if GetValue(newMin, -iL) or iL == offset - 1 and GetValue(priceL, -iL) == tL then Double.NaN else tL;
} else {
    lastL = Double.NaN;
}

plot ZZ;
if barNumber == 1 {
    ZZ = fold iF = 1 to offset with tP = Double.NaN while IsNaN(tP) do if GetValue(state, -iF) == GetValue(state.uptrend, 0) then priceL else if GetValue(state, -iF) == GetValue(state.downtrend, 0) then priceH else Double.NaN;
} else if barNumber == barCount {
    ZZ = if highPoint or state == state.downtrend and priceL > minPriceL then priceH else if lowPoint or state == state.uptrend and priceH < maxPriceH then priceL else Double.NaN;
} else {
    ZZ = if !IsNaN(lastH) then lastH else if !IsNaN(lastL) then lastL else Double.NaN;
}

def zzSave = if !IsNaN(ZZ) then priceH else getValue(zzSave, 1);
def chg = priceH - getValue(zzSave, 1);
def isUp = chg >= 0;

ZZ.EnableApproximation();
ZZ.DefineColor("Up", Color.UPTICK);
ZZ.DefineColor("Down", Color.DOWNTICK);
#ZZ.AssignValueColor(if isUp then ZZ.Color("Up") else ZZ.Color("Down")); # from study: ZigZagSign

ZZ.SetLineWeight(3);
ZZ.SetStyle(1);
ZZ.HideBubble();
ZZ.HideTitle();
#--------------------------
#def prevPivotHigh = GetValue(maxPriceH, 1);
#def prevPivotLow = GetValue(minPriceL, 1);

#AddChartBubble(showBubbles and !IsNaN(lastH), lastH, if lastH > prevPivotHigh then "HH" else "LH", if lastH > prevPivotHigh then Color.GREEN else Color.RED, no);
#AddChartBubble(showBubbles and !IsNaN(lastL), lastL, if lastL < prevPivotLow then "LL" else "HL", if lastL < prevPivotLow then Color.RED else Color.GREEN, yes);
#--------------------------
def na = Double.NaN;
def bn = BarNumber();
def big = 99999;

def peak = (high > high[1] and high > high[2] and high > high[-1] and high > high[-2]);
def valley = (low < low[1] and low < low[2] and low < low[-1] and low < low[-2]);

def pklevel;
def vallevel;
def pkval;
if bn == 1
then {
    pklevel = high;
    vallevel = big;
    pkval = 0;
} else if !IsNaN(ZZ) and peak
then {
# peak
    pklevel = high;
    vallevel = vallevel[1];
    pkval = 1;
} else if !IsNaN(ZZ) and valley
then {
# valley
    pklevel = pklevel[1];
    vallevel = low;
    pkval = -1;
} else {
    pklevel = pklevel[1];
    vallevel = vallevel[1];
    pkval = 0;
}

def EIH = ZigZagHighLow("Price H" = priceH, "Price L" = priceL,
 "percentage reversal" = .01,
 "absolute reversal"   = .01,
 "atr length"          = atrLength,
 "atr reversal"        = atrReversal).lastH;

def SignalSELL = !IsNaN(EIH);
AddChartBubble(SignalSELL, high, "3", Color.RED, yes);
#plot SignalSELL = !isNAN(EIH);
#SignalSELL.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#SignalSELL.SetDefaultColor(Color.RED);

def EIL = ZigZagHighLow("Price H" = priceH, "Price L" = priceL,
 "percentage reversal" = .01,
 "absolute reversal"   = .01,
 "atr length"          = atrLength,
 "atr reversal"        = atrReversal).lastL;

def SignalBUY = !IsNaN(EIL);
AddChartBubble(SignalBUY, low, "3", Color.GREEN, no);
#plot SignalBUY = !isNaN(EIL);
#SignalBUY.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#SignalBUY.SetDefaultColor(Color.GREEN);

def trend = if SignalBuy then 1 else if SignalSell then 0 else trend[1];
def pTrend = trend;

ZZ.AssignValueColor(if pTrend then ZZ.Color("Up") else ZZ.Color("Down"));
 
@Carl-not-Karl

change this code snippet:
def trend = if SignalBuy then 1 else if SignalSell then 0 else trend[1];
def pTrend = trend;

ZZ.AssignValueColor(
if pTrend then ZZ.Color("Up") else ZZ.Color("Down"));

to this:
def trend = if SignalBuy then 1 else if SignalSell then 0 else trend[1];
def pTrend = trend;

ZZ.AssignValueColor(
if !pTrend[1] and pTrend then ZZ.Color("Down") else
if pTrend[1] and !pTrend then ZZ.Color("Up") else
if pTrend then ZZ.Color("Up") else ZZ.Color("Down"));
8Ezh5Zu.png
 
Solution

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
401 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top