Volume To Act As Support & Resistance For ThinkOrSwim

raj999

New member
Drawing the zones from the candle with respect to higher volume on 30 minutes candle on each day upto 5 days back(act as support and resistance) !!!!!

I view the 30 minutes chart where we can see in each day there is the highest volume bar, now with respect to that highest volume bar i want to draw zones on the candle . if the highest volume bar is Green then i want to create a zone on the candle from open to low of the candle however if the highest volume bar is Red then i want to draw a zone from high to open.

I was able to create this using AI.
If anyone would like to use the code, feel free to do so!
I'd also appreciate it if someone could help optimize it. I'm happy to share the improved version and reuse the optimized code myself."
uX3mqCZ.png

Code:
# ============================================================
# Multi-Timeframe Highest Volume Bar Zones
# ============================================================

declare upper;

input higherTimeframe = AggregationPeriod.DAY; # I changed it to 30 minutes
input lookbackDays = 10;
input startTime = 0930;
input endTime = 1600;
input showZones = yes; # Toggle to show/hide zones
input showLabels = yes; # Toggle to show/hide labels

def bar = BarNumber();

# Define regular market hours on higher timeframe
def isRegularHour = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;

# Use higher timeframe aggregation
def higherTFClose = close(period = higherTimeframe);
def higherTFOpen = open(period = higherTimeframe);
def higherTFHigh = high(period = higherTimeframe);
def higherTFLow = low(period = higherTimeframe);
def higherTFVolume = volume(period = higherTimeframe);
def higherTFBarCount = BarNumber();

# Detect day changes on higher timeframe
def currentDay = GetYYYYMMDD();
def newDay = currentDay != currentDay[1];

# Day index
def dayIndex = if newDay then dayIndex[1] + 1 else dayIndex[1];

# Days of interest - up to 10 days back
def highestDayIndex = HighestAll(dayIndex);

def isCurrentDay = dayIndex == highestDayIndex;
def isDayMinus1 = dayIndex == highestDayIndex - 1;
def isDayMinus2 = dayIndex == highestDayIndex - 2;
def isDayMinus3 = dayIndex == highestDayIndex - 3;
def isDayMinus4 = dayIndex == highestDayIndex - 4;
def isDayMinus5 = dayIndex == highestDayIndex - 5;
def isDayMinus6 = dayIndex == highestDayIndex - 6;
def isDayMinus7 = dayIndex == highestDayIndex - 7;
def isDayMinus8 = dayIndex == highestDayIndex - 8;
def isDayMinus9 = dayIndex == highestDayIndex - 9;
def isDayMinus10 = dayIndex == highestDayIndex - 10;

# Track highest volume for each day on higher timeframe
def volCurrentDay = if isCurrentDay and isRegularHour then higherTFVolume else 0;
def volDayMinus1 = if isDayMinus1 and isRegularHour then higherTFVolume else 0;
def volDayMinus2 = if isDayMinus2 and isRegularHour then higherTFVolume else 0;
def volDayMinus3 = if isDayMinus3 and isRegularHour then higherTFVolume else 0;
def volDayMinus4 = if isDayMinus4 and isRegularHour then higherTFVolume else 0;
def volDayMinus5 = if isDayMinus5 and isRegularHour then higherTFVolume else 0;
def volDayMinus6 = if isDayMinus6 and isRegularHour then higherTFVolume else 0;
def volDayMinus7 = if isDayMinus7 and isRegularHour then higherTFVolume else 0;
def volDayMinus8 = if isDayMinus8 and isRegularHour then higherTFVolume else 0;
def volDayMinus9 = if isDayMinus9 and isRegularHour then higherTFVolume else 0;
def volDayMinus10 = if isDayMinus10 and isRegularHour then higherTFVolume else 0;

# Find max volume for each day
def maxVolCurrentDay = HighestAll(volCurrentDay);
def maxVolDayMinus1 = HighestAll(volDayMinus1);
def maxVolDayMinus2 = HighestAll(volDayMinus2);
def maxVolDayMinus3 = HighestAll(volDayMinus3);
def maxVolDayMinus4 = HighestAll(volDayMinus4);
def maxVolDayMinus5 = HighestAll(volDayMinus5);
def maxVolDayMinus6 = HighestAll(volDayMinus6);
def maxVolDayMinus7 = HighestAll(volDayMinus7);
def maxVolDayMinus8 = HighestAll(volDayMinus8);
def maxVolDayMinus9 = HighestAll(volDayMinus9);
def maxVolDayMinus10 = HighestAll(volDayMinus10);

# Identify bars with max volume for each day
def isHighVolCurrentDay = isCurrentDay and isRegularHour and higherTFVolume == maxVolCurrentDay;
def isHighVolDayMinus1 = isDayMinus1 and isRegularHour and higherTFVolume == maxVolDayMinus1;
def isHighVolDayMinus2 = isDayMinus2 and isRegularHour and higherTFVolume == maxVolDayMinus2;
def isHighVolDayMinus3 = isDayMinus3 and isRegularHour and higherTFVolume == maxVolDayMinus3;
def isHighVolDayMinus4 = isDayMinus4 and isRegularHour and higherTFVolume == maxVolDayMinus4;
def isHighVolDayMinus5 = isDayMinus5 and isRegularHour and higherTFVolume == maxVolDayMinus5;
def isHighVolDayMinus6 = isDayMinus6 and isRegularHour and higherTFVolume == maxVolDayMinus6;
def isHighVolDayMinus7 = isDayMinus7 and isRegularHour and higherTFVolume == maxVolDayMinus7;
def isHighVolDayMinus8 = isDayMinus8 and isRegularHour and higherTFVolume == maxVolDayMinus8;
def isHighVolDayMinus9 = isDayMinus9 and isRegularHour and higherTFVolume == maxVolDayMinus9;
def isHighVolDayMinus10 = isDayMinus10 and isRegularHour and higherTFVolume == maxVolDayMinus10;

# Determine if highest volume bar was bullish (green) or bearish (red)
def isBullishDay0 = if isHighVolCurrentDay then higherTFClose > higherTFOpen else isBullishDay0[1];
def isBullishDay1 = if isHighVolDayMinus1 then higherTFClose > higherTFOpen else isBullishDay1[1];
def isBullishDay2 = if isHighVolDayMinus2 then higherTFClose > higherTFOpen else isBullishDay2[1];
def isBullishDay3 = if isHighVolDayMinus3 then higherTFClose > higherTFOpen else isBullishDay3[1];
def isBullishDay4 = if isHighVolDayMinus4 then higherTFClose > higherTFOpen else isBullishDay4[1];
def isBullishDay5 = if isHighVolDayMinus5 then higherTFClose > higherTFOpen else isBullishDay5[1];
def isBullishDay6 = if isHighVolDayMinus6 then higherTFClose > higherTFOpen else isBullishDay6[1];
def isBullishDay7 = if isHighVolDayMinus7 then higherTFClose > higherTFOpen else isBullishDay7[1];
def isBullishDay8 = if isHighVolDayMinus8 then higherTFClose > higherTFOpen else isBullishDay8[1];
def isBullishDay9 = if isHighVolDayMinus9 then higherTFClose > higherTFOpen else isBullishDay9[1];
def isBullishDay10 = if isHighVolDayMinus10 then higherTFClose > higherTFOpen else isBullishDay10[1];

# Store prices based on candle direction (using higher timeframe prices)
def upperPriceDay0 = if isHighVolCurrentDay then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay0[1];
def lowerPriceDay0 = if isHighVolCurrentDay then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay0[1];

def upperPriceDay1 = if isHighVolDayMinus1 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay1[1];
def lowerPriceDay1 = if isHighVolDayMinus1 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay1[1];

def upperPriceDay2 = if isHighVolDayMinus2 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay2[1];
def lowerPriceDay2 = if isHighVolDayMinus2 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay2[1];

def upperPriceDay3 = if isHighVolDayMinus3 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay3[1];
def lowerPriceDay3 = if isHighVolDayMinus3 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay3[1];

def upperPriceDay4 = if isHighVolDayMinus4 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay4[1];
def lowerPriceDay4 = if isHighVolDayMinus4 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay4[1];

def upperPriceDay5 = if isHighVolDayMinus5 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay5[1];
def lowerPriceDay5 = if isHighVolDayMinus5 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay5[1];

