Accessing Seconds from 1min Chart ThinkOrSwim

evanevans

Active member
I'm trying to create a label to show projected number of shares traded (volume) by close of the current bar. Technically all I want to do is color a CurrentBarVolume label according to whether the projected volume of the current bar will be above or below the average of the last 30 bars.

The problem is, I can't get the number of seconds that have passed in the current minute (GetTime) so that I can do a calculated projection.

For example, if in the first 10 seconds of the current minute 100,000 shares have traded, than at that point you can project that 600,000 shares might trade by the close of the current bar.

So for my script, if that 600,000 number (for example) is above the average bar volume of the last 30 bars, I want to color the label green, otherwise light_gray.

Any help?

Many thanks
 
Accessing Seconds On A Tick Chart
This needs to be done on a tick chart, this is the only way you'll get the data to use before a 1 min bar closes.

This was tested on a 1 tick chart. The user inputs the number of seconds for the aggregation they want to use(in this case it is set to 60 seconds for a 1 min bar). Depending on the time of day when there is more activity (was testing during futures globex session) and/or if you are adjusting the aggregationsInSeconds input to higher values, then you can increase the ticks on the chart aggregation. Play around and find a readable balance.

edit:
  • Cleaned up the script a little
  • Added some more variables and labels for them so that I and others can play around with them and discover some things in relation to volatility spikes, etc.
  • Previous cycle value for CVol is now carried over as a yellow line, allowing you to better see visually when the current cycle meets/exceeds the previous CVol level. I'd like to script something with this that better shows the relations between current cycle length, previous cycle length, and the amount of time it took to meet those CVol levels when volatility starts to spike.
  • Also made it so that projection isn't plotted when multiplier value is infinite

MHCqXuk.png

Code:
#[email protected]
#Thanks to YungTraderFromMontana and evanevans for the ideas
declare lower;

def NA = Double.NaN;
input aggregationInSeconds = 60;
input elapsedPercentSmoothValue = 5;
input elapsedProjectionDivisor = 2;
def start = 0000;
def end = 1600;
def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def bb = Max(o, c) == c;
def min = Floor(SecondsFromTime(start) / aggregationInSeconds);
def till = SecondsTillTime(end) / aggregationInSeconds;
def test = min != min[1];
def vc = if test and !test[1] then v else if !test then vc[1] + v else vc[1];
def secondselapsed = (AbsValue(till - Ceil(till)) * aggregationInSeconds);
def secondsleft = aggregationInSeconds - secondselapsed;
def multipliertest = aggregationInSeconds / secondselapsed;
def multiplier  = if IsInfinite(multipliertest) then NA else multipliertest;
def percntelapsed = Round(((secondselapsed / aggregationInSeconds) * 100), 0);
def cl = if test then 1 else cl[1] + 1;
def ch = if test then cl[1] else ch[1];
def prevcumulativehigh = if test and !test[1] then vc[1] else prevcumulativehigh[1];
def cvolpassprev = vc >= prevcumulativehigh and vc[1] < prevcumulativehigh;
def highestprevchigh = highestall(prevcumulativehigh);
def projectioncalc = vc * multiplier;

plot cvolpassprevsig = if cvolpassprev then vc else NA;

plot CVol = vc;
plot prevchigh = prevcumulativehigh;
plot cycleavg = Round(TotalSum(if test then ch[1] else 0) / min, 1);
plot cyclehigh = ch;
plot cyclelength = cl;
plot projection = if (projectioncalc>=highestprevchigh) and (percntelapsed<elapsedPercentSmoothValue) then projectioncalc/elapsedProjectionDivisor else projectioncalc;

AddVerticalLine(!IsNaN(cvolpassprevsig), "                      "+secondselapsed+"s / "+aggregationInSeconds+" | "+percntelapsed+"%", Color.CYAN);
AddVerticalLine(test, "                      CVol "+prevcumulativehigh, Color.GRAY, Curve.FIRM);

