# Incrementing volume periodically to filter out less liquid stocks as the day passes

##### New member
Hi All,

Can anyone of you please help me with the below script.
The purpose of this script to fetch only those stocks at respective period of time which meets the volume condition of that period for eg. between 9:45 am to 10:59 am EST I only want those stocks who volume is greater than equal to 1.5M, between 11 am to 12 noon I only want those stocks whose volume is greater than equal to 2.5M and so on.
The problem I am facing with this script is that it always takes the highest volume condition i.e. in the below script it skips all stocks with volume 1.5M or 2.5M and only takes into consideration the highest which is 3.5M and above for all the time periods defined, that means I miss all the stocks of 1.5M volume between 9:45 am to 10:59 am EST and only get notified for stocks greater than 3.5M.

Please let me know in case there is any difficulty in understanding, I can try to explain again. Thanks for all the help and inputs.

Rich (BB code):
``````# ************************ INCREMENTING VOLUME PERIODICALLY ********************************* #

input alertPeriodStart1 = 0945; # Alert Start
input alertPeriodEnd1 = 1059;

input alertPeriodStart2 = 1100;
input alertPeriodEnd2 = 1159;

input alertPeriodStart3 = 1200;
input alertPeriodEnd3 = 1235; # Alert End

def startCounter1 =  SecondsFromTime(alertPeriodStart1);
def endCounter1 = SecondsTillTime(alertPeriodEnd1);

def startCounter2 =  SecondsFromTime(alertPeriodStart2);
def endCounter2 = SecondsTillTime(alertPeriodEnd2);

def startCounter3 =  SecondsFromTime(alertPeriodStart3);
def endCounter3 = SecondsTillTime(alertPeriodEnd3);

def alertPeriod1 = if startCounter1 >= 0 and endCounter1 >= 0 then 1 else 0;
def alertPeriod2 = if startCounter2 >= 0 and endCounter2 >= 0 then 1 else 0;
def alertPeriod3 = if startCounter3 >= 0 and endCounter3 >= 0 then 1 else 0;

def volCondition1 = if volume("period" = AggregationPeriod.DAY) >= 1500000 then 1 else 0;
def volCondition2 = if volume("period" = AggregationPeriod.DAY) >= 2500000 then 1 else 0;
def volCondition3 = if volume("period" = AggregationPeriod.DAY) >= 3500000 then 1 else 0;

plot scan = if (alertPeriod1 and volCondition1 and !alertPeriod2 and !alertPeriod3) then 1
else if (alertPeriod2 and volCondition2 and !alertPeriod3) then 1
else if (alertPeriod3 and volCondition3) then 1 else 0;``````

Solution
Hi All,

Can anyone of you please help me with the below script.
The purpose of this script to fetch only those stocks at respective period of time which meets the volume condition of that period for eg. between 9:45 am to 10:59 am EST I only want those stocks who volume is greater than equal to 1.5M, between 11 am to 12 noon I only want those stocks whose volume is greater than equal to 2.5M and so on.
The problem I am facing with this script is that it always takes the highest volume condition i.e. in the below script it skips all stocks with volume 1.5M or 2.5M and only takes into consideration the highest which is 3.5M and above for all the time periods defined, that means I miss all the stocks of 1.5M volume between 9:45 am to...
Hi All,

Can anyone of you please help me with the below script.
The purpose of this script to fetch only those stocks at respective period of time which meets the volume condition of that period for eg. between 9:45 am to 10:59 am EST I only want those stocks who volume is greater than equal to 1.5M, between 11 am to 12 noon I only want those stocks whose volume is greater than equal to 2.5M and so on.
The problem I am facing with this script is that it always takes the highest volume condition i.e. in the below script it skips all stocks with volume 1.5M or 2.5M and only takes into consideration the highest which is 3.5M and above for all the time periods defined, that means I miss all the stocks of 1.5M volume between 9:45 am to 10:59 am EST and only get notified for stocks greater than 3.5M.

Please let me know in case there is any difficulty in understanding, I can try to explain again. Thanks for all the help and inputs.

Rich (BB code):
``````# ************************ INCREMENTING VOLUME PERIODICALLY ********************************* #

input alertPeriodStart1 = 0945; # Alert Start
input alertPeriodEnd1 = 1059;