def upperPriceDay6 = if isHighVolDayMinus6 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay6[1];
def lowerPriceDay6 = if isHighVolDayMinus6 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay6[1];

def upperPriceDay7 = if isHighVolDayMinus7 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay7[1];
def lowerPriceDay7 = if isHighVolDayMinus7 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay7[1];

def upperPriceDay8 = if isHighVolDayMinus8 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay8[1];
def lowerPriceDay8 = if isHighVolDayMinus8 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay8[1];

def upperPriceDay9 = if isHighVolDayMinus9 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay9[1];
def lowerPriceDay9 = if isHighVolDayMinus9 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay9[1];

def upperPriceDay10 = if isHighVolDayMinus10 then (if higherTFClose > higherTFOpen then higherTFOpen else higherTFHigh) else upperPriceDay10[1];
def lowerPriceDay10 = if isHighVolDayMinus10 then (if higherTFClose > higherTFOpen then higherTFLow else higherTFOpen) else lowerPriceDay10[1];

# Get higher timeframe bar numbers for plotting
def highVolBarDay0 = if isHighVolCurrentDay then higherTFBarCount else highVolBarDay0[1];
def highVolBarDay1 = if isHighVolDayMinus1 then higherTFBarCount else highVolBarDay1[1];
def highVolBarDay2 = if isHighVolDayMinus2 then higherTFBarCount else highVolBarDay2[1];
def highVolBarDay3 = if isHighVolDayMinus3 then higherTFBarCount else highVolBarDay3[1];
def highVolBarDay4 = if isHighVolDayMinus4 then higherTFBarCount else highVolBarDay4[1];
def highVolBarDay5 = if isHighVolDayMinus5 then higherTFBarCount else highVolBarDay5[1];
def highVolBarDay6 = if isHighVolDayMinus6 then higherTFBarCount else highVolBarDay6[1];
def highVolBarDay7 = if isHighVolDayMinus7 then higherTFBarCount else highVolBarDay7[1];
def highVolBarDay8 = if isHighVolDayMinus8 then higherTFBarCount else highVolBarDay8[1];
def highVolBarDay9 = if isHighVolDayMinus9 then higherTFBarCount else highVolBarDay9[1];
def highVolBarDay10 = if isHighVolDayMinus10 then higherTFBarCount else highVolBarDay10[1];

# Current higher timeframe bar
def currentHigherTFBar = higherTFBarCount;

# Function to create plots for each day
script createBullishPlot {
input dayNumber = 0;
input lookbackDays = 10;
input showZones = yes;
input currentHigherTFBar = 0;
input highVolBar = 0;
input isBullish = no;
input upperPrice = 0;
input lowerPrice = 0;

plot result = if showZones and currentHigherTFBar >= highVolBar and lookbackDays >= dayNumber and isBullish then upperPrice else Double.NaN;
}

script createBearishPlot {
input dayNumber = 0;
input lookbackDays = 10;
input showZones = yes;
input currentHigherTFBar = 0;
input highVolBar = 0;
input isBullish = no;
input upperPrice = 0;
input lowerPrice = 0;

plot result = if showZones and currentHigherTFBar >= highVolBar and lookbackDays >= dayNumber and !isBullish then upperPrice else Double.NaN;
}

# Create plots for each day (0-10)
# Day 0 (Current)
plot BullishZoneUpperDay0 = if showZones and currentHigherTFBar >= highVolBarDay0 and isBullishDay0 then upperPriceDay0 else Double.NaN;
plot BullishZoneLowerDay0 = if showZones and currentHigherTFBar >= highVolBarDay0 and isBullishDay0 then lowerPriceDay0 else Double.NaN;
plot BearishZoneUpperDay0 = if showZones and currentHigherTFBar >= highVolBarDay0 and !isBullishDay0 then upperPriceDay0 else Double.NaN;
plot BearishZoneLowerDay0 = if showZones and currentHigherTFBar >= highVolBarDay0 and !isBullishDay0 then lowerPriceDay0 else Double.NaN;

# Day 1
plot BullishZoneUpperDay1 = if showZones and currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and isBullishDay1 then upperPriceDay1 else Double.NaN;
plot BullishZoneLowerDay1 = if showZones and currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and isBullishDay1 then lowerPriceDay1 else Double.NaN;
plot BearishZoneUpperDay1 = if showZones and currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and !isBullishDay1 then upperPriceDay1 else Double.NaN;
plot BearishZoneLowerDay1 = if showZones and currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and !isBullishDay1 then lowerPriceDay1 else Double.NaN;

