I put together a ThinkScript indicator that tries to find important trap zones by looking for volume-confirmed breakouts of recent highs and lows. It draws two horizontal lines—one at the last big high breakout and one at the last big low breakout. The lines change color based on whether the price is above or below them, turning green when price is above (like support) and red when below (like resistance). It’s a simple way to visualize key levels, but honestly, it’s not working as well as I hoped. The signals can be unclear or unreliable at times. I’m open to any suggestions or improvements, like better ways to track states, filter false breakouts, or confirm signals. I’d appreciate any help to make it more useful. And feel free to roast my coding skills lol—I’m here to learn! Here is the code:
Thanks in advance!
Code:
input lookback = 20;
input VolumeMultiplier = 1.5;
def h = high;
def l = low;
def c = close;
def v = volume;
def na = Double.NaN;
def HL = Highest(h, lookback);
def LL = Lowest(l, lookback);
def BA = h > HL[1];
def BB = l < LL[1];
def avgV = Average(v, lookback);
def VS = v > avgV * VolumeMultiplier;
def BU = BA and VS;
def BD = BB and VS;
def CBIU = c < HL and BU[1];
def CBID = c > LL and BD[1];
def TU = CBIU;
def TD = CBID;
def trapUpValue = if TU then HL else trapUpValue[1];
def trapDownValue = if TD then LL else trapDownValue[1];
def showTrapHigh = CompoundValue(1, if TU then 1 else showTrapHigh[1], 0);
def showTrapLow = CompoundValue(1, if TD then 1 else showTrapLow[1], 0);
# Color logic: green if price above line, red if below
def highLineColorGreen = c > trapUpValue;
def lowLineColorGreen = c > trapDownValue;
# Plot Trap High Line
plot TrapHigh_Resist = if showTrapHigh then trapUpValue else na;
TrapHigh_Resist.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TrapHigh_Resist.AssignValueColor(
if highLineColorGreen then Color.GREEN else Color.RED
);
TrapHigh_Resist.SetLineWeight(2);
# Plot Trap Low Line
plot TrapLow_Support = if showTrapLow then trapDownValue else na;
TrapLow_Support.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
TrapLow_Support.AssignValueColor(
if lowLineColorGreen then Color.GREEN else Color.RED
);
TrapLow_Support.SetLineWeight(2);
# Trap arrows
plot TrapUpArrow = TU;
TrapUpArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
TrapUpArrow.SetDefaultColor(Color.RED);
plot TrapDownArrow = TD;
TrapDownArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
TrapDownArrow.SetDefaultColor(Color.GREEN);