AddLabel(1, "Cycle Length: " + cyclelength[1], Color.GRAY);
AddLabel(1, "Prev Cycle Length: " + cyclehigh, Color.GRAY);
AddLabel(1, "Cycle Avg: " + cycleavg, Color.GRAY);
AddLabel(1, "Cycles Since Start: " + min, Color.GRAY);
AddLabel(1, "Secs " + secondselapsed + "/" + aggregationInSeconds + "   " + percntelapsed + "%", Color.YELLOW);
AddLabel(1, "CVol: " + vc, Color.WHITE);
AddLabel(1, "Prev CVol: " + prevcumulativehigh, Color.WHITE);
AddLabel(1, "Proj Vol: " + Round(projection, 0), Color.DARK_ORANGE);
AddLabel(1, "x" + Round(multiplier, 2), Color.DARK_ORANGE);

CVol.SetDefaultColor(Color.DARK_GRAY);
CVol.SetLineWeight(2);
prevchigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevchigh.SetDefaultColor(Color.YELLOW);
projection.SetDefaultColor(Color.DARK_ORANGE);
projection.SetLineWeight(2);
cvolpassprevsig.SetPaintingStrategy(PaintingStrategy.POINTS);
cvolpassprevsig.SetLineWeight(3);
AddCloud(projection, CVol, CreateColor(0, 100, 200), CreateColor(0, 100, 200));
AddCloud(CVol, 0, Color.DARK_GRAY, Color.DARK_GRAY);
AddCloud(CVol, prevchigh, Color.DARK_GREEN, Color.BLACK);
 
Last edited by a moderator:

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

Dude, that's pretty freaking great. It shows the projection at each moment, and the actual is the gray area? Phenomenal. I can just put this underneath my main 1m charts, in a tick chart, and that will help me do the forecasting. I'm sure you can see the usefulness as I do. Looks like you can see if the prediction is waning .... or "waxing".
 
Well that was certainly amazing in action. Before the first big volume candle zoomed up and the candlestick price zoomed up, you could see the explosion in volume. If I had a video of it happening it would be very revealing... but, essentially, you could see the volume exploding before price changed. It was beautiful to see. And very easy to see after a consolidation period of low volume because of the differential (between low volume and insane volume).

LlQl44l.png


I have some questions and further ideas:

1. Could each tick cloud moment be colored whether it was up in price (ex: green: bright green if it hit the ask; forest green if it was the same as last which was up) or down in price (ex: red: bright red if it hit the bid; dark red if it was the same as last which was down)? I can almost picture a thermograph in the cloud area.

2. I also notice there is a ROC or velocity in this tick flow that is useful and should be converted into something we can see/interpret.

3. Could we compress the output to put no further than 1 seconds data into the minute region? Because on some very heavily traded stocks which experience light volume, one has to be on 1 tick to see anything significant, but then suddenly when 5 million shares trade in a minute, that 1 minute ends up spanning several scrolled windows worth of data! :)

4. Finally, I think there must be something that can be done about the first 5-10 seconds of each aggregation period. Many times it way overprojects the math. Maybe for the first 10 seconds, it can compare to the previous 10 seconds, and feather out, just so it's not so blind at the start each time. Perhaps this could even be a rolling 10 second "smoother" throughout.

P.S. Going to send you a PayPal donation good sir, well done!
 
Last edited:
@evanevans - I'm trying to get the same tick volume chart layout you have for $PIXY. What do you have the tick settings at? Did you move the study into the upper?