# Day 2
plot BullishZoneUpperDay2 = if showZones and currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and isBullishDay2 then upperPriceDay2 else Double.NaN;
plot BullishZoneLowerDay2 = if showZones and currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and isBullishDay2 then lowerPriceDay2 else Double.NaN;
plot BearishZoneUpperDay2 = if showZones and currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and !isBullishDay2 then upperPriceDay2 else Double.NaN;
plot BearishZoneLowerDay2 = if showZones and currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and !isBullishDay2 then lowerPriceDay2 else Double.NaN;

# Day 3
plot BullishZoneUpperDay3 = if showZones and currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and isBullishDay3 then upperPriceDay3 else Double.NaN;
plot BullishZoneLowerDay3 = if showZones and currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and isBullishDay3 then lowerPriceDay3 else Double.NaN;
plot BearishZoneUpperDay3 = if showZones and currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and !isBullishDay3 then upperPriceDay3 else Double.NaN;
plot BearishZoneLowerDay3 = if showZones and currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and !isBullishDay3 then lowerPriceDay3 else Double.NaN;

# Day 4
plot BullishZoneUpperDay4 = if showZones and currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and isBullishDay4 then upperPriceDay4 else Double.NaN;
plot BullishZoneLowerDay4 = if showZones and currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and isBullishDay4 then lowerPriceDay4 else Double.NaN;
plot BearishZoneUpperDay4 = if showZones and currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and !isBullishDay4 then upperPriceDay4 else Double.NaN;
plot BearishZoneLowerDay4 = if showZones and currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and !isBullishDay4 then lowerPriceDay4 else Double.NaN;

# Day 5
plot BullishZoneUpperDay5 = if showZones and currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and isBullishDay5 then upperPriceDay5 else Double.NaN;
plot BullishZoneLowerDay5 = if showZones and currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and isBullishDay5 then lowerPriceDay5 else Double.NaN;
plot BearishZoneUpperDay5 = if showZones and currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and !isBullishDay5 then upperPriceDay5 else Double.NaN;
plot BearishZoneLowerDay5 = if showZones and currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and !isBullishDay5 then lowerPriceDay5 else Double.NaN;

# Day 6
plot BullishZoneUpperDay6 = if showZones and currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and isBullishDay6 then upperPriceDay6 else Double.NaN;
plot BullishZoneLowerDay6 = if showZones and currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and isBullishDay6 then lowerPriceDay6 else Double.NaN;
plot BearishZoneUpperDay6 = if showZones and currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and !isBullishDay6 then upperPriceDay6 else Double.NaN;
plot BearishZoneLowerDay6 = if showZones and currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and !isBullishDay6 then lowerPriceDay6 else Double.NaN;

# Day 7
plot BullishZoneUpperDay7 = if showZones and currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and isBullishDay7 then upperPriceDay7 else Double.NaN;
plot BullishZoneLowerDay7 = if showZones and currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and isBullishDay7 then lowerPriceDay7 else Double.NaN;
plot BearishZoneUpperDay7 = if showZones and currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and !isBullishDay7 then upperPriceDay7 else Double.NaN;
plot BearishZoneLowerDay7 = if showZones and currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and !isBullishDay7 then lowerPriceDay7 else Double.NaN;

# Day 8
plot BullishZoneUpperDay8 = if showZones and currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and isBullishDay8 then upperPriceDay8 else Double.NaN;
plot BullishZoneLowerDay8 = if showZones and currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and isBullishDay8 then lowerPriceDay8 else Double.NaN;
plot BearishZoneUpperDay8 = if showZones and currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and !isBullishDay8 then upperPriceDay8 else Double.NaN;
plot BearishZoneLowerDay8 = if showZones and currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and !isBullishDay8 then lowerPriceDay8 else Double.NaN;

