# ==========================================
# MTFL Architect - Custom Watchlist Column
# ==========================================
input midBufferPercent = 1.0;
def CurH = high;
def CurL = low;
def CurC = close;
def PCH = CompoundValue(1, high[1], high);
def PCL = CompoundValue(1, low[1], low);
def PCM = (PCH + PCL) / 2;
def MidBuffer = PCM * midBufferPercent / 100;
def isInside = CurH < PCH and CurL > PCL;
def isBothSides = CurH > PCH and CurL < PCL;
def isSweepLow = CurL < PCL and CurH <= PCH;
def isSweepHigh = CurH > PCH and CurL >= PCL;
# --- Signal Detection ---
def isTU = CurH > PCH and CurL >= PCL and CurC > PCH;
def isTD = CurL < PCL and CurH <= PCH and CurC < PCL;
def isFTU = CurH > PCH and CurC < PCH and CurC > PCM and CurL > PCM;
def isFTD = CurL < PCL and CurC > PCL and CurC < PCM and CurH < PCM;
def isIBULL = isInside and CurL >= PCM;
def isIBEAR = isInside and CurH <= PCM;
def isIBAL = isInside and CurH > PCM and CurL < PCM;
def isIPIN = isInside and AbsValue(CurH - PCM) <= MidBuffer and AbsValue(CurL - PCM) <= MidBuffer;
def isOBULL = isBothSides and CurC > PCH;
def isOBEAR = isBothSides and CurC < PCL;
def isBITDU = isBothSides and CurC >= PCL and CurC < PCM;
def isBITDD = isBothSides and CurC <= PCH and CurC > PCM;
def isOSBULL_Active = isSweepLow and CurC > PCM;
def isOSBULL_Pot = isSweepLow and CurH >= PCM and CurC < PCM;
def isOSBEAR_Active = isSweepHigh and CurC < PCM;
def isOSBEAR_Pot = isSweepHigh and CurL <= PCM and CurC > PCM;
# --- Label Output ---
AddLabel(isTU, "TU", Color.GREEN);
AddLabel(isTD, "TD", Color.RED);
AddLabel(isFTU, "FTU", Color.DARK_RED);
AddLabel(isFTD, "FTD", Color.DARK_GREEN);
AddLabel(isIBULL, "IBULL", Color.GREEN);
AddLabel(isIBEAR, "IBEAR", Color.RED);
AddLabel(isIBAL, "IBAL", Color.YELLOW);
AddLabel(isIPIN, "IPIN", Color.WHITE);
AddLabel(isOBULL, "OBULL", Color.CYAN);
AddLabel(isOBEAR, "OBEAR", Color.MAGENTA);
AddLabel(isBITDU, "BITDU", Color.ORANGE);
AddLabel(isBITDD, "BITDD", Color.ORANGE);
AddLabel(isOSBULL_Active, "OSBULL", Color.CYAN);
AddLabel(isOSBULL_Pot, "OSBULL-Pot", Color.DARK_ORANGE);
AddLabel(isOSBEAR_Active, "OSBEAR", Color.MAGENTA);
AddLabel(isOSBEAR_Pot, "OSBEAR-Pot", Color.DARK_RED);
# --- Column Value (for sorting) ---
plot Signal =
if isTU then 1 else
if isTD then 2 else
if isFTU then 3 else
if isFTD then 4 else
if isOBULL then 5 else
if isOBEAR then 6 else
if isOSBULL_Active then 7 else
if isOSBEAR_Active then 8 else
if isOSBULL_Pot then 9 else
if isOSBEAR_Pot then 10 else
if isBITDU then 11 else
if isBITDD then 12 else
if isIBULL then 13 else
if isIBEAR then 14 else
if isIBAL then 15 else
if isIPIN then 16 else 0;
Signal.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
Signal.AssignValueColor(
if isTU then Color.GREEN else
if isTD then Color.RED else
if isFTU then Color.DARK_RED else
if isFTD then Color.DARK_GREEN else
if isOBULL then Color.CYAN else
if isOBEAR then Color.MAGENTA else
if isOSBULL_Active then Color.CYAN else
if isOSBEAR_Active then Color.MAGENTA else
if isOSBULL_Pot then Color.DARK_ORANGE else
if isOSBEAR_Pot then Color.DARK_RED else
if isBITDU then Color.ORANGE else
if isBITDD then Color.ORANGE else
if isIBULL then Color.GREEN else
if isIBEAR then Color.RED else
if isIBAL then Color.YELLOW else
if isIPIN then Color.WHITE else
Color.GRAY);