I added a C2 (second chart from the right "Grid" sidebar choices) to the chart (C1). I then removed it from displaying the upper chart (on that C2 second chart) so it only had the lower indicator. Then I set the timeframe on the lower C2 to Ticks. Depending on the stock volume, one has to choose 1 tick, 10 tick, 50 ticks, 5 ticks, depends, because every stock has a different amount of volume. Looks like @Welkin is going to have a go at my suggestions, so maybe there will be something coming to address the non-uniformity between different levels of tick volume. When it's a lot, it requires choosing a larger amount of ticks per data point (10+). I think if we can always "sub-aggregate" those down to 1 second bars, that might be the ideal, although I really dig the speed of the realtime. There must be a solution. Maybe 250ms bars. 100ms bars. Something unified, no matter what volume of tick data there is, it has a standardized display method across varying stocks.
 
@Welkin my goodness get it together man... How long did it take you to overthrow NYC and fix the power? Also why haven't you finished colonizing Mars??? You probably got distracted performing remote surgery with nanobots but man get your schedule together maybe a life coach! We expect more out of you...

I did something I think might add functionality to your solution... Only thing is at some point we will be moving so fast we will be deceived by HighFreqTrading https://usethinkscript.com/threads/automating-aggregation-selection-for-thinkorswim.3183/#post-29405
 
Here's a v1 for a daily predicted volume. I assisted the prediction by eyeballing when the volume came in on SPY, very primitive but still much more effective at this point. Prediction seems to be pretty accurate even very early in the day. Next steps are trying to find statistical ratios using previous data instead of manual ones as well as a better way of smoothing so there aren't spikes in the prediction during ratio changes.
Code:
#[email protected]
declare lower;
def NA = Double.NaN;
input aggregationInSeconds = 23400;
def start = 0930;
def v = volume;
def min = Floor(SecondsFromTime(start) / aggregationInSeconds);
def till = SecondsTillTime(start) / aggregationInSeconds;
def test = if min != min[1] then 1 else 0;
def vc = if (test == 1) and (test[1] == 0) then v else if (test == 0) then vc[1] + volume else vc[1];
plot vct = if test == 1 then NA else vc;
def secondselapsed = (AbsValue(till - Ceil(till)) * aggregationInSeconds);
def secondsleft = aggregationInSeconds - secondselapsed;
def multiplier = aggregationInSeconds / secondselapsed;
def prj = vc * multiplier;
input Time = 0934;
input Time2 = 0945;
input Time3 = 0958;
input Time4 = 1010;
input Time5 = 1025;
input Time6 = 1040;
input Time7 = 1100;
input Time8 = 1125;
input Time9 = 1150;
input Time10 = 1300;
input Time11 = 1540;
def Active = SecondstillTime(Time) >= 0;
def Active2 = SecondstillTime(Time2) >= 0;
def Active3 = SecondstillTime(Time3) >= 0;
def Active4 = SecondstillTime(Time4) >= 0;
def Active5 = SecondstillTime(Time5) >= 0;
def Active6 = SecondstillTime(Time6) >= 0;
def Active7 = SecondstillTime(Time7) >= 0;
def Active8 = SecondstillTime(Time8) >= 0;
def Active9 = SecondstillTime(Time9) >= 0;
def Active10 = SecondstillTime(Time10) >= 0;
def Active11 = SecondstillTime(Time11) >= 0;
plot prjmod = if Active then prj / 3 else if Active2 then prj / 2.3 else if Active3 then prj / 2.15 else if Active4 then prj / 2 else if Active5 then prj / 1.7 else if Active6 then prj / 1.55 else if Active7 then prj / 1.4 else if Active8 then prj / 1.3 else if Active9 then prj / 1.15 else  if active10 then prj/.97 else if active11 then prj/.9 else prj;
AddLabel(1, multiplier, Color.ORANGE);
AddVerticalLine(test, " ", Color.GRAY);
AddLabel(1, "Cycles Since Start: " + min, Color.WHITE);
AddLabel(1, "Seconds Elapsed: " + secondselapsed, Color.YELLOW);
AddLabel(1, "Seconds Left: " + secondsleft, Color.YELLOW);
AddLabel(1, "Current Cumulative Vol: " + vc, Color.WHITE);
AddLabel(1, "Projected Volume: " + Round(prjmod, 0), Color.DARK_ORANGE);
AddCloud(vct, 0, Color.GRAY, Color.GRAY);
AddCloud(prjmod, vct, Color.BLUE, Color.BLUE);
vct.SetDefaultColor(Color.WHITE);
prjmod.SetDefaultColor(Color.DARK_ORANGE);