# Day 9
plot BullishZoneUpperDay9 = if showZones and currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and isBullishDay9 then upperPriceDay9 else Double.NaN;
plot BullishZoneLowerDay9 = if showZones and currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and isBullishDay9 then lowerPriceDay9 else Double.NaN;
plot BearishZoneUpperDay9 = if showZones and currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and !isBullishDay9 then upperPriceDay9 else Double.NaN;
plot BearishZoneLowerDay9 = if showZones and currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and !isBullishDay9 then lowerPriceDay9 else Double.NaN;

# Day 10
plot BullishZoneUpperDay10 = if showZones and currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and isBullishDay10 then upperPriceDay10 else Double.NaN;
plot BullishZoneLowerDay10 = if showZones and currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and isBullishDay10 then lowerPriceDay10 else Double.NaN;
plot BearishZoneUpperDay10 = if showZones and currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and !isBullishDay10 then upperPriceDay10 else Double.NaN;
plot BearishZoneLowerDay10 = if showZones and currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and !isBullishDay10 then lowerPriceDay10 else Double.NaN;

# Create shaded zones
AddCloud(BullishZoneUpperDay0, BullishZoneLowerDay0, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay0, BearishZoneLowerDay0, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay1, BullishZoneLowerDay1, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay1, BearishZoneLowerDay1, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay2, BullishZoneLowerDay2, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay2, BearishZoneLowerDay2, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay3, BullishZoneLowerDay3, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay3, BearishZoneLowerDay3, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay4, BullishZoneLowerDay4, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay4, BearishZoneLowerDay4, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay5, BullishZoneLowerDay5, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay5, BearishZoneLowerDay5, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay6, BullishZoneLowerDay6, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay6, BearishZoneLowerDay6, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay7, BullishZoneLowerDay7, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay7, BearishZoneLowerDay7, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay8, BullishZoneLowerDay8, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay8, BearishZoneLowerDay8, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay9, BullishZoneLowerDay9, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay9, BearishZoneLowerDay9, Color.RED, Color.RED);

AddCloud(BullishZoneUpperDay10, BullishZoneLowerDay10, Color.GREEN, Color.GREEN);
AddCloud(BearishZoneUpperDay10, BearishZoneLowerDay10, Color.RED, Color.RED);

# Create boundary lines for each day
# Day 0
plot BullishUpperLineDay0 = if currentHigherTFBar >= highVolBarDay0 and isBullishDay0 then upperPriceDay0 else Double.NaN;
plot BullishLowerLineDay0 = if currentHigherTFBar >= highVolBarDay0 and isBullishDay0 then lowerPriceDay0 else Double.NaN;
plot BearishUpperLineDay0 = if currentHigherTFBar >= highVolBarDay0 and !isBullishDay0 then upperPriceDay0 else Double.NaN;
plot BearishLowerLineDay0 = if currentHigherTFBar >= highVolBarDay0 and !isBullishDay0 then lowerPriceDay0 else Double.NaN;

# Day 1
plot BullishUpperLineDay1 = if currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and isBullishDay1 then upperPriceDay1 else Double.NaN;
plot BullishLowerLineDay1 = if currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and isBullishDay1 then lowerPriceDay1 else Double.NaN;
plot BearishUpperLineDay1 = if currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and !isBullishDay1 then upperPriceDay1 else Double.NaN;
plot BearishLowerLineDay1 = if currentHigherTFBar >= highVolBarDay1 and lookbackDays >= 1 and !isBullishDay1 then lowerPriceDay1 else Double.NaN;

# Day 2
plot BullishUpperLineDay2 = if currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and isBullishDay2 then upperPriceDay2 else Double.NaN;
plot BullishLowerLineDay2 = if currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and isBullishDay2 then lowerPriceDay2 else Double.NaN;
plot BearishUpperLineDay2 = if currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and !isBullishDay2 then upperPriceDay2 else Double.NaN;
plot BearishLowerLineDay2 = if currentHigherTFBar >= highVolBarDay2 and lookbackDays >= 2 and !isBullishDay2 then lowerPriceDay2 else Double.NaN;

