Volume greater than previous candles

wenzmann

New member
Hello,

I am trying to build a script that would scan and alert me if a stock on one of my watchlists has a volume bar higher than the previous 15 candles on a one minute time frame. I built a script but it doesn't seem to be working correctly. It is still just pulling up all of the stocks on the watchlist regardless of current volume. Any help on where my script went wrong would be greatly appreciated!

#previous candles volume
def Active = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
plot scan = sum(volume > volume[1], 15) >= 1;
 
Still getting all the tickers on the list.


def Active = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
plot scan = Highest(volume> volume[1], 15) >= 1;

also:


def Active = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
plot scan = Highest(volume[1], 15) >= 1;

Cant figure out what the missing criteria or value is.
 

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

Still getting all the tickers on the list.


def Active = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
plot scan = Highest(volume> volume[1], 15) >= 1;

also:


def Active = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
plot scan = Highest(volume[1], 15) >= 1;

Cant figure out what the missing criteria or value is.
One of these 3 might help.

Since the market is closed I did not include your 'active' constraint. Since you mentioned in your first post "current volume", this compares the current bar's volume to the highest volume of the last input (15) bars. Depending on when you run the scan, the developing current bars volume may result in false readings, so you may want to change this.

Ruby:
#previous candles volume

def Active     = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
def lastvolume = if IsNaN(close[-1]) and !IsNaN(close) then volume else Double.NaN;
plot scan      = Highest(volume[1], 15) >= HighestAll(lastvolume);

AddLabel(1, "HVol15 " + Highest(volume[1], 15) + " LastVol " + HighestAll(lastvolume) + "  Scan " + scan, Color.WHITE);

The next two methods just compare the volume of one bar to the prior bar and if volume > volume[1], it counts it and sums it. The first uses a count routine that you can visually see at each bar the result. The second, just uses the sum() function.

Ruby:
def lastbar    = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else lastbar[1];

#Method 1
def volcompare = if BarNumber() >= HighestAll(lastbar - 15) then if volume > volume[1] then  volcompare[1] + 1 else volcompare[1] else 0;

plot xvol      = if BarNumber() < HighestAll(lastbar - 15) then Double.NaN else volcompare;
xvol.SetPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
AddLabel(1, "Count1 " + xvol, Color.ORANGE);

#Method 2
def  svol      = if BarNumber() >= HighestAll(lastbar - 15) then Sum( volume > volume[1], 15) else svol[1];
AddLabel(1, "Count2 " + svol, Color.WHITE);

Finally, a chart with all three displayed

Capture.jpg
 
One of these 3 might help.

Since the market is closed I did not include your 'active' constraint. Since you mentioned in your first post "current volume", this compares the current bar's volume to the highest volume of the last input (15) bars. Depending on when you run the scan, the developing current bars volume may result in false readings, so you may want to change this.



The next two methods just compare the volume of one bar to the prior bar and if volume > volume[1], it counts it and sums it. The first uses a count routine that you can visually see at each bar the result. The second, just uses the sum() function.



Finally, a chart with all three displayed
This is extremely helpful, thank you! What could I change the 15 bar value to in order to avoid false readings?
 
I am not sure what your plan is on how to use the information. If you use the first script, to avoid false readings, you might not want to use the current developing volume but perhaps the volume[1] in the lastvolume code.
 
#previous candles volume
def Active = SecondsFromTime(0900) > 0 and SecondsTillTime(1430) >= 0;
If you are probably looking to compare if the volume of the current bar will end up being higher than previous bars. it's necessary to compare the volume per second of the developing bar vs. volume per second of the previous bar.

In this way, it is possible to anticipate if the current volume bar will end up being greater than the previous volume bar. Said that, I don't know if this's possible using Thinkorswim.
 
I am not sure what your plan is on how to use the information. If you use the first script, to avoid false readings, you might not want to use the current developing volume but perhaps the volume[1] in the lastvolume code.
I just want to see if there is going to be an intraday volume spike or a big move by using this scan to see if the volume is larger than the last consecutive candles.
 
I just want to see if there is going to be an intraday volume spike or a big move by using this scan to see if the volume is larger than the last consecutive candles

Just change the input bars to be the number of previous bars total volume.

Ruby:
input bars = 5;
def pvol   = Sum(volume[1], bars);
#addlabel(1, "V " + volume + " PV " + pvol, if volume > pvol then color.light_green else color.pink);
plot scan  = volume > pvol;
 
Try this pocket pivot code found elsewhere from this website. I didn't write the code. I copied it out of my TOS fro you.

#
# Copyright 2015 Scott J. Johnson (http://scottjjohnson.com)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS-IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#
# PocketPivot
#
# Identifies up-day volume spikes that may be a buyable pocket pivot. Based on the
# work of Gil Morales and Chris Kacher:
#
# http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470616539,miniSiteCd-WILEYTRADING.html
# http://www.wiley.com/WileyCDA/WileyTitle/productCd-1118273028,miniSiteCd-WILEYTRADING.html
# http://www.aaiilosangeles.org/SkirballPresentations/Morales&Kacher091110.pdf
#
# This study checks price and volume to see if they met the pocket pivot
# criteria. The other criteria (strong fundamentals, no wedging, constructive
# basing, etc.) need to be evaluated separately.
#
# I made these additions/modifications to Gil's and Chris's vague and sometimes
# conflicting definition of a pocket pivot:
#
# 1. Per Gil and Chris, the volume on the day of the pocket pivot must be
# higher than any down day in the previous 10 days. But if the volume is
# "choppy", then increase the period to 11 to 15 days. But they don't
# define "choppy". For the purposes of this script, I define choppy when
# the standard deviation of the volume is > 125% of the average. Update: I
# removed the stddev logic since it didn't eliminate any obviously poor
# pivots. I'm always looking at the volume on the previous 10 days.
#
# 2. I only count the pocket pivot if the stock closes in the upper 62% of the
# day's price range. Up days that close lower in the range are considered
# stalling.
#
# 3. Gil and Chris say daily price closes prior to the pivot should be "tight"
# without any specifics. I defined tight as where the average percent price
# change at close over the last 10 days is <= 1.5%. Update: I removed this
# rule after backtesting against Gil's examples.
#
# 4. Gil and Chris have examples of pocket pivots off of the 50-day instead of
# the 10-day. At that point the stock is extended from the 10-day. That
# seems to conflict with the idea that a pocket pivot occurs after a quiet
# period in the stock so I have not implemented rules for 50-day PPs here.
#
# 5. The low on the day of the pivot must be within 1.4% of the 10-day SMA or
# the price must have moved up through the 10-day during that day. Several
# of Gil/Chris's examples conflict. (Example: 1.24 in one example is
# described as too extended, but there are others where 1.6 or even 2.5%
# above the 10-day SMA isn't too extended. In the Trading Cockpit with the
# O'Neil Disciples, Chapter 5.) I'm choosing to use a middle and slightly
# conservative setting here. The more extended, the more risky the buy.
#
# 6. Pocket pivots should not be bought when then stock is below the 50- or
# 200-day simple moving averages. I check only the 50-day here because when
# I checked the 200-day, TOS was hiding the study for recent IPOs with less
# than 200 days of price history.
#
input Period = 11; # normal volume lookback period (today + 10 prior days)
input MaximumDistanceFrom10DaySMAPercent = 1.4; # Price on pivot day should be near the 10-day SMA. MAX = 1.6 Per FOSL1, 1.23 per PII, but RAX not extended at 1.61 and 1.64.

# Volume functions
def DownVolume = If(close < close[1], volume, 0);
def HighestDownVolume = Highest(DownVolume, Period);

def FiftyDayAverageVolume = MovingAverage(AverageType.SIMPLE, volume, 50);

def IsVolumeGreaterHighestDownVolume = if (volume > HighestDownVolume) then 1 else 0;

# Price functions
def TenDaySMA = MovingAverage(AverageType.SIMPLE, close, 10);
def FiftyDaySMA = MovingAverage(AverageType.SIMPLE, close, 50);

def IsLowPriceNear10DaySMA = if ((AbsValue(low - TenDaySMA) / TenDaySMA) <= MaximumDistanceFrom10DaySMAPercent / 100) then 1 else 0;
def DidPricePass10DaySMA = if (low <= TenDaySMA && close >= TenDaySMA) then 1 else 0;

def IsPriceNear10DaySMA = if (IsLowPriceNear10DaySMA or DidPricePass10DaySMA) then 1 else 0;

def IsPriceAtOrAbove50DaySMA = if (close >= FiftyDaySMA) then 1 else 0;

def AveragePriceChangePercent = MovingAverage(AverageType.SIMPLE, AbsValue(close[1] - close[2]) / close[2], Period);

def IsCloseInUpperHalfOfRange = close >= close[1] && close > ((high - low) * .38 + low);

def IsPriceInTheProperRange = if (IsCloseInUpperHalfOfRange && IsPriceNear10DaySMA && IsPriceAtOrAbove50DaySMA) then 1 else 0;

# add a chart bubble if then PP criteria are met
AddChartBubble(IsVolumeGreaterHighestDownVolume && IsPriceInTheProperRange, low, "PP", Color.CYAN, no);

#Scan
def PParrow = IsVolumeGreaterHighestDownVolume and IsPriceInTheProperRange;
plot PP = PParrow;
PP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
PP.SetLineWeight(2);
PP.AssignValueColor(Color.WHITE);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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