Premarket Volume Pressure indicator

naquan24

Member
I'm trying to calculate the Buying and selling volume in the premarket only from 4am to 9:25am. I have the below indicator that I'm using with the labels included but the issue with the script is, it doesn't stop calculating at 9:25am. It continues to show me buying and selling volume after 9:25am. Can you tell me where I went wrong in my script or can you provide me a corrected script?

declare lower;
declare Hide_On_Daily;


#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];



def O = open;
def h = high;
def l = low;
def c = close;

def V = volume;
def volsum = if bars == 1 then volume
else if SecondsTillTime(till) >= 0
then volsum[1] + volume
else Double.NaN;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);

def Avgbuy = round((buying[1] + buying[2] + buying[3]) / 3 / 1000, 0);
def AvgSell = round((selling[1] + selling[2] + selling[3]) / 3 / 1000, 0);
def Todayhigh = high(period = "Day");
def TodayLow = Low(period = "Day");
def TodaySelling = todayvol * (todayhigh-C)/(todayhigh - todaylow);
def TodayBuying = todayvol *(C - todaylow)/(Todayhigh - todaylow);

# Labels

input showlabel = yes;

DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;

AddLabel(Show_Labels, "Pre-M Buy Vol = " + Round(Buying / 1000, 0) + "K",
if buying/1000 > avgbuy and buying > selling then color.green else color.white);

AddLabel(Show_Labels, "Pre-M Sell Vol = " + Round(Selling / 1000, 0) + "K",
if selling/1000 > avgsell and Selling > Buying then color.red else color.white);

AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) , Color.white);

AddLabel(yes, "Pre-M Buys" + " " + round(todaybuying , 0) + " " ,if todaybuying * .5 > todayselling then color.green else color.white);
AddLabel(yes, "Pre-M Sells" + " " + round(todayselling , 0) + " " , if todayselling * .5 > todaybuying then color.red else color.white);
 
Solution
I added some plots to your lower to see what was going on and then added this code:
Code:
def pre_market_only_buy = if secondsTillTime(till) > 0 then todaybuying else pre_market_only_buy[1];

def pre_market_only_sell = if secondsTillTime(till) > 0 then todayselling else pre_market_only_sell[1];

plot pm_buy = Round(pre_market_only_buy / 1000, 0);
plot pm_sell = Round(pre_market_only_sell / 1000, 0);
EDIT
I noted that the chart quit after 6:25... perhaps changing the > above to >= will fix that.

All I did is define an additional series which, if the time is between your start and 9:30 uses it, otherwise uses the last value of the plot.
it is shown in the bottom most lower on this screen grab:

5shkF3A.png


-mashume
I added some plots to your lower to see what was going on and then added this code:
Code:
def pre_market_only_buy = if secondsTillTime(till) > 0 then todaybuying else pre_market_only_buy[1];

def pre_market_only_sell = if secondsTillTime(till) > 0 then todayselling else pre_market_only_sell[1];

plot pm_buy = Round(pre_market_only_buy / 1000, 0);
plot pm_sell = Round(pre_market_only_sell / 1000, 0);
EDIT
I noted that the chart quit after 6:25... perhaps changing the > above to >= will fix that.

All I did is define an additional series which, if the time is between your start and 9:30 uses it, otherwise uses the last value of the plot.
it is shown in the bottom most lower on this screen grab:

5shkF3A.png


-mashume
 
Last edited:
Solution
Mashume ...thanks for getting back to me. Question...do I create a new script with the info you provided or do I simply add your code to the bottom of mines. If so, should I enter the below script?

declare lower;
declare Hide_On_Daily;


#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];



def O = open;
def h = high;
def l = low;
def c = close;

def V = volume;
def volsum = if bars == 1 then volume
else if SecondsTillTime(till) >= 0
then volsum[1] + volume
else Double.NaN;
def buying = V*(C-L)/(H-L);
def selling = V*(H-C)/(H-L);

def Avgbuy = round((buying[1] + buying[2] + buying[3]) / 3 / 1000, 0);
def AvgSell = round((selling[1] + selling[2] + selling[3]) / 3 / 1000, 0);
def Todayhigh = high(period = "Day");
def TodayLow = Low(period = "Day");
def TodaySelling = todayvol * (todayhigh-C)/(todayhigh - todaylow);
def TodayBuying = todayvol *(C - todaylow)/(Todayhigh - todaylow);

