Watchlist color change based on Pivot Point

Qadeer

New member
I have a watchlist that changes color based on the pivot point. However, it only works during market hours and does not work pre- or after market hours. I was wondering if it could be improved to work both during the regular hours and pre and after market hours. Sometimes it does not change color on certian stocks. I highly appericte it if you could help with fixing it. Below is the code:

# Pivot Points Watchlist Column

input aggregationPeriod = AggregationPeriod.DAY;
def HIGHprev = high(period = aggregationPeriod)[1];
def LOWprev = low(period = aggregationPeriod)[1];
def CLOSEprev = close(period = aggregationPeriod)[1];

def PP = (HIGHprev + LOWprev + CLOSEprev) / 3;
def R1 = PP * 2 - LOWprev;
def S1 = PP * 2 - HIGHprev;
def R2 = PP + (HIGHprev - LOWprev);
def S2 = PP - (HIGHprev - LOWprev);
def R3 = PP * 2 + (HIGHprev - 2 * LOWprev);
def S3 = PP * 2 - (2 * HIGHprev - LOWprev);

# Set background color based on conditions
AssignBackgroundColor(
if close >= PP then Color.CYAN
else if close >= S1 then Color.WHITE
else if close >= S2 then Color.DARK_ORANGE
else if close >= S3 then Color.GRAY
else if close >= R1 then Color.Red
else if close >= R2 Then Color.Yellow
else if close >= R3 then color.Green
else Color.current
);
addlabel(yes, " ", color.current);
 
Solution
I have a watchlist that changes color based on the pivot point. However, it only works during market hours and does not work pre- or after market hours. I was wondering if it could be improved to work both during the regular hours and pre and after market hours. Sometimes it does not change color on certian stocks. I highly appericte it if you could help with fixing it. Below is the code:

# Pivot Points Watchlist Column

input aggregationPeriod = AggregationPeriod.DAY;
def HIGHprev = high(period = aggregationPeriod)[1];
def LOWprev = low(period = aggregationPeriod)[1];
def CLOSEprev = close(period = aggregationPeriod)[1];

def PP = (HIGHprev + LOWprev + CLOSEprev) / 3;
def R1 = PP * 2 - LOWprev;
def S1 = PP * 2 - HIGHprev;
def R2 =...
I have a watchlist that changes color based on the pivot point. However, it only works during market hours and does not work pre- or after market hours. I was wondering if it could be improved to work both during the regular hours and pre and after market hours. Sometimes it does not change color on certian stocks. I highly appericte it if you could help with fixing it. Below is the code:

# Pivot Points Watchlist Column

input aggregationPeriod = AggregationPeriod.DAY;
def HIGHprev = high(period = aggregationPeriod)[1];
def LOWprev = low(period = aggregationPeriod)[1];
def CLOSEprev = close(period = aggregationPeriod)[1];

def PP = (HIGHprev + LOWprev + CLOSEprev) / 3;
def R1 = PP * 2 - LOWprev;
def S1 = PP * 2 - HIGHprev;
def R2 = PP + (HIGHprev - LOWprev);
def S2 = PP - (HIGHprev - LOWprev);
def R3 = PP * 2 + (HIGHprev - 2 * LOWprev);
def S3 = PP * 2 - (2 * HIGHprev - LOWprev);

# Set background color based on conditions
AssignBackgroundColor(
if close >= PP then Color.CYAN
else if close >= S1 then Color.WHITE
else if close >= S2 then Color.DARK_ORANGE
else if close >= S3 then Color.GRAY
else if close >= R1 then Color.Red
else if close >= R2 Then Color.Yellow
else if close >= R3 then color.Green
else Color.current
);
addlabel(yes, " ", color.current);

This defines the pre/regular/post market times high/low/close from the previous day by using the volumeprofile indicator's profilehigh/low code in part. These were substituted into your code.

Please note I was not able to test this during the premarket this morning. This may not work as a watchlist as you want during non-trading hours. Your code was dependent upon using the aggregation DAY which only uses RTHrs. As this does not, the hope is that it might work for you.

Screenshot 2023-12-29 065148.png
Code:
#Pivot Points Watchlist Column
[CODE]#Pivot Points Watchlist Column
#Previous_HLC_Pre_RTH_Post

input pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE};
input onExpansion = no;
input profiles = 2;
input valueAreaPercent = 70;

def cond          = getyyyYMMDD()[1] != getyyyYMMDD();
def profilecount  = if cond then profilecount[1] + 1 else profilecount[1];
def profiletoday  = HighestAll(profilecount) - profilecount ;

profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = no, "numberOfProfiles" = profiles, "pricePerRow" = ticksize());
def con = CompoundValue(1, onExpansion, no);

def pc = if cond then close[1] else pc[1];
def ph = if IsNaN(close) then ph[1] else if IsNaN(vol.gethighest()[1]) and con then ph[1] else if cond == 1 then vol.GetHighest()[1] else ph[1];
def pl = if IsNaN(close) then pl[1] else if IsNaN(vol.GetLowest()[1]) and con then pl[1] else if cond == 1 then vol.GetLowest()[1] else pl[1];

def pClose = pc;
def pHigh  = ph;
def pLow   = pl;


#input aggregationPeriod = AggregationPeriod.DAY;
def HIGHprev = phigh;#high(period = aggregationPeriod)[1];
def LOWprev = plow;#low(period = aggregationPeriod)[1];
def CLOSEprev = pclose;#close(period = aggregationPeriod)[1];

def PP = (HIGHprev + LOWprev + CLOSEprev) / 3;
def R1 = PP * 2 - LOWprev;
def S1 = PP * 2 - HIGHprev;
def R2 = PP + (HIGHprev - LOWprev);
def S2 = PP - (HIGHprev - LOWprev);
def R3 = PP * 2 + (HIGHprev - 2 * LOWprev);
def S3 = PP * 2 - (2 * HIGHprev - LOWprev);
addlabel(1," ");
# Set background color based on conditions
AssignBackgroundColor(
if close >= PP then Color.CYAN
else if close >= S1 then Color.WHITE
else if close >= S2 then Color.DARK_ORANGE
else if close >= S3 then Color.GRAY
else if close >= R1 then Color.Red
else if close >= R2 Then Color.Yellow
else if close >= R3 then color.Green
else Color.current
);
 
Last edited:
Solution

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
357 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