Here's a pic, no prediction after 3:50 eastern because there is no point
 
I added a C2 (second chart from the right "Grid" sidebar choices) to the chart (C1). I then removed it from displaying the upper chart (on that C2 second chart) so it only had the lower indicator. Then I set the timeframe on the lower C2 to Ticks.

How do you do that? (the bolded part)
 
Well that was certainly amazing in action. Before the first big volume candle zoomed up and the candlestick price zoomed up, you could see the explosion in volume. If I had a video of it happening it would be very revealing... but, essentially, you could see the volume exploding before price changed. It was beautiful to see. And very easy to see after a consolidation period of low volume because of the differential (between low volume and insane volume).

LlQl44l.png


I have some questions and further ideas:

1. Could each tick cloud moment be colored whether it was up in price (ex: green: bright green if it hit the ask; forest green if it was the same as last which was up) or down in price (ex: red: bright red if it hit the bid; dark red if it was the same as last which was down)? I can almost picture a thermograph in the cloud area.

2. I also notice there is a ROC or velocity in this tick flow that is useful and should be converted into something we can see/interpret.

3. Could we compress the output to put no further than 1 seconds data into the minute region? Because on some very heavily traded stocks which experience light volume, one has to be on 1 tick to see anything significant, but then suddenly when 5 million shares trade in a minute, that 1 minute ends up spanning several scrolled windows worth of data! :)

4. Finally, I think there must be something that can be done about the first 5-10 seconds of each aggregation period. Many times it way overprojects the math. Maybe for the first 10 seconds, it can compare to the previous 10 seconds, and feather out, just so it's not so blind at the start each time. Perhaps this could even be a rolling 10 second "smoother" throughout.

P.S. Going to send you a PayPal donation good sir, well done!
1. Trying to come up with something to better show direction, perhaps some sort of weighting based on an uptick or downtick ratio using something similar to on balance volume. Haven't been able to get bid/ask data to plot on tick charts. still pursuing and testing ideas...
2. I updated the post with the original script providing some new variables to help tackle and provide further insight into this.
3. if a tick plots then the line will plot, not sure how I'd go about compressing the time axis besides adjusting the actual tick chart aggregation itself.
4. I do want to find a way to smooth it out but with as little loss as possible, because there are times when it is accurate, and sometimes the spikes come towards the middle instead of the start of the cycle, which can give some volatility insight. I've thought of implimenting some sort of 'ceiling' but there are times when that does more harm to the output. @YungTraderFromMontana is using a method artificially smoothes the multiplier using manuallty entered values for those less active times of an average trading day. I'd like to come up with a more dynamic solution, perhaps through the introduction of an ATR with volume.

there are tons of things I'd like to play around with, but I still need to tend to my other commitments as well throughout the process.
 