def pre_market_only_buy = if secondsTillTime(till) > 0 then todaybuying else pre_market_only_buy[1];

def pre_market_only_sell = if secondsTillTime(till) > 0 then todayselling else pre_market_only_sell[1];

plot pm_buy = Round(pre_market_only_buy / 1000, 0);
plot pm_sell = Round(pre_market_only_sell / 1000, 0);

# Labels

input showlabel = yes;

DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;

AddLabel(Show_Labels, "Pre-M Buy Vol = " + Round(Buying / 1000, 0) + "K",
if buying/1000 > avgbuy and buying > selling then color.green else color.white);

AddLabel(Show_Labels, "Pre-M Sell Vol = " + Round(Selling / 1000, 0) + "K",
if selling/1000 > avgsell and Selling > Buying then color.red else color.white);

AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) , Color.white);

AddLabel(yes, "Pre-M Buys" + " " + round(todaybuying , 0) + " " ,if todaybuying * .5 > todayselling then color.green else color.white);
AddLabel(yes, "Pre-M Sells" + " " + round(todayselling , 0) + " " , if todayselling * .5 > todaybuying then color.red else color.white);
 
I think I just added it at the end, but if you want to use the values in your labels, you'll need to add it above the AddLabel() calls.

-mashume
 
Mashume, the todaybuying formula (below) is based on the period = "Day".....is there a way to change to change the period time to be between 0400 and 0925?

def Todayhigh = high(period = "Day");
def TodayLow = Low(period = "Day");
 
Mashume, the todaybuying formula (below) is based on the period = "Day".....is there a way to change to change the period time to be between 0400 and 0925?

def Todayhigh = high(period = "Day");
def TodayLow = Low(period = "Day");
If your referencing period = Day, you can only access that aggregation as a whole. You cannot specify a time within that aggregation in the same way that you cannot reference the first 5 minutes of a candle if you are looking at a 15 minute chart. For your purposes, your maximum (largest) time frame that can accommodate 9:25 am would be 5 minutes. (since 15 would be 9:15 and then 9:30 and 10 minutes would give 9:20 and then 9:30).

-mashume
 
Ok.

First off, I'll start by saying I do not like code like this:
Code:
def premarket = secondsFromTime(premarketopen)>=0 and secondsTillTime(premarketclose)>0;

While it works, it is not explicit. Explicit code is always preferred over implicit code. This is how it should be done, for clarity:
Code:
def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;
The first works, but it is lazy and it is hard to remember what it is set to when true.

Now, with that set in a way that we can use it we can define some things (and make it work for tick charts too):
Code:
declare upper;
input premarketOpen = 0400;
input premarketClose = 0925;

def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;

def premarket_low = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then low
else if premarket == 1 and low < premarket_low[1] then low
else if premarket == 0 then premarket_low[1]
else premarket_low[1];

plot pre_market_low = premarket_low;

def premarket_high = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then high
else if premarket == 1 and high > premarket_high[1] then high
else if premarket == 0 then premarket_high[1]
else premarket_high[1];

plot pre_market_high = premarket_high;
 
Ok.

First off, I'll start by saying I do not like code like this:
Code:
def premarket = secondsFromTime(premarketopen)>=0 and secondsTillTime(premarketclose)>0;

While it works, it is not explicit. Explicit code is always preferred over implicit code. This is how it should be done, for clarity:
Code:
def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;
The first works, but it is lazy and it is hard to remember what it is set to when true.

Now, with that set in a way that we can use it we can define some things (and make it work for tick charts too):
Code:
declare upper;
input premarketOpen = 0400;
input premarketClose = 0925;

def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;

def premarket_low = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then low
else if premarket == 1 and low < premarket_low[1] then low
else if premarket == 0 then premarket_low[1]
else premarket_low[1];

plot pre_market_low = premarket_low;

def premarket_high = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then high
else if premarket == 1 and high > premarket_high[1] then high
else if premarket == 0 then premarket_high[1]
else premarket_high[1];

plot pre_market_high = premarket_high;
 
That makes sense.....can I ask one last question...is there a way to define the close price the same way you did the Premarket low and premarket high?
The reason why I'm aksing is because after 9:30, the volume (buying/Selling) information gets changed based on the close price that is occurring during live trading. As you know already, to calculate the volume of buying, part of the formula is close-Low, so when I look at the amount of buying volume, it changes after 9:30 because the script is referring to the current close price during normal day and not the premarket close.
The good news is using your script, the premarket low and premarket high doesnt change after 9:30....
So that's why I was wondering is there a way to def pre-market_close?
 
put the definitions I wrote far enough up in your script that you can use their values in your labels and they won't change any more. 🙃

-mashume

or just move the labels to the end, but remember to use the new values I wrote up in the label calls.
 
Below is the entire script. As you indicated, I moved the labels to the end.....and replaced the explicit codes with the codes you sent over. The labels still show an incorrect Buy and sell volume and the Pre-M close price shows the price as of day at 4pm instead of the premarket close.
You can see the buying and selling formula is using the close price to determine the value. And on this ticker (Beke)...the premarket close at 9:25 was 19.06 while the label is showing that the script is using the close price at the end of normal trading at 4pm which was $19.67. Can you tell me I put something in the script in the wrong place?

#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];


input premarketOpen = 0400;
input premarketClose = 0925;

def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;

def premarket_low = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then low
else if premarket == 1 and low < premarket_low[1] then low
else if premarket == 0 then premarket_low[1]
else premarket_low[1];

plot pre_market_low = premarket_low;

def premarket_high = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then high
else if premarket == 1 and high > premarket_high[1] then high
else if premarket == 0 then premarket_high[1]
else premarket_high[1];



def TodaySelling = todayvol * (premarket_high-close)/(premarket_high - premarket_low);
def TodayBuying = todayvol *(Close - premarket_low)/(premarket_high - premarket_low);

# Labels

input showlabel = yes;

DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;

AddLabel(Show_Labels, "Pre-M Buy Vol = " + Round(TodayBuying/ 1000, 0) + "K", if todaybuying > todayselling then color.green else color.white);


AddLabel(Show_Labels, "Pre-M Sell Vol = " + Round(todaySelling / 1000, 0) + "K",
if todaybuying < todayselling then color.red else color.white);


AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) , Color.white);

AddLabel(showlabel," Pre-M Close Price : " + close , Color.white);
 
I'm confused as to what you're after a bit...

This bit of code:
Code:
def TodaySelling = todayvol * (premarket_high - close) / (premarket_high - premarket_low);
def TodayBuying = todayvol *(Close - premarket_low) / (premarket_high - premarket_low);
references "close" which will always be (unless you unwisely choose to define close as something else) be the close of the current bar.

Storing the pre-market close price is not in your script, nor was it in the original request I thought... it can be done this way:
Code:
def pre_market_close = if premarket == 0 and premarket[1] == 1 then close[1] else pre_market_close[1];

And then your script looks like this:
Code:
#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];


input premarketOpen = 0400;
input premarketClose = 0925;

def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;

def premarket_low = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then low
else if premarket == 1 and low < premarket_low[1] then low
else if premarket == 0 then premarket_low[1]
else premarket_low[1];

plot pre_market_low = premarket_low;

def premarket_high = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then high
else if premarket == 1 and high > premarket_high[1] then high
else if premarket == 0 then premarket_high[1]
else premarket_high[1];

def pre_market_close = if premarket == 0 and premarket[1] == 1 then close[1] else pre_market_close[1];

plot TodaySelling = todayvol * (premarket_high - pre_market_close) / (premarket_high - premarket_low);
plot TodayBuying = todayvol *(pre_market_close - premarket_low)/(premarket_high - premarket_low);

# Labels

input showlabel = yes;

DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;

AddLabel(Show_Labels, "  Pre-M Buy Vol = " + Round(TodayBuying/ 1000, 0) + "K  ", if todaybuying > todayselling then color.green else color.gray);


AddLabel(Show_Labels, "  Pre-M Sell Vol = " + Round(todaySelling / 1000, 0) + "K  ",
if todaybuying < todayselling then color.red else color.gray);


AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) + "  " , color.gray);

AddLabel(showlabel," Pre-M Close Price : " + pre_market_close , color.gray);

-mashume
 
