How to code:
(1) I want to highlight the unconfirmed candles
(2) similar to question #1, I want to highlight the unconfirmed area.
(3) Ignore the unconfirmed candles.
Thank you.
Using the zigzag indicator's 'unconfirmed' definition, here are 3 methods. The chart has the first method showing, but you can go to the input screen to select the other methods. The zigzag script I used already colored the zigzag 'unconfirmed' as dark_orange. I used this same color for the unconfirmed in the methods.
(1) #Candle Color of just unconfirmed, rest normal color
input use_candle_color = yes;
AssignPriceColor(if use_candle_color and !isConf then Color.DARK_ORANGE else Color.CURRENT);
(2)#Candle Area of unconfirmed
input use_candle_area = no;
def areahigh = if isConf[1] and !isConf then high else areahigh[1];
def arealow = if isConf[1] and !isConf then low else arealow[1];
def xisconf = GetValue(isConf, 0);
def xhigh = GetValue(areahigh, 0);
def xlow = GetValue(arealow, 0);
AddCloud(if !use_candle_area or xisconf then Double.NaN else xhigh, xlow, GlobalColor("Unconfirmed"), GlobalColor("Unconfirmed"));
(3)#Hide Candle Plot when unconfirmed, otherwise plot candles
input use_hide_candle = no;
hidePricePlot(use_hide_candle);
input charttype=chartType.CANDLE;
def o = open;
def h = high;
def l = low;
def c = close;
def o1 = if isconf and o<c then o else double.nan;
def c1 = if isconf and o<c then c else double.nan;
def h1 = if isconf and o<c then h else double.nan;
def l1 = if isconf and o<c then l else double.nan;
AddChart(growColor = color.green, fallColor = color.red, neutralColor = color.gray, high = h1, low = l1, open = c1, close = o1, type = chartType);
def o2 = if isconf and o >=c then o else double.nan;
def h2 = if isconf and o >=c then h else double.nan;
def l2 = if isconf and o >=c then l else double.nan;
def c2 = if isconf and o >=c then c else double.nan;
AddChart(growColor = color.red, fallColor = color.green, neutralColor = color.gray, high = h2, low = l2, open = o2, close = c2, type = chartType);[/CODE]
Code:
# TD Ameritrade IP Company, Inc. (c) 2011-2021
input price = close;
input reversalAmount = 8.0;
input showBubbles = no;
input showLabel = no;
Assert(reversalAmount > 0, "'reversal amount' should be positive: " + reversalAmount);
plot "ZZ%" = reference ZigZagHighLow(price, price, reversalAmount, 0, 1, 0);
def zzSave = if !IsNaN("ZZ%") then price else GetValue(zzSave, 1);
def chg = (price / GetValue(zzSave, 1) - 1) * 100;
def isUp = chg >= 0;
def isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue("ZZ%", 1)) and GetValue(isConf, 1));
"ZZ%".EnableApproximation();
"ZZ%".DefineColor("Up Trend", Color.UPTICK);
"ZZ%".DefineColor("Down Trend", Color.DOWNTICK);
"ZZ%".DefineColor("Undefined", Color.DARK_ORANGE);
"ZZ%".AssignValueColor(if !isConf then "ZZ%".Color("Undefined") else if isUp then "ZZ%".Color("Up Trend") else "ZZ%".Color("Down Trend"));
DefineGlobalColor("Unconfirmed", Color.DARK_ORANGE);
DefineGlobalColor("Up", Color.UPTICK);
DefineGlobalColor("Down", Color.DOWNTICK);
def barNumber = BarNumber();
AddChartBubble(showBubbles and !IsNaN("ZZ%") and barNumber != 1, price, Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"), isUp);
AddLabel(showLabel and barNumber != 1, (if isConf then "Confirmed " else "Unconfirmed ") + "ZigZag: " + Round(chg) + "%", if !isConf then GlobalColor("Unconfirmed") else if isUp then GlobalColor("Up") else GlobalColor("Down"));
#Candle Color
input use_candle_color = yes;
AssignPriceColor(if use_candle_color and !isConf then Color.DARK_ORANGE else Color.CURRENT);
#Candle Area
input use_candle_area = no;
def areahigh = if isConf[1] and !isConf then high else areahigh[1];
def arealow = if isConf[1] and !isConf then low else arealow[1];
def xisconf = GetValue(isConf, 0);
def xhigh = GetValue(areahigh, 0);
def xlow = GetValue(arealow, 0);
AddCloud(if !use_candle_area or xisconf then Double.NaN else xhigh, xlow, GlobalColor("Unconfirmed"), GlobalColor("Unconfirmed"));
#Hide Candle Plot
input use_hide_candle = no;
hidePricePlot(use_hide_candle);
input charttype=chartType.CANDLE;
def o = open;
def h = high;
def l = low;
def c = close;
def o1 = if isconf and o<c then o else double.nan;
def c1 = if isconf and o<c then c else double.nan;
def h1 = if isconf and o<c then h else double.nan;
def l1 = if isconf and o<c then l else double.nan;
AddChart(growColor = color.green, fallColor = color.red, neutralColor = color.gray, high = h1, low = l1, open = c1, close = o1, type = chartType);
def o2 = if isconf and o >=c then o else double.nan;
def h2 = if isconf and o >=c then h else double.nan;
def l2 = if isconf and o >=c then l else double.nan;
def c2 = if isconf and o >=c then c else double.nan;
AddChart(growColor = color.red, fallColor = color.green, neutralColor = color.gray, high = h2, low = l2, open = o2, close = c2, type = chartType);