Abnormal Number Of Trades Intraday For ThinkOrSwim

justAnotherTrader

Active member
VIP
VIP Enthusiast
Just a simple momentum scanner designed to pick up on unusual number of trades inspired by equityfeed. This scanner will scan on the desired time frame for stocks that are 3*the average number of trades in the current bar i.e. 1min etc. I hope you guys like it, I havent found a similar one on this site, so let me know if its a dup.

Code:
declare lower;

def AbnormalTradeMultiplier = 3;
def AvgTradeCountLength = 50;

def TradeCount = tick_count;
def AvgTradeCount = Average(TradeCount, AvgTradeCountLength);
def AbnormalNumberOfTrades = AbnormalTradeMultiplier*AvgTradeCount;
def scan = TradeCount > AbnormalNumberOfTrades;

plot s =scan;

This picture shows where the scan would have picked up NCLH indicated by the oval on the lower indicator and the red arrow on the main chart.

cmPOGz3.png
 
Last edited:
@Newton I use it as a scanner, but I adjust everything from the thinkscript editor. So far the way I have gotten the most utility out of it is to set the AvgTradeCount > 100 and set time frame to 5 minutes to get me the most liquid stocks with abnormal trade activity.

A real life example: Yesterday the scanner picked up on AMD at $60 around market open. The stock continued to run all day into after market reaching a peak of somewhere around 62.50

Im still playing with the settings but I believe there is a lot of potential using it in conjunction with another study. If for no other reason than to identify a universe of stocks that are super liquid to get in and out of quickly.

My settings with the 5 minute time frame:
Code:
declare lower;

def AbnormalTradeMultiplier = 3;
def AvgTradeCountLength = 50;

def TradeCount = tick_count;
def AvgTradeCount = Average(TradeCount, AvgTradeCountLength);
def AbnormalNumberOfTrades = AbnormalTradeMultiplier*AvgTradeCount;
def scan = TradeCount > AbnormalNumberOfTrades;


plot s =scan and AvgTradeCount > 100;
 
Last edited:
Very limited indicator, but it does exactly what its programmed it to do. I like intraday, not so much swingtrade or buy and hold, so I shortened the "def AvgTradeCountLength" to '13', to give it room to look back and still be ahead of any major movement. Works very well! I can get into a bullish run and, along with other indicators, it always provides the first indication of any major move in PPS in the bullish direction. lots of possibilities, maybe someone can code up a center-zero-line, and a distinction of a bearish signal too. Nice work J.A.Trader!

Lower indicator - - - - - -averagetradecountlength = 5, plot > 87

Lower lower indicator - -averagetradecountlength = 17, plot > 25
 
Last edited by a moderator:
Just a simple momentum scanner designed to pick up on unusual number of trades inspired by equityfeed. This scanner will scan on the desired time frame for stocks that are 3*the average number of trades in the current bar i.e. 1min etc. I hope you guys like it, I havent found a similar one on this site, so let me know if its a dup.

Code:
declare lower;

def AbnormalTradeMultiplier = 3;
def AvgTradeCountLength = 50;

def TradeCount = tick_count;
def AvgTradeCount = Average(TradeCount, AvgTradeCountLength);
def AbnormalNumberOfTrades = AbnormalTradeMultiplier*AvgTradeCount;
def scan = TradeCount > AbnormalNumberOfTrades;

plot s =scan;

This picture shows where the scan would have picked up NCLH indicated by the oval on the lower indicator and the red arrow on the main chart.

View attachment 7488
nice
 
If I am understanding correctly this only works in the TOS scanner. Is there any way it could be scripted to work as a Study?
 
If I am understanding correctly this only works in the TOS scanner. Is there any way it could be scripted to work as a Study?
This is the code found from thinkorswim's learning center found here https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Fundamentals/tick-count :

Code:
declare lower;

declare zerobase;

plot TradeCount = tick_count;

plot AvgTradeCount = Average(TradeCount, 50);

TradeCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

TradeCount.AssignValueColor(if TradeCount >= AvgTradeCount then Color.UPTICK else Color.DOWNTICK);
 
Nicely done @justAnotherTrader...I've taken the liberty of extending the color palette associated with TradeCount histogram...Hope this helps :cool:

Code:
declare lower;
declare zerobase;

input AbnormalTradeMultiplier = 3;
input AvgTradeCountLength = 21; #50;

plot TradeCount = tick_count;
plot AvgTradeCount = Round(Average(TradeCount, AvgTradeCountLength), 0);

#def AbnormalTradeLevel = AvgTradeCount * AbnormalTradeMultiplier;
plot AbnormalTradeLevel = AvgTradeCount * AbnormalTradeMultiplier;

TradeCount.SetLineWeight(3);
TradeCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TradeCount.AssignValueColor(
if TradeCount >= AbnormalTradeLevel and close > open then Color.GREEN
else if TradeCount >= AbnormalTradeLevel and open > close then Color.RED  
else if TradeCount >= AvgTradeCount and open < close then Color.DARK_GREEN
else if TradeCount >= AvgTradeCount and open > close then Color.DARK_RED
else if TradeCount < AvgTradeCount and close < open then Color.GRAY
else if TradeCount < AvgTradeCount and close > open then Color.LIGHT_GRAY
else Color.ORANGE);

AvgTradeCount.SetDefaultColor(Color.YELLOW);
AvgTradeCount.SetLineWeight(2);
AvgTradeCount.HideTitle();

