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

mhtrader

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:
Solution

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

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.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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