# Day 3
plot BullishUpperLineDay3 = if currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and isBullishDay3 then upperPriceDay3 else Double.NaN;
plot BullishLowerLineDay3 = if currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and isBullishDay3 then lowerPriceDay3 else Double.NaN;
plot BearishUpperLineDay3 = if currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and !isBullishDay3 then upperPriceDay3 else Double.NaN;
plot BearishLowerLineDay3 = if currentHigherTFBar >= highVolBarDay3 and lookbackDays >= 3 and !isBullishDay3 then lowerPriceDay3 else Double.NaN;

# Day 4
plot BullishUpperLineDay4 = if currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and isBullishDay4 then upperPriceDay4 else Double.NaN;
plot BullishLowerLineDay4 = if currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and isBullishDay4 then lowerPriceDay4 else Double.NaN;
plot BearishUpperLineDay4 = if currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and !isBullishDay4 then upperPriceDay4 else Double.NaN;
plot BearishLowerLineDay4 = if currentHigherTFBar >= highVolBarDay4 and lookbackDays >= 4 and !isBullishDay4 then lowerPriceDay4 else Double.NaN;

# Day 5
plot BullishUpperLineDay5 = if currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and isBullishDay5 then upperPriceDay5 else Double.NaN;
plot BullishLowerLineDay5 = if currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and isBullishDay5 then lowerPriceDay5 else Double.NaN;
plot BearishUpperLineDay5 = if currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and !isBullishDay5 then upperPriceDay5 else Double.NaN;
plot BearishLowerLineDay5 = if currentHigherTFBar >= highVolBarDay5 and lookbackDays >= 5 and !isBullishDay5 then lowerPriceDay5 else Double.NaN;

# Day 6
plot BullishUpperLineDay6 = if currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and isBullishDay6 then upperPriceDay6 else Double.NaN;
plot BullishLowerLineDay6 = if currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and isBullishDay6 then lowerPriceDay6 else Double.NaN;
plot BearishUpperLineDay6 = if currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and !isBullishDay6 then upperPriceDay6 else Double.NaN;
plot BearishLowerLineDay6 = if currentHigherTFBar >= highVolBarDay6 and lookbackDays >= 6 and !isBullishDay6 then lowerPriceDay6 else Double.NaN;

# Day 7
plot BullishUpperLineDay7 = if currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and isBullishDay7 then upperPriceDay7 else Double.NaN;
plot BullishLowerLineDay7 = if currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and isBullishDay7 then lowerPriceDay7 else Double.NaN;
plot BearishUpperLineDay7 = if currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and !isBullishDay7 then upperPriceDay7 else Double.NaN;
plot BearishLowerLineDay7 = if currentHigherTFBar >= highVolBarDay7 and lookbackDays >= 7 and !isBullishDay7 then lowerPriceDay7 else Double.NaN;

# Day 8
plot BullishUpperLineDay8 = if currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and isBullishDay8 then upperPriceDay8 else Double.NaN;
plot BullishLowerLineDay8 = if currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and isBullishDay8 then lowerPriceDay8 else Double.NaN;
plot BearishUpperLineDay8 = if currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and !isBullishDay8 then upperPriceDay8 else Double.NaN;
plot BearishLowerLineDay8 = if currentHigherTFBar >= highVolBarDay8 and lookbackDays >= 8 and !isBullishDay8 then lowerPriceDay8 else Double.NaN;

# Day 9
plot BullishUpperLineDay9 = if currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and isBullishDay9 then upperPriceDay9 else Double.NaN;
plot BullishLowerLineDay9 = if currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and isBullishDay9 then lowerPriceDay9 else Double.NaN;
plot BearishUpperLineDay9 = if currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and !isBullishDay9 then upperPriceDay9 else Double.NaN;
plot BearishLowerLineDay9 = if currentHigherTFBar >= highVolBarDay9 and lookbackDays >= 9 and !isBullishDay9 then lowerPriceDay9 else Double.NaN;

# Day 10
plot BullishUpperLineDay10 = if currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and isBullishDay10 then upperPriceDay10 else Double.NaN;
plot BullishLowerLineDay10 = if currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and isBullishDay10 then lowerPriceDay10 else Double.NaN;
plot BearishUpperLineDay10 = if currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and !isBullishDay10 then upperPriceDay10 else Double.NaN;
plot BearishLowerLineDay10 = if currentHigherTFBar >= highVolBarDay10 and lookbackDays >= 10 and !isBullishDay10 then lowerPriceDay10 else Double.NaN;