1. Trying to come up with something to better show direction, perhaps some sort of weighting based on an uptick or downtick ratio using something similar to on balance volume. Haven't been able to get bid/ask data to plot on tick charts. still pursuing and testing ideas...
I think the coloring is a good way to show the direction of the tick. I can imagine the "cloud" being changed out for quantized 1 second tick bars, colored to whatever was the majority (up or down or same or half up half down, etc), or a thermal plot. But I understand you have other projects. Looking forward to getting somewhere with indicating direction in conjunction with the display as you have it. That is the combo that would allow us to act fast on direction.
2. I updated the post with the original script providing some new variables to help tackle and provide further insight into this.
Cool, I'll play around with it tomorrow during day trading.
3. if a tick plots then the line will plot, not sure how I'd go about compressing the time axis besides adjusting the actual tick chart aggregation itself.
Yeah I guess that's a limitation of the software. Ideally, you could collect or round or average data for the second, then display the results as a bar height and coloration.
4. I do want to find a way to smooth it out but with as little loss as possible, because there are times when it is accurate, and sometimes the spikes come towards the middle instead of the start of the cycle, which can give some volatility insight. I've thought of implimenting some sort of 'ceiling' but there are times when that does more harm to the output. @YungTraderFromMontana is using a method artificially smoothes the multiplier using manuallty entered values for those less active times of an average trading day. I'd like to come up with a more dynamic solution, perhaps through the introduction of an ATR with volume.
Yeah I'm with you on trying to be very careful about "dulling" the display of whenever volume starts picking up.
there are tons of things I'd like to play around with, but I still need to tend to my other commitments as well throughout the process.
Absolutely. And totally understand. What you've done so far is very useful. I'm going to be using it all week, and will let you know the results. I find it to be very useful. I've witnessed with my own eyes on Friday, where a massive wave of volume started to show up, and yet the price of the stock had not yet changed significantly. 2-5 seconds later it exploded to the upside. Had I been able to see that the initial "wave" of tick volume was predominantly UP TICKS (green or something), I could have pounced and got an entry at a 5c to 10c advantage, which in day trading is a significant edge. At 10,000 shares, a 10c advantage means an additional $1000 profit. :) This is why I'm happy to send you something this week. ;) Alright, talk soon.
 
made a few more small changes
MHCqXuk.png

When the max cumulative volume of the previous cycle is reached a cyan dot and vertical line is plotted showing the seconds and percentage of the inputted aggregate that has elapsed as an indicator of increasing volatility. When volume exceeds the previous bar you will see the CVol cloud begin plotting green.
Added a temporary smoother for volume projection during the first 5%(adjustable in settings) of elapsed time so that the projection is divided in half(can also be adjusted in settings) to help cut the extreme spikes that happen at the start of a new cycle. This is to help cut down on the heavy distortion/compression on the y axis that can make the indicator unreadable sometimes without manual adjustments, until something better comes along.

Code:
#[email protected]
#Thanks to YungTraderFromMontana and evanevans for the ideas
declare lower;
#v8.24.2020

def NA = Double.NaN;
input aggregationInSeconds = 60;
input elapsedPercentSmoothValue = 5;
input elapsedProjectionDivisor = 2;
input showVerticalExceedPrevCvol = yes;
input showVerticalCycleEndCvol = yes;
def start = 0000;
def end = 1600;
def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def bb = Max(o, c) == c;
def min = Floor(SecondsFromTime(start) / aggregationInSeconds);
def till = SecondsTillTime(end) / aggregationInSeconds;
def test = min != min[1];
def vc = if test and !test[1] then v else if !test then vc[1] + v else vc[1];
def secondselapsed = (AbsValue(till - Ceil(till)) * aggregationInSeconds);
def secondsleft = aggregationInSeconds - secondselapsed;
def multipliertest = aggregationInSeconds / secondselapsed;
def multiplier  = if IsInfinite(multipliertest) then NA else multipliertest;
def percntelapsed = Round(((secondselapsed / aggregationInSeconds) * 100), 0);
def cl = if test then 1 else cl[1] + 1;
def ch = if test then cl[1] else ch[1];
def prevcumulativehigh = if test and !test[1] then vc[1] else prevcumulativehigh[1];
def cvolpassprev = vc >= prevcumulativehigh and vc[1] < prevcumulativehigh;
def highestprevchigh = highestall(prevcumulativehigh);
def projectioncalc = vc * multiplier;

plot cvolpassprevsig = if cvolpassprev then vc else NA;