input alertPeriodStart2 = 1100;
input alertPeriodEnd2 = 1159;

input alertPeriodStart3 = 1200;
input alertPeriodEnd3 = 1235; # Alert End

def startCounter1 =  SecondsFromTime(alertPeriodStart1);
def endCounter1 = SecondsTillTime(alertPeriodEnd1);

def startCounter2 =  SecondsFromTime(alertPeriodStart2);
def endCounter2 = SecondsTillTime(alertPeriodEnd2);

def startCounter3 =  SecondsFromTime(alertPeriodStart3);
def endCounter3 = SecondsTillTime(alertPeriodEnd3);

def alertPeriod1 = if startCounter1 >= 0 and endCounter1 >= 0 then 1 else 0;
def alertPeriod2 = if startCounter2 >= 0 and endCounter2 >= 0 then 1 else 0;
def alertPeriod3 = if startCounter3 >= 0 and endCounter3 >= 0 then 1 else 0;

def volCondition1 = if volume("period" = AggregationPeriod.DAY) >= 1500000 then 1 else 0;
def volCondition2 = if volume("period" = AggregationPeriod.DAY) >= 2500000 then 1 else 0;
def volCondition3 = if volume("period" = AggregationPeriod.DAY) >= 3500000 then 1 else 0;

plot scan = if (alertPeriod1 and volCondition1 and !alertPeriod2 and !alertPeriod3) then 1
else if (alertPeriod2 and volCondition2 and !alertPeriod3) then 1
else if (alertPeriod3 and volCondition3) then 1 else 0;``````
As the scanner does not allow secondary aggregations, I assume you were using "D" (DAY) as your scan setting. That would not recognize intraday periods and possibly be the reason you results were not what you expected. You need to set the scanner to 1min.

I have revised your well done script, and worked around the above limitation by computing the developing volume from the start of the day rather than the "period=aggregationperiod.DAY one. It seems to be working. However, the period end limitation has been surpassed so you may have to wait till tomorrow to adequately test the scan code.

Ruby:
``````input alertPeriodStart1 = 0945; # Alert Start
input alertPeriodEnd1 = 1059;

input alertPeriodStart2 = 1100;
input alertPeriodEnd2 = 1159;

input alertPeriodStart3 = 1200;
input alertPeriodEnd3 = 1235; # Alert End

def startCounter1 =  SecondsFromTime(alertPeriodStart1);
def endCounter1 = SecondsTillTime(alertPeriodEnd1);

def startCounter2 =  SecondsFromTime(alertPeriodStart2);
def endCounter2 = SecondsTillTime(alertPeriodEnd2);

def startCounter3 =  SecondsFromTime(alertPeriodStart3);
def endCounter3 = SecondsTillTime(alertPeriodEnd3);

def alertPeriod1 = if startCounter1 >= 0 and endCounter1 >= 0 then 1 else 0;
def alertPeriod2 = if startCounter2 >= 0 and endCounter2 >= 0 then 1 else 0;
def alertPeriod3 = if startCounter3 >= 0 and endCounter3 >= 0 then 1 else 0;

def  v = if GetDay() != GetDay()[1]
then volume
else if SecondsFromTime(0400) >= 0
then v[1] + volume
else v[1];

def volCondition1 = if v >= 1500000 then 1 else 0;
def volCondition2 = if v >= 2500000 then 1 else 0;
def volCondition3 = if v >= 3500000 then 1 else 0;

plot scan = if (alertPeriod1 and volCondition1 and !alertPeriod2 and !alertPeriod3)
then 1
else if (alertPeriod2 and volCondition2 and !alertPeriod3)
then 1
else if (alertPeriod3 and volCondition3)
then 1 else 0;``````

Last edited:
As the scanner does not allow secondary aggregations, I assume you were using "D" (DAY) as your scan setting. That would not recognize intraday periods and possibly be the reason you results were not what you expected. You need to set the scanner to 1min.

I have revised your well done script, and worked around the above limitation by computing the developing volume from the start of the day rather than the "period=aggregationperiod.DAY one. It seems to be working. However, the period end limitation has been surpassed so you may have to wait till tomorrow to adequately test the scan code.
Thanks so much @SleepyZ , you rightly got hold of the root cause. I tested it a while back and seems working as expected. Thanks once again.

### Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
366 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• 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?