# Hide zone plots (keep them hidden, only use for clouds)
BullishZoneUpperDay0.Hide(); BullishZoneLowerDay0.Hide(); BearishZoneUpperDay0.Hide(); BearishZoneLowerDay0.Hide();
BullishZoneUpperDay1.Hide(); BullishZoneLowerDay1.Hide(); BearishZoneUpperDay1.Hide(); BearishZoneLowerDay1.Hide();
BullishZoneUpperDay2.Hide(); BullishZoneLowerDay2.Hide(); BearishZoneUpperDay2.Hide(); BearishZoneLowerDay2.Hide();
BullishZoneUpperDay3.Hide(); BullishZoneLowerDay3.Hide(); BearishZoneUpperDay3.Hide(); BearishZoneLowerDay3.Hide();
BullishZoneUpperDay4.Hide(); BullishZoneLowerDay4.Hide(); BearishZoneUpperDay4.Hide(); BearishZoneLowerDay4.Hide();
BullishZoneUpperDay5.Hide(); BullishZoneLowerDay5.Hide(); BearishZoneUpperDay5.Hide(); BearishZoneLowerDay5.Hide();
BullishZoneUpperDay6.Hide(); BullishZoneLowerDay6.Hide(); BearishZoneUpperDay6.Hide(); BearishZoneLowerDay6.Hide();
BullishZoneUpperDay7.Hide(); BullishZoneLowerDay7.Hide(); BearishZoneUpperDay7.Hide(); BearishZoneLowerDay7.Hide();
BullishZoneUpperDay8.Hide(); BullishZoneLowerDay8.Hide(); BearishZoneUpperDay8.Hide(); BearishZoneLowerDay8.Hide();
BullishZoneUpperDay9.Hide(); BullishZoneLowerDay9.Hide(); BearishZoneUpperDay9.Hide(); BearishZoneLowerDay9.Hide();
BullishZoneUpperDay10.Hide(); BullishZoneLowerDay10.Hide(); BearishZoneUpperDay10.Hide(); BearishZoneLowerDay10.Hide();

# Set line styles, colors, and weights for all days
# Day 0
BullishUpperLineDay0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay0.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay0.SetDefaultColor(Color.GREEN); BullishLowerLineDay0.SetDefaultColor(Color.GREEN);
BearishUpperLineDay0.SetDefaultColor(Color.RED); BearishLowerLineDay0.SetDefaultColor(Color.RED);
BullishUpperLineDay0.SetLineWeight(1); BullishLowerLineDay0.SetLineWeight(1);
BearishUpperLineDay0.SetLineWeight(1); BearishLowerLineDay0.SetLineWeight(1);

# Day 1
BullishUpperLineDay1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay1.SetDefaultColor(Color.GREEN); BullishLowerLineDay1.SetDefaultColor(Color.GREEN);
BearishUpperLineDay1.SetDefaultColor(Color.RED); BearishLowerLineDay1.SetDefaultColor(Color.RED);
BullishUpperLineDay1.SetLineWeight(1); BullishLowerLineDay1.SetLineWeight(1);
BearishUpperLineDay1.SetLineWeight(1); BearishLowerLineDay1.SetLineWeight(1);

# Day 2
BullishUpperLineDay2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay2.SetDefaultColor(Color.GREEN); BullishLowerLineDay2.SetDefaultColor(Color.GREEN);
BearishUpperLineDay2.SetDefaultColor(Color.RED); BearishLowerLineDay2.SetDefaultColor(Color.RED);
BullishUpperLineDay2.SetLineWeight(1); BullishLowerLineDay2.SetLineWeight(1);
BearishUpperLineDay2.SetLineWeight(1); BearishLowerLineDay2.SetLineWeight(1);

# Day 3
BullishUpperLineDay3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay3.SetDefaultColor(Color.GREEN); BullishLowerLineDay3.SetDefaultColor(Color.GREEN);
BearishUpperLineDay3.SetDefaultColor(Color.RED); BearishLowerLineDay3.SetDefaultColor(Color.RED);
BullishUpperLineDay3.SetLineWeight(1); BullishLowerLineDay3.SetLineWeight(1);
BearishUpperLineDay3.SetLineWeight(1); BearishLowerLineDay3.SetLineWeight(1);