plot CVol = vc;
plot prevchigh = prevcumulativehigh;
plot cycleavg = Round(TotalSum(if test then ch[1] else 0) / min, 1);
plot cyclehigh = ch;
plot cyclelength = cl;
plot projection = if (projectioncalc>=highestprevchigh) and (percntelapsed<elapsedPercentSmoothValue) then projectioncalc/elapsedProjectionDivisor else projectioncalc;

AddVerticalLine(showVerticalExceedPrevCvol and !IsNaN(cvolpassprevsig), "                      "+secondselapsed+"s / "+aggregationInSeconds+" | "+percntelapsed+"%", Color.CYAN);
AddVerticalLine(showVerticalCycleEndCvol and test, "                      CVol "+prevcumulativehigh, Color.GRAY, Curve.FIRM);

AddLabel(1, "Cycle Length: " + cyclelength[1], Color.GRAY);
AddLabel(1, "Prev Cycle Length: " + cyclehigh, Color.GRAY);
AddLabel(1, "Cycle Avg: " + cycleavg, Color.GRAY);
AddLabel(1, "Cycles Since Start: " + min, Color.GRAY);
AddLabel(1, "Secs " + secondselapsed + "/" + aggregationInSeconds + "   " + percntelapsed + "%", Color.YELLOW);
AddLabel(1, "CVol: " + vc, Color.WHITE);
AddLabel(1, "Prev CVol: " + prevcumulativehigh, Color.WHITE);
AddLabel(1, "Proj Vol: " + Round(projection, 0), Color.DARK_ORANGE);
AddLabel(1, "x" + Round(multiplier, 2), Color.DARK_ORANGE);

CVol.SetDefaultColor(Color.DARK_GRAY);
CVol.SetLineWeight(2);
prevchigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevchigh.SetDefaultColor(Color.YELLOW);
projection.SetDefaultColor(Color.DARK_ORANGE);
projection.SetLineWeight(2);
cvolpassprevsig.SetPaintingStrategy(PaintingStrategy.POINTS);
cvolpassprevsig.SetLineWeight(3);
AddCloud(projection, CVol, CreateColor(0, 100, 200), CreateColor(0, 100, 200));
AddCloud(CVol, 0, Color.DARK_GRAY, Color.DARK_GRAY);
AddCloud(CVol, prevchigh, Color.DARK_GREEN, Color.BLACK);
 
Good idea on the 5% "smoother". And I literally was just thinking we could use a line to compare the previous period. Boom! Nice thinking! FYI though, just because volume has exceeded the previous period does not mean it's UP volume. It could be selling volume. So "green" might not be the right approach. Although I suppose we could dynamically color that at whatever CLOSE to the previous period CLOSE direction is indicating.

So there is no way to store the number of ticks that went up vs went down in price? Ticks are just ticks? They don't have direction? (Not being sarcastic, I really don't know the answer) :)
 
Just going to be posting notes from real-world examples, anytime I see anything and have a thought to contribute, I'll post it. So, here's the first one.

This goes back to my original comments about if there is anything we can do to color each tick, or cloud area, or border color, or something, to indicate that the volume is bearish or bullish.

lONQrCD.png
 
In this image, projected volume shows a multiple of 1.2x. Maybe I don't understand that that is, but if it's supposed to represent the ratio of the current projected volume to the previous period, than it looks like something might be wrong with the math, as visually it appears the current period pictured is showing a lower projected volume than the last period (yellow line)...somewhere closer to 0.75x.

zQd34I9.png
 
Good idea on the 5% "smoother". And I literally was just thinking we could use a line to compare the previous period. Boom! Nice thinking! FYI though, just because volume has exceeded the previous period does not mean it's UP volume. It could be selling volume. So "green" might not be the right approach. Although I suppose we could dynamically color that at whatever CLOSE to the previous period CLOSE direction is indicating.

