Hi Everyone!
First time posting and relatively new ToS user (about a year) and have learned a lot from the great group of contributors/mods on here!
I'm attempting to create a study where I can visually pickup volume spikes/bursts/surges primarily applicable to option premium contract charts, but adjustable enough so that it can apply to anything that has volume.
I've read this thread and while I'm not looking for a scan (yet) or a column (yet) I tried to pickup on some of the logic and apply it to something I've been working on.
https://usethinkscript.com/threads/thinkorswim-volume-spike-alert-and-scanner.1057/page-4
Apologies in advance but I have no formal thinkscript or programming experience or background. So logically I hopped on ChatGPT and spent the better half of two nights trying to come up with something close to what I'm trying to accomplish and hit a wall. This is the code I currently have running.
The logic and strategy is two-fold.
The thought here is then trigger different color points (white,orange,violet) based on how big of a difference the volume bars show when compared to atr(9). As I type this, I'm thinking this should be based off the sessions volume, which thinking about it might be ATR(1) if we're talking a 0Dte contract that doesn't have prior volume.
Ideally, the BBsq will pick when price is consolidating a bit, then the FIRST volume bar on a 1m chart prints the following conditions: higher than 100% of previous 10 bars based on atr(9) avg volume (this would paint a white point) An ORANGE point would be 200% greater than previous 11 bars (including the previous white point) and combined ATR() And Violet would be 500+% greater than 12 bars combined along with ATR() These thresholds should be user-defined. The logic here is to try and catch a surge and identify if the vol surge is sustained and not just a single bar. This all should be picked up from the 1M chart (defaul aggregation)
I put in a matype as a way to smooth the oscillator line, but don't think there is logic to actually get that done. I do have an EMA code which I want to associate itself with the price of the ticker- I don't think it does that. In other words, a 8 or 21ema (21 is defined in the code but it doesn't move much from the zero line) would move up and down with price within the oscillitor and give me insight on possible divergences.
There is a code i entered from the thread above about picking up on a % spike that seems to capture a spike, but needs adjusting.
I am open to completely re-designing the logic here and am not married to anything other than the visual aspect of the study. I want it to be an oscillator with a zero-line and the first conditions of rvol to match with the 4 colors presented. I do think the rvol thresholds and logic need adjusting since my goal is to capture when volume surges (both present in calls and puts and underlying stocks)
I also want to use the colored points visual to identify when the surge starts happening and the colors intensify(change) as volume bars surge higher. Especially with option contracts, lots of volume comes pouring in sometimes and can have a sudden affect in premium. Being able to see the volume spike earlier would be helpful.
The thought of using the squeeze was to try and limit the amount of false positives, but i think my implementation is off. I love the idea of using ATR as the measure by which rvol/squeeze's are calculated, but could be a bit off on implementation.
These are some images that can help visualize what I'm trying to get done. And again, open to completely re-working the logic. And maybe i'm over-complicating things, hoping to clear up some thoughts and get something workable.
Thanks!
H
**Shared Chart Link: https://tos.mx/LFDfRvW
First time posting and relatively new ToS user (about a year) and have learned a lot from the great group of contributors/mods on here!
I'm attempting to create a study where I can visually pickup volume spikes/bursts/surges primarily applicable to option premium contract charts, but adjustable enough so that it can apply to anything that has volume.
I've read this thread and while I'm not looking for a scan (yet) or a column (yet) I tried to pickup on some of the logic and apply it to something I've been working on.
https://usethinkscript.com/threads/thinkorswim-volume-spike-alert-and-scanner.1057/page-4
Apologies in advance but I have no formal thinkscript or programming experience or background. So logically I hopped on ChatGPT and spent the better half of two nights trying to come up with something close to what I'm trying to accomplish and hit a wall. This is the code I currently have running.
Code:
# Define input parameters
input maPeriod = 21; # Smoothing EMA period
input rvolThreshold1 = 50;
input rvolThreshold2 = 100;
input rvolThreshold3 = 200;
input rvolThreshold4 = 500;
input rvolThreshold5 = 800;
input bbLength = 20; # Bollinger Bands length
input atrLength = 9; # ATR length for Bollinger Bands and BBSQ points
input bbsqMultiplier1 = 1.5; # Multiplier for BBSQ condition 1
input bbsqMultiplier2 = 1.6; # Multiplier for BBSQ condition 2
input bbsqMultiplier3 = 1.9; # Multiplier for BBSQ condition 3
# User-defined Moving Average type
input maType = {default SMA, EMA};
input pctvolchg = 5; # Percentage volume change
input vol_length = 20; # Length for average volume calculation
# Calculate the relative volume change
def cumulativeVolume = Sum(volume, 10);
def avgVolume = (cumulativeVolume - cumulativeVolume[10]) / 10;
def rvolChange = ((volume - avgVolume) / avgVolume) * 100;
# Calculate the oscillator value between -1500 and 1500
def oscillatorValue = Min(Max(rvolChange, -1500), 1500);
# Choose the Moving Average type
def maValue;
switch (maType) {
case SMA:
maValue = Average(oscillatorValue, maPeriod);
case EMA:
maValue = ExpAverage(oscillatorValue, maPeriod);
}
# Calculate Bollinger Bands using user-defined ATR length
def atr = MovingAverage(AverageType.WILDERS, TrueRange(high, close, low), atrLength);
def bbDeviation = 2;
def bbUpper = maValue + bbDeviation * atr;
def bbLower = maValue - bbDeviation * atr;
# Identify BBSQ points based on user-defined multipliers
def bbsqCondition1 = close > bbsqMultiplier1 * atr;
def bbsqCondition2 = close > bbsqMultiplier2 * atr;
def bbsqCondition3 = close > bbsqMultiplier3 * atr;
# Calculate the total of the sum of 10 previous bars
def totalVolume = TotalSum(volume);
# Determine spike thresholds based on a 100% increase
def spikeThreshold = rvolChange > 100;
# Plot the zero line
plot ZeroLine = 0;
ZeroLine.SetPaintingStrategy(PaintingStrategy.LINE);
ZeroLine.SetDefaultColor(Color.GRAY);
# Plot BBSQ points as separate plots with colors in the lower pane
plot BBSQPointsWhite = if bbsqCondition1 then 0 else double.nan;
BBSQPointsWhite.SetPaintingStrategy(PaintingStrategy.POINTS);
BBSQPointsWhite.AssignValueColor(Color.WHITE);
plot BBSQPointsOrange = if bbsqCondition2 then 0 else double.nan;
BBSQPointsOrange.SetPaintingStrategy(PaintingStrategy.POINTS);
BBSQPointsOrange.AssignValueColor(Color.ORANGE);
plot BBSQPointsViolet = if bbsqCondition3 then 0 else double.nan;
BBSQPointsViolet.SetPaintingStrategy(PaintingStrategy.POINTS);
BBSQPointsViolet.AssignValueColor(Color.VIOLET);
# Plot colored points for the spike thresholds
plot SpikePoints = if spikeThreshold then 0 else double.nan;
SpikePoints.SetPaintingStrategy(PaintingStrategy.POINTS);
SpikePoints.AssignValueColor(Color.GREEN);
# Plot the oscillator in the lower pane
plot RelativeVolumeOscillator = maValue;
RelativeVolumeOscillator.AssignValueColor(
if rvolChange >= rvolThreshold5 then Color.RED
else if rvolChange >= rvolThreshold4 then Color.MAGENTA
else if rvolChange >= rvolThreshold3 then Color.CYAN
else if rvolChange >= rvolThreshold2 then Color.YELLOW
else if rvolChange >= rvolThreshold1 then Color.GREEN
else Color.GRAY
);
RelativeVolumeOscillator.SetLineWeight(1);
RelativeVolumeOscillator.HideTitle();
# Set the plot index to the lower pane
BBSQPointsWhite.SetPaintingStrategy(PaintingStrategy.POINTS);
BBSQPointsOrange.SetPaintingStrategy(PaintingStrategy.POINTS);
BBSQPointsViolet.SetPaintingStrategy(PaintingStrategy.POINTS);
SpikePoints.SetPaintingStrategy(PaintingStrategy.POINTS);
The logic and strategy is two-fold.
- The first is calculating RVOL based on percentages differences of total cumulative volume of "x" bars back (would like to make this user-defined)
- I then wanted to make sure this was in an oscillator format and within that oscillator line, paint different colors when different rvol thresholds are met. Again, these thresholds should be user-defined so that they can be applied to different securites that exhibit different volume characteristics. Currently, this is what the oscillator looks like
- I then attemped to include Bollinger band squeeze logic so that i can reduce the amount areas where volume surges actually happen(false-postive reductions) I had trouble adding keltners so what I tried to do is base the squeeze and bands off ATR(9) (user-definable)
The thought here is then trigger different color points (white,orange,violet) based on how big of a difference the volume bars show when compared to atr(9). As I type this, I'm thinking this should be based off the sessions volume, which thinking about it might be ATR(1) if we're talking a 0Dte contract that doesn't have prior volume.
Ideally, the BBsq will pick when price is consolidating a bit, then the FIRST volume bar on a 1m chart prints the following conditions: higher than 100% of previous 10 bars based on atr(9) avg volume (this would paint a white point) An ORANGE point would be 200% greater than previous 11 bars (including the previous white point) and combined ATR() And Violet would be 500+% greater than 12 bars combined along with ATR() These thresholds should be user-defined. The logic here is to try and catch a surge and identify if the vol surge is sustained and not just a single bar. This all should be picked up from the 1M chart (defaul aggregation)
I put in a matype as a way to smooth the oscillator line, but don't think there is logic to actually get that done. I do have an EMA code which I want to associate itself with the price of the ticker- I don't think it does that. In other words, a 8 or 21ema (21 is defined in the code but it doesn't move much from the zero line) would move up and down with price within the oscillitor and give me insight on possible divergences.
There is a code i entered from the thread above about picking up on a % spike that seems to capture a spike, but needs adjusting.
I am open to completely re-designing the logic here and am not married to anything other than the visual aspect of the study. I want it to be an oscillator with a zero-line and the first conditions of rvol to match with the 4 colors presented. I do think the rvol thresholds and logic need adjusting since my goal is to capture when volume surges (both present in calls and puts and underlying stocks)
I also want to use the colored points visual to identify when the surge starts happening and the colors intensify(change) as volume bars surge higher. Especially with option contracts, lots of volume comes pouring in sometimes and can have a sudden affect in premium. Being able to see the volume spike earlier would be helpful.
The thought of using the squeeze was to try and limit the amount of false positives, but i think my implementation is off. I love the idea of using ATR as the measure by which rvol/squeeze's are calculated, but could be a bit off on implementation.
These are some images that can help visualize what I'm trying to get done. And again, open to completely re-working the logic. And maybe i'm over-complicating things, hoping to clear up some thoughts and get something workable.
Thanks!
H
**Shared Chart Link: https://tos.mx/LFDfRvW
Last edited: