Add Chart Label to compare Cumulative Overnight Volume to Avg Overnight Vol

GOCUSH

New member
In TOS Studies there is a Study named CumulativeOvernightVolume with plots for CumulativeOvernightVolume and AverageOvernightVolume on lines 42 and 43, respectively.

I have successfully added this Study to my Chart, and now I would like to Add a Label in the Upper Left corner of my chart. The new Label needs to show the ratio of Average-to-Cumulative Volume

Additionally, I would like the Label color to change from (some dull color) to GREEN when the Cumulative overnight volume is more than X times (an input) the Average Volume

If you can help me add this feature, I would be grateful.
 
Solution
In TOS Studies there is a Study named CumulativeOvernightVolume with plots for CumulativeOvernightVolume and AverageOvernightVolume on lines 42 and 43, respectively.

I have successfully added this Study to my Chart, and now I would like to Add a Label in the Upper Left corner of my chart. The new Label needs to show the ratio of Average-to-Cumulative Volume

Additionally, I would like the Label color to change from (some dull color) to GREEN when the Cumulative overnight volume is more than X times (an input) the Average Volume

If you can help me add this feature, I would be grateful.

i added code to the end of the study.
it reads values in premarket and saves the last for during...
In TOS Studies there is a Study named CumulativeOvernightVolume with plots for CumulativeOvernightVolume and AverageOvernightVolume on lines 42 and 43, respectively.

I have successfully added this Study to my Chart, and now I would like to Add a Label in the Upper Left corner of my chart. The new Label needs to show the ratio of Average-to-Cumulative Volume

Additionally, I would like the Label color to change from (some dull color) to GREEN when the Cumulative overnight volume is more than X times (an input) the Average Volume

If you can help me add this feature, I would be grateful.

i added code to the end of the study.
it reads values in premarket and saves the last for during daytime.
it compares the 2 values , with a default factor of 5. if this is true, then label is green
def ca_isbig = cum > (avg * factor);


Code:
#vol_compare_night

#https://usethinkscript.com/threads/add-chart-label-to-compare-cumulative-overnight-volume-to-avg-overnight-vol.20199/
#Add Chart Label to compare Cumulative Overnight Volume to Avg Overnight Vol
#GOCUSH  Jan 6, 2025  #1

#In TOS Studies there is a Study named CumulativeOvernightVolume
# with plots for CumulativeOvernightVolume and AverageOvernightVolume on lines 42 and 43

# Add a Label to show the ratio of Average-to-Cumulative Volume

#Additionally, I would like the Label color to change from (some dull color) to GREEN when the Cumulative overnight volume is more than X times (an input) the Average Volume



# CumulativeOvernightVolume
declare lower;
declare hide_on_daily;

input nightSessionFromMidnight = 0100;
input firstHourTrading = 0930;
input mainSession = 1030;
input nightSessionFromMainSessionEnd = 1615;
input paintBars = yes;

def isNightSessionFromMidnight = SecondsFromTime(nightSessionFromMidnight) >= 0 and SecondsTillTime(firstHourTrading) > 0;
def isFirstHourTrading = SecondsFromTime(firstHourTrading) >= 0 and SecondsTillTime(mainSession) > 0;
def isMainSession = SecondsFromTime(mainSession) >= 0 and SecondsTillTime(nightSessionFromMainSessionEnd) > 0;

def newNightSessionFromMidnight = isNightSessionFromMidnight and !isNightSessionFromMidnight[1];
def cOvernightVolume = if newNightSessionFromMidnight then volume else if isNightSessionFromMidnight then cOvernightVolume[1] + volume else cOvernightVolume[1];

def count = count[1] + if newNightSessionFromMidnight then 1 else 0;

def overnightVolume1;
def overnightVolume2;
def overnightVolume3;
def overnightVolume4;
def overnightVolume5;
if (newNightSessionFromMidnight and count > 1) {
    overnightVolume1 = cOvernightVolume[1];
    overnightVolume2 = overnightVolume1[1];
    overnightVolume3 = overnightVolume2[1];
    overnightVolume4 = overnightVolume3[1];
    overnightVolume5 = overnightVolume4[1];
} else {
    overnightVolume1 = overnightVolume1[1];
    overnightVolume2 = overnightVolume2[1];
    overnightVolume3 = overnightVolume3[1];
    overnightVolume4 = overnightVolume4[1];
    overnightVolume5 = overnightVolume5[1];
}

plot CumulativeOvernightVolume = if isNightSessionFromMidnight then cOvernightVolume else Double.NaN;
plot AverageOvernightVolume = if count > 5 then (overnightVolume1 + overnightVolume2 + overnightVolume3 + overnightVolume4 + overnightVolume5) / 5 else Double.NaN;

CumulativeOvernightVolume.DefineColor("Below", GetColor(1));
CumulativeOvernightVolume.DefineColor("Above", GetColor(0));
CumulativeOvernightVolume.AssignValueColor(if CumulativeOvernightVolume > AverageOvernightVolume then CumulativeOvernightVolume.Color("Above") else CumulativeOvernightVolume.Color("Below"));
CumulativeOvernightVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
AverageOvernightVolume.SetDefaultColor(GetColor(5));
AverageOvernightVolume.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

DefineGlobalColor("Night Session #1", Color.WHITE);
DefineGlobalColor("First Hour Trading", Color.RED);
DefineGlobalColor("Main Session", Color.BLUE);
DefineGlobalColor("Night Session #2", Color.GRAY);
AssignPriceColor(if paintBars then if isNightSessionFromMidnight then GlobalColor("Night Session #1") else if isFirstHourTrading then GlobalColor("First Hour Trading") else if isMainSession then GlobalColor("Main Session") else GlobalColor("Night Session #2") else Color.CURRENT);


#------------------------------------

# Add a Label to show the ratio of Average-to-Cumulative Volume
#  the Label color to change from (some dull color) to GREEN,
#   when the Cumulative overnight volume is more than X times (an input) the Average Volume

def avg = if isNightSessionFromMidnight then AverageOvernightVolume else avg[1];
def cum = if isNightSessionFromMidnight then  CumulativeOvernightVolume else cum[1];

#def vratio_ac = AverageOvernightVolume / CumulativeOvernightVolume;
#def vratio_ca = CumulativeOvernightVolume / AverageOvernightVolume;
def vratio_ac = avg/cum;
def vratio_ca = cum/avg;

input factor = 5;
def ca_isbig = cum > (avg * factor);

addlabel(1, " ", color.black);
addlabel(1, "avg/cum " + vratio_ac , color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "cum/avg " + vratio_ca , (if ca_isbig then color.green else color.gray));
addlabel(1, " ", color.black);


addchartbubble(0,0,
 AverageOvernightVolume + " a\n" +
 CumulativeOvernightVolume + " c"
, color.yellow, yes);

#
 

Attachments

  • img1.JPG
    img1.JPG
    105.9 KB · Views: 35
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
256 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