So there is no way to store the number of ticks that went up vs went down in price? Ticks are just ticks? They don't have direction? (Not being sarcastic, I really don't know the answer) :)
Correct just because the cumulative volume from the previous session is exceeded does not mean it is up volume, the green is just a visual for that and can be changed to something more neutral. I did plan on changing it to something else, just wanted something to be there in the meantime. at least until I start scripting something to better indicate direction. Indicators take time, you add pieces and change things as you go. a work in progress.

There is, i just didn't script it yet... I decided to stop where I was and pick up at a later time after getting some rest, trading, and doing the other things I need to do. Just wanted to post the little bit of progress I made and keep it updated.
In this image, projected volume shows a multiple of 1.2x. Maybe I don't understand that that is, but if it's supposed to represent the ratio of the current projected volume to the previous period, than it looks like something might be wrong with the math, as visually it appears the current period pictured is showing a lower projected volume than the last period (yellow line)...somewhere closer to 0.75x.
thats the multiplier for the projection, i use labels and sometimes chart bubbles as well to help debug script and to see what values different variables are spitting out. it is not a vol ratio or rvol or anything like that. That is on the list though.
 
Last edited:
Ok, tried a few things and this is what I've currently settled on for determining tick direction/sentiment. This creates a ratio based on if the tick bar's close >previous close (+1 to upval counter) or close < previous close(+1 to downval counter), instances where close == close[1], which are common in low value tick charts, are ignored. Depending on which is weighted more heavily, upval or downval, the projection line will be colored green or red accordingly.
Also added a label that shows current cumulative volume relative to previous cycle's max cumulative volume value.
Needs more testing but give it a shot.
Also, I know you wanted the cloud to change color offering a thermal effect, but it didn't look right, there were empty spaces being plotted between transitions and didn't look right.
yzErQMC.png


Code:
#[email protected]
#Thanks to YungTraderFromMontana and evanevans for the ideas
#v8.25.2020
declare lower;

def NA = Double.NaN;
input aggregationInSeconds = 60;
input elapsedPercentSmoothValue = 5;
input elapsedProjectionDivisor = 2;
input showVerticalExceedPrevCvol = yes;
input showVerticalCycleEndCvol = yes;
def start = 0000;
def end = 1600;
def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def bull = c > c[1];
def bear = c < c[1];
def neutral = c == o;
def min = Floor(SecondsFromTime(start) / aggregationInSeconds);
def till = SecondsTillTime(end) / aggregationInSeconds;
def test = min != min[1];
def vc = if test and !test[1] then v else if !test then vc[1] + v else vc[1];
def secondselapsed = (AbsValue(till - Ceil(till)) * aggregationInSeconds);
def secondsleft = aggregationInSeconds - secondselapsed;
def multipliertest = aggregationInSeconds / secondselapsed;
def multiplier  = if IsInfinite(multipliertest) then NA else multipliertest;
def percntelapsed = Round(((secondselapsed / aggregationInSeconds) * 100), 0);
def cl = if test then 1 else cl[1] + 1;
def ch = if test then cl[1] else ch[1];
def prevcumulativehigh = if test and !test[1] then vc[1] else prevcumulativehigh[1];
def cvolpassprev = vc >= prevcumulativehigh and vc[1] < prevcumulativehigh;
def highestprevchigh = HighestAll(prevcumulativehigh);
def projectioncalc = vc * multiplier;
#tick sentiment test
def upval = if test and !test[1] and bull then 1 else if !test and bull then upval[1] + 1 else if test and bear then 0 else upval[1];
def downval = if test and !test[1] and bear then 1 else if !test and bear then downval[1] + 1 else if test and bull then 0 else downval[1];

AddLabel(1, upval, Color.GREEN);
AddLabel(1, downval, Color.RED);
def cycleticksentiment = upval / downval;
addlabel(1,"Cycle Sentiment: " +Round(cycleticksentiment,2), if !isinfinite(cycleticksentiment) and cycleticksentiment > 1 then Color.GREEN else if !isinfinite(cycleticksentiment) and cycleticksentiment < 1 then Color.RED else  Color.GRAY);