# Day 4
BullishUpperLineDay4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay4.SetDefaultColor(Color.GREEN); BullishLowerLineDay4.SetDefaultColor(Color.GREEN);
BearishUpperLineDay4.SetDefaultColor(Color.RED); BearishLowerLineDay4.SetDefaultColor(Color.RED);
BullishUpperLineDay4.SetLineWeight(1); BullishLowerLineDay4.SetLineWeight(1);
BearishUpperLineDay4.SetLineWeight(1); BearishLowerLineDay4.SetLineWeight(1);

# Day 5
BullishUpperLineDay5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay5.SetDefaultColor(Color.GREEN); BullishLowerLineDay5.SetDefaultColor(Color.GREEN);
BearishUpperLineDay5.SetDefaultColor(Color.RED); BearishLowerLineDay5.SetDefaultColor(Color.RED);
BullishUpperLineDay5.SetLineWeight(1); BullishLowerLineDay5.SetLineWeight(1);
BearishUpperLineDay5.SetLineWeight(1); BearishLowerLineDay5.SetLineWeight(1);

# Day 6
BullishUpperLineDay6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay6.SetDefaultColor(Color.GREEN); BullishLowerLineDay6.SetDefaultColor(Color.GREEN);
BearishUpperLineDay6.SetDefaultColor(Color.RED); BearishLowerLineDay6.SetDefaultColor(Color.RED);
BullishUpperLineDay6.SetLineWeight(1); BullishLowerLineDay6.SetLineWeight(1);
BearishUpperLineDay6.SetLineWeight(1); BearishLowerLineDay6.SetLineWeight(1);

# Day 7
BullishUpperLineDay7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay7.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay7.SetDefaultColor(Color.GREEN); BullishLowerLineDay7.SetDefaultColor(Color.GREEN);
BearishUpperLineDay7.SetDefaultColor(Color.RED); BearishLowerLineDay7.SetDefaultColor(Color.RED);
BullishUpperLineDay7.SetLineWeight(1); BullishLowerLineDay7.SetLineWeight(1);
BearishUpperLineDay7.SetLineWeight(1); BearishLowerLineDay7.SetLineWeight(1);

# Day 8
BullishUpperLineDay8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay8.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay8.SetDefaultColor(Color.GREEN); BullishLowerLineDay8.SetDefaultColor(Color.GREEN);
BearishUpperLineDay8.SetDefaultColor(Color.RED); BearishLowerLineDay8.SetDefaultColor(Color.RED);
BullishUpperLineDay8.SetLineWeight(1); BullishLowerLineDay8.SetLineWeight(1);
BearishUpperLineDay8.SetLineWeight(1); BearishLowerLineDay8.SetLineWeight(1);

# Day 9
BullishUpperLineDay9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay9.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay9.SetDefaultColor(Color.GREEN); BullishLowerLineDay9.SetDefaultColor(Color.GREEN);
BearishUpperLineDay9.SetDefaultColor(Color.RED); BearishLowerLineDay9.SetDefaultColor(Color.RED);
BullishUpperLineDay9.SetLineWeight(1); BullishLowerLineDay9.SetLineWeight(1);
BearishUpperLineDay9.SetLineWeight(1); BearishLowerLineDay9.SetLineWeight(1);

# Day 10
BullishUpperLineDay10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BullishLowerLineDay10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BearishUpperLineDay10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); BearishLowerLineDay10.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
BullishUpperLineDay10.SetDefaultColor(Color.GREEN); BullishLowerLineDay10.SetDefaultColor(Color.GREEN);
BearishUpperLineDay10.SetDefaultColor(Color.RED); BearishLowerLineDay10.SetDefaultColor(Color.RED);
BullishUpperLineDay10.SetLineWeight(1); BullishLowerLineDay10.SetLineWeight(1);
BearishUpperLineDay10.SetLineWeight(1); BearishLowerLineDay10.SetLineWeight(1);

# Add timeframe label
AddLabel(showLabels, "Higher TF: " + GetAggregationPeriod() / 60000 + "min | Lookback: " + lookbackDays + " days", Color.WHITE);
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
620 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