Hey Mashume, I wanted to thank you...I applied the script today and it worked great! Can I ask a question regarding volume average?
Currently I'm using the below script to calculate the volume average for the market open. It uses the last 20 bars to determine the average. The problem is since the premarket doesn't typically have a large volume, the volume average indicator is off. Is there a way to exclude volume listed in the premarket and only the previous 20 bars from normal trading day?
Ex: At 9:30am on a 5 min chart, it would calculate the Vol avg from the previous days bars from 2:20pm till 4pm since thats 20 bars back. Then at 9:35, it would plot the avg using previous day bars from 2:25 till 9:30 the current day. At 9:40, it would plot the avg using previous day 2:30 till 9:45 the current day.
Simply put, the formula below works when I don't have the premarket screen open.....so is there a way to exclude the premarket info even whenthe screen is open?

declare lower;
declare Hide_On_Daily;


#Inputs
input begin = 0930;
input till = 1600;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];

def V = volume;
def volsum = if bars == 1 then volume
else if SecondsTillTime(till) >= 0
then volsum[1] + volume
else Double.NaN;

input length = 20;
plot VolAvg = average(volume, length);
VolAvg.SetDefaultColor(color.yellow);
 
Hey Mashume, I wanted to thank you...I applied the script today and it worked great! Can I ask a question regarding volume average?
Currently I'm using the below script to calculate the volume average for the market open. It uses the last 20 bars to determine the average. The problem is since the premarket doesn't typically have a large volume, the volume average indicator is off. Is there a way to exclude volume listed in the premarket and only the previous 20 bars from normal trading day?
Ex: At 9:30am on a 5 min chart, it would calculate the Vol avg from the previous days bars from 2:20pm till 4pm since thats 20 bars back. Then at 9:35, it would plot the avg using previous day bars from 2:25 till 9:30 the current day. At 9:40, it would plot the avg using previous day 2:30 till 9:45 the current day.
Simply put, the formula below works when I don't have the premarket screen open.....so is there a way to exclude the premarket info even whenthe screen is open?

declare lower;
declare Hide_On_Daily;


#Inputs
input begin = 0930;
input till = 1600;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];

def V = volume;
def volsum = if bars == 1 then volume
else if SecondsTillTime(till) >= 0
then volsum[1] + volume
else Double.NaN;

input length = 20;
plot VolAvg = average(volume, length);
VolAvg.SetDefaultColor(color.yellow);

take a look at the study that joshua created, to calculate an average, while skipping over a time period
https://usethinkscript.com/threads/moving-average-excludes-extended-hours.14061/
 
Good afternoon Halcyonguy, unfortunately this didn't work but I think I may have an idea why. I see that its using a length of 20 but I didnt see something that says it calcuating volume of a length of 20. Can you tell me what the script is using to calculate?
is there a way I can edit the script to get it use the volume over a length of 20 to calculate the volume average?

Good afternoon.....the script that was sent over (shown below) didn't work because its not calculating that last 20 bars to determine the volume average. Can you tell me what the script is using to calculate or if there is a way to edit so it uses the last 20 bars (excluding the premarket) to calculate the volume average?
https://usethinkscript.com/threads/moving-average-excludes-extended-hours.14061/

Good afternoon.....can I ask your assistance in reading a script that I'm using? Below is a script that is used to tell me the Low of the premarket for the current trading day. The problem is it sometimes gives me the Low for the previous trading day....and I don't understand why. Can you tell me what its saying and how I can edit it to only show the Low for the current day?

input premarketOpen = 0400;
input premarketClose = 0925;

def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;

def premarket_low = if secondsFromTime(premarketOpen) <= 0 and secondsFromTime(premarketOpen)[1] > 0 then low else if premarket == 1 and low < premarket_low[1] then low
else if premarket == 0 then premarket_low[1]
else premarket_low[1];

I'm confused as to what you're after a bit...

This bit of code:
Code:
def TodaySelling = todayvol * (premarket_high - close) / (premarket_high - premarket_low);
def TodayBuying = todayvol *(Close - premarket_low) / (premarket_high - premarket_low);
references "close" which will always be (unless you unwisely choose to define close as something else) be the close of the current bar.

Storing the pre-market close price is not in your script, nor was it in the original request I thought... it can be done this way:
Code:
def pre_market_close = if premarket == 0 and premarket[1] == 1 then close[1] else pre_market_close[1];

And then your script looks like this:
Code:
#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];


input premarketOpen = 0400;
input premarketClose = 0925;

def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;

def premarket_low = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then low
else if premarket == 1 and low < premarket_low[1] then low
else if premarket == 0 then premarket_low[1]
else premarket_low[1];