plot cvolpassprevsig = if cvolpassprev then vc else NA;
plot CVol = vc;
plot prevchigh = prevcumulativehigh;
plot cycleavg = Round(TotalSum(if test then ch[1] else 0) / min, 1);
plot cyclehigh = ch;
plot cyclelength = cl;
plot projection = if (projectioncalc >= highestprevchigh) and (percntelapsed < elapsedPercentSmoothValue) then projectioncalc / elapsedProjectionDivisor else projectioncalc;

cycleavg.Hide();
cyclehigh.Hide();
cyclelength.Hide();

AddVerticalLine(showVerticalExceedPrevCvol and !IsNaN(cvolpassprevsig), "                 " + secondselapsed + "s / " + aggregationInSeconds + " | " + percntelapsed + "%", Color.CYAN);
AddVerticalLine(showVerticalCycleEndCvol and test, "                 CVol " + prevcumulativehigh, Color.GRAY, Curve.FIRM);

AddLabel(1, "Cycle Length: " + cyclelength[1], Color.GRAY);
AddLabel(1, "Prev Cycle Length: " + cyclehigh, Color.GRAY);
AddLabel(1, "Cycle Avg: " + cycleavg, Color.GRAY);
AddLabel(1, "Cycles Since Start: " + min, Color.GRAY);
AddLabel(1, "Secs " + secondselapsed + "/" + aggregationInSeconds + "   " + percntelapsed + "%", Color.YELLOW);
AddLabel(1, "CVol: " + vc, Color.WHITE);
AddLabel(1, "Prev CVol: " + prevcumulativehigh, Color.WHITE);
AddLabel(1, "x"+Round(vc/prevcumulativehigh,2)+" Prev CVol", Color.WHITE);
AddLabel(1, "Proj Vol: " + Round(projection, 0), Color.DARK_ORANGE);
AddLabel(1, "Proj Multiplier x" + Round(multiplier, 2), Color.DARK_ORANGE);

CVol.SetDefaultColor(Color.DARK_GRAY);
CVol.SetLineWeight(2);
prevchigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
prevchigh.SetDefaultColor(Color.YELLOW);
projection.SetDefaultColor(Color.DARK_ORANGE);
#projection.AssignValueColor(if bull then Color.GREEN else if bear then Color.RED else if neutral then Color.GRAY else Color.CURRENT);
projection.AssignValueColor(if !isinfinite(cycleticksentiment) and cycleticksentiment > 1 then Color.GREEN else if !isinfinite(cycleticksentiment) and cycleticksentiment < 1 then Color.RED else Color.GRAY);
projection.SetLineWeight(2);
cvolpassprevsig.SetPaintingStrategy(PaintingStrategy.POINTS);
cvolpassprevsig.SetLineWeight(3);
AddCloud(projection, CVol, CreateColor(0, 100, 200), CreateColor(0, 100, 200));
AddCloud(CVol, 0, Color.DARK_GRAY, Color.DARK_GRAY);
AddCloud(CVol, prevchigh, Color.YELLOW, Color.BLACK);
 
Last edited:
@Welkin it went great today. The colors indicating up/down direction multiplied the usefulness massively. I think it's a really great momentum style indicator at this point. I did set the smoothing to 0, but interestingly I did not notice a visual difference between 0 and the default of 5.

What were some of your other thoughts for it?

I still would love to see it auto-adapt to the amount of tick volume that is coming in. I think a user posted an example of how that could be approached earlier in this thread? I find myself frequently going in and changing the tick-frame to 1 premarket and midday, and to 5 or 10 during market open and end of day and during strong rally moments. You have to constantly be changing it. Is there no way to not plot each tick and instead plot the value of a cumulative tick counted value each passing second?

This is how it looks on my setup:
swceGpm.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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