AbnormalTradeLevel.SetDefaultColor(Color.LIGHT_GRAY);
AbnormalTradeLevel.SetLineWeight(2);
AbnormalTradeLevel.HideTitle();
AbnormalTradeLevel.Hide();
 

Attachments

  • 202307171447_Abnormal_Histogram_.jpg
    202307171447_Abnormal_Histogram_.jpg
    23.6 KB · Views: 164
Last edited:
Nicely done @justAnotherTrader...I've taken the liberty of extending the color palette associated with TradeCount histogram...Hope this helps :cool:

Code:
declare lower;
declare zerobase;

input AbnormalTradeMultiplier = 3;
input AvgTradeCountLength = 21; #50;

plot TradeCount = tick_count;
plot AvgTradeCount = Round(Average(TradeCount, AvgTradeCountLength), 0);

#def AbnormalTradeLevel = AvgTradeCount * AbnormalTradeMultiplier;
plot AbnormalTradeLevel = AvgTradeCount * AbnormalTradeMultiplier;

TradeCount.SetLineWeight(3);
TradeCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TradeCount.AssignValueColor(
if TradeCount >= AbnormalTradeLevel and close > open then Color.GREEN
else if TradeCount >= AbnormalTradeLevel and open > close then Color.RED
else if TradeCount >= AvgTradeCount and open < close then Color.DARK_GREEN
else if TradeCount >= AvgTradeCount and open > close then Color.DARK_RED
else if TradeCount < AvgTradeCount and close < open then Color.GRAY
else if TradeCount < AvgTradeCount and close > open then Color.LIGHT_GRAY
else Color.ORANGE);

AvgTradeCount.SetDefaultColor(Color.YELLOW);
AvgTradeCount.SetLineWeight(2);
AvgTradeCount.HideTitle();

AbnormalTradeLevel.SetDefaultColor(Color.LIGHT_GRAY);
AbnormalTradeLevel.SetLineWeight(2);
AbnormalTradeLevel.HideTitle();
AbnormalTradeLevel.Hide();

Thanks to all who contributed, this is great. I made an additional improvement using the code from @Joshua in this post to exclude extended hours from the average calculation. Makes it much more useful for higher periods such as 30 minutes (recommend having the chart set to at least 15 days, and, it only works on intraday charts, not daily):

Code:
# Original script by justAnotherTrader, expanded color palette by netarchitech, improved to exclude extended hours from trade count average by lmk99 using code from Joshua ; thead at https://usethinkscript.com/threads/abnormal-number-of-trades-intraday-for-thinkorswim.3171/#post-128465

declare lower;
declare zerobase;

plot TradeCount = tick_count;
input Length = 21;
def isOpen =
    between(
        GetTime(),
        RegularTradingStart(GetYYYYMMDD()),
        RegularTradingEnd(GetYYYYMMDD())
    )
;
def NoExIndex =
    if isOpen then
        AbsValue(
            Fold i = 0 to Max(0,BarNumber())
            with d = 0 while d >= 0 do
            if d == Length then -i
            else if GetValue(isOpen,i) then d + 1
            else d
        )
    else 0  
;
def NoExMa =
    if isOpen then
        (
            Fold Index = 0 to NoExIndex with Data do
            if GetValue(isOpen,index)
            then Data + GetValue(TradeCount,index)
            else Data
        )
    else Double.NaN
;
def Len =
    (NoExMa - floor(NoExMa)) * 1000
;
def Tot =
    Floor(NoExMa) * 0.01  
;
def AvgTradeCount_pre = NoExMa / Length;
#NoExtHourMA.setpaintingStrategy(paintingStrategy.Line_Vs_POINTS);
#NoExtHourMA.setdefaultColor(color.white);
#Plot WithExHours = Average(close,Length);
#WithExHours.setdefaultColor(color.white);
#NoExtHourMA.assignValueColor(if NoExtHourMA == WithExHours then color.cyan else color.yellow);

input AbnormalTradeMultiplier = 3;
input AvgTradeCountLength = 21; #50;


plot AvgTradeCount = Round(AvgTradeCount_pre, 0);

#def AbnormalTradeLevel = AvgTradeCount * AbnormalTradeMultiplier;
plot AbnormalTradeLevel = AvgTradeCount * AbnormalTradeMultiplier;

TradeCount.SetLineWeight(3);
TradeCount.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TradeCount.AssignValueColor(
if TradeCount >= AbnormalTradeLevel and close > open then Color.GREEN
else if TradeCount >= AbnormalTradeLevel and open > close then Color.RED
else if TradeCount >= AvgTradeCount and open < close then Color.DARK_GREEN
else if TradeCount >= AvgTradeCount and open > close then Color.DARK_RED
else if TradeCount < AvgTradeCount and close < open then Color.GRAY
else if TradeCount < AvgTradeCount and close > open then Color.LIGHT_GRAY
else Color.ORANGE);

AvgTradeCount.SetDefaultColor(Color.YELLOW);
AvgTradeCount.SetLineWeight(2);
AvgTradeCount.HideTitle();

AbnormalTradeLevel.SetDefaultColor(Color.LIGHT_GRAY);
AbnormalTradeLevel.SetLineWeight(2);
AbnormalTradeLevel.HideTitle();
AbnormalTradeLevel.Hide();
 
Last edited:

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