plot pre_market_low = premarket_low;

def premarket_high = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then high
else if premarket == 1 and high > premarket_high[1] then high
else if premarket == 0 then premarket_high[1]
else premarket_high[1];

def pre_market_close = if premarket == 0 and premarket[1] == 1 then close[1] else pre_market_close[1];

plot TodaySelling = todayvol * (premarket_high - pre_market_close) / (premarket_high - premarket_low);
plot TodayBuying = todayvol *(pre_market_close - premarket_low)/(premarket_high - premarket_low);

# Labels

input showlabel = yes;

DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;

AddLabel(Show_Labels, "  Pre-M Buy Vol = " + Round(TodayBuying/ 1000, 0) + "K  ", if todaybuying > todayselling then color.green else color.gray);


AddLabel(Show_Labels, "  Pre-M Sell Vol = " + Round(todaySelling / 1000, 0) + "K  ",
if todaybuying < todayselling then color.red else color.gray);


AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) + "  " , color.gray);

AddLabel(showlabel," Pre-M Close Price : " + pre_market_close , color.gray);

-mashume

I'm confused as to what you're after a bit...

This bit of code:
Code:
def TodaySelling = todayvol * (premarket_high - close) / (premarket_high - premarket_low);
def TodayBuying = todayvol *(Close - premarket_low) / (premarket_high - premarket_low);
references "close" which will always be (unless you unwisely choose to define close as something else) be the close of the current bar.

Storing the pre-market close price is not in your script, nor was it in the original request I thought... it can be done this way:
Code:
def pre_market_close = if premarket == 0 and premarket[1] == 1 then close[1] else pre_market_close[1];

And then your script looks like this:
Code:
#Inputs
input begin = 0400;
input till = 0925;
def bars = if GetDay() == GetLastDay() and SecondsFromTime(begin) >= 0 and
SecondsTillTime(till) > 0
then bars[1] + 1
else bars[1];
def todayvol = if GetDay() == GetLastDay() and
SecondsFromTime(begin) >= 0 and SecondsTillTime(till) > 0
then todayvol[1] + volume
else todayvol[1];


input premarketOpen = 0400;
input premarketClose = 0925;

def premarket = if secondsFromTime(premarketopen) >= 0 and secondsTillTime(premarketclose) > 0 then 1 else 0;

def premarket_low = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then low
else if premarket == 1 and low < premarket_low[1] then low
else if premarket == 0 then premarket_low[1]
else premarket_low[1];

plot pre_market_low = premarket_low;

def premarket_high = if secondsFromTime(premarketOpen) <= 0 AND secondsFromTime(premarketOpen)[1] > 0 then high
else if premarket == 1 and high > premarket_high[1] then high
else if premarket == 0 then premarket_high[1]
else premarket_high[1];

def pre_market_close = if premarket == 0 and premarket[1] == 1 then close[1] else pre_market_close[1];

plot TodaySelling = todayvol * (premarket_high - pre_market_close) / (premarket_high - premarket_low);
plot TodayBuying = todayvol *(pre_market_close - premarket_low)/(premarket_high - premarket_low);

# Labels

input showlabel = yes;

DefineGlobalColor("LabelGreen", CreateColor(0, 165, 0)) ;
input Show_Labels = yes;

AddLabel(Show_Labels, "  Pre-M Buy Vol = " + Round(TodayBuying/ 1000, 0) + "K  ", if todaybuying > todayselling then color.green else color.gray);


AddLabel(Show_Labels, "  Pre-M Sell Vol = " + Round(todaySelling / 1000, 0) + "K  ",
if todaybuying < todayselling then color.red else color.gray);


AddLabel(showlabel, bars + " bars Pre-M Volume : " + Round(todayvol, 0) + "  " , color.gray);

AddLabel(showlabel," Pre-M Close Price : " + pre_market_close , color.gray);

-mashume
Mashume, I used the script you provided.....its works as it provides the premarket highs and Lows....the issue is that it doesn't provide them for the current trading day. It seems to go back and provides the high and low over the aggregated time interval that you are viewing....so if I have my time frame on a 5 min chart with lookback period of 30 days....it shows the highest high and lowest low over 30 days.

Can you tell me how I can adjust it so that it provides the high and low of the premarket for today only